From ab20545e0455b4bbf807e4c65e857052b5db6370 Mon Sep 17 00:00:00 2001 From: Mari Imaizumi Date: Mon, 11 Nov 2024 02:53:30 +0900 Subject: [PATCH 1/2] Fix RELINE_TEST_ENCODING It was not working because it was not environment variable. --- test/reline/helper.rb | 27 +++++++++++++++++---------- test/reline/test_key_actor_emacs.rb | 7 ++++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/test/reline/helper.rb b/test/reline/helper.rb index ce4fe8d16d..c1336f3a65 100644 --- a/test/reline/helper.rb +++ b/test/reline/helper.rb @@ -19,12 +19,12 @@ end module Reline - class < Date: Thu, 28 Nov 2024 00:10:49 +0900 Subject: [PATCH 2/2] Fix Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8 Error: test_completion_append_character(Reline::KeyActor::EmacsTest): Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8 /home/runner/work/reline/reline/lib/reline/line_editor.rb:814:in 'block in Reline::LineEditor#filter_normalize_candidates' /home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Array#select' /home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Reline::LineEditor#filter_normalize_candidates' /home/runner/work/reline/reline/lib/reline/line_editor.rb:831:in 'Reline::LineEditor#perform_completion' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1434:in 'Reline::LineEditor#complete' /home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Method#call' /home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Reline::LineEditor#wrap_method_call' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1029:in 'block in Reline::LineEditor#process_key' /home/runner/work/reline/reline/lib/reline/line_editor.rb:932:in 'Reline::LineEditor#run_for_operators' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1028:in 'Reline::LineEditor#process_key' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1051:in 'Reline::LineEditor#normal_char' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1089:in 'Reline::LineEditor#input_key' /home/runner/work/reline/reline/test/reline/helper.rb:124:in 'block in Reline::TestCase#input_keys' /home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Array#each' /home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Reline::TestCase#input_keys' /home/runner/work/reline/reline/test/reline/test_key_actor_emacs.rb:948:in 'Reline::KeyActor::EmacsTest#test_completion_append_character' =============================================================================== =============================================================================== Error: test_continuous_completion_disabled_with_perfect_match(Reline::KeyActor::EmacsTest): Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8 /home/runner/work/reline/reline/lib/reline/line_editor.rb:814:in 'block in Reline::LineEditor#filter_normalize_candidates' /home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Array#select' /home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Reline::LineEditor#filter_normalize_candidates' /home/runner/work/reline/reline/lib/reline/line_editor.rb:831:in 'Reline::LineEditor#perform_completion' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1434:in 'Reline::LineEditor#complete' /home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Method#call' /home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Reline::LineEditor#wrap_method_call' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1029:in 'block in Reline::LineEditor#process_key' /home/runner/work/reline/reline/lib/reline/line_editor.rb:932:in 'Reline::LineEditor#run_for_operators' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1028:in 'Reline::LineEditor#process_key' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1051:in 'Reline::LineEditor#normal_char' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1089:in 'Reline::LineEditor#input_key' /home/runner/work/reline/reline/test/reline/helper.rb:124:in 'block in Reline::TestCase#input_keys' /home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Array#each' /home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Reline::TestCase#input_keys' /home/runner/work/reline/reline/test/reline/test_key_actor_emacs.rb:936:in 'Reline::KeyActor::EmacsTest#test_continuous_completion_disabled_with_perfect_match' =============================================================================== =============================================================================== Error: test_continuous_completion_with_perfect_match(Reline::KeyActor::EmacsTest): Encoding::CompatibilityError: Shift_JIS is not compatible with UTF-8 /home/runner/work/reline/reline/lib/reline/line_editor.rb:814:in 'block in Reline::LineEditor#filter_normalize_candidates' /home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Array#select' /home/runner/work/reline/reline/lib/reline/line_editor.rb:808:in 'Reline::LineEditor#filter_normalize_candidates' /home/runner/work/reline/reline/lib/reline/line_editor.rb:831:in 'Reline::LineEditor#perform_completion' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1434:in 'Reline::LineEditor#complete' /home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Method#call' /home/runner/work/reline/reline/lib/reline/line_editor.rb:961:in 'Reline::LineEditor#wrap_method_call' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1029:in 'block in Reline::LineEditor#process_key' /home/runner/work/reline/reline/lib/reline/line_editor.rb:932:in 'Reline::LineEditor#run_for_operators' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1028:in 'Reline::LineEditor#process_key' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1051:in 'Reline::LineEditor#normal_char' /home/runner/work/reline/reline/lib/reline/line_editor.rb:1089:in 'Reline::LineEditor#input_key' /home/runner/work/reline/reline/test/reline/helper.rb:124:in 'block in Reline::TestCase#input_keys' /home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Array#each' /home/runner/work/reline/reline/test/reline/helper.rb:117:in 'Reline::TestCase#input_keys' /home/runner/work/reline/reline/test/reline/test_key_actor_emacs.rb:924:in 'Reline::KeyActor::EmacsTest#test_continuous_completion_with_perfect_match' =============================================================================== Finished in 2.118582151 seconds. 385 tests, 1762 assertions, 0 failures, 3 errors, 0 pendings, 3 omissions, 0 notifications --- lib/reline/line_editor.rb | 10 ++++++---- test/reline/helper.rb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 94646633a3..a8f4c6198c 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -807,11 +807,13 @@ def editing_mode target = target.downcase if @config.completion_ignore_case list.select do |item| next unless item - unless Encoding.compatible?(target.encoding, item.encoding) - # Crash with Encoding::CompatibilityError is required by readline-ext/test/readline/test_readline.rb - # TODO: fix the test - raise Encoding::CompatibilityError, "#{target.encoding.name} is not compatible with #{item.encoding.name}" + # Workaround for Readline test + if defined?(::Readline) && ::Readline == ::Reline + raise Encoding::CompatibilityError, "incompatible character encodings: #{target.encoding} and #{item.encoding}" + end + + next true end if @config.completion_ignore_case diff --git a/test/reline/helper.rb b/test/reline/helper.rb index c1336f3a65..587376623b 100644 --- a/test/reline/helper.rb +++ b/test/reline/helper.rb @@ -23,7 +23,7 @@ class << self def test_mode(ansi: false) @original_iogate = IOGate - if Reline.const_defined?(:RELINE_TEST_ENCODING) && RELINE_TEST_ENCODING.is_a?(Encoding) + if defined?(RELINE_TEST_ENCODING) encoding = RELINE_TEST_ENCODING else encoding = Encoding::UTF_8