diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/reline/helper.rb | 34 | ||||
-rw-r--r-- | test/reline/test_key_actor_emacs.rb | 20 | ||||
-rw-r--r-- | test/reline/test_key_actor_vi.rb | 31 | ||||
-rw-r--r-- | test/reline/test_key_stroke.rb | 39 | ||||
-rw-r--r-- | test/reline/test_macro.rb | 8 | ||||
-rw-r--r-- | test/reline/test_reline_key.rb | 7 | ||||
-rw-r--r-- | test/reline/yamatanooroti/test_rendering.rb | 2 |
7 files changed, 69 insertions, 72 deletions
diff --git a/test/reline/helper.rb b/test/reline/helper.rb index 587376623b..a0c1b097e6 100644 --- a/test/reline/helper.rb +++ b/test/reline/helper.rb @@ -108,31 +108,29 @@ class Reline::TestCase < Test::Unit::TestCase input end - def input_key_by_symbol(input) - @line_editor.input_key(Reline::Key.new(input, input, false)) + def input_key_by_symbol(method_symbol, csi: false) + dummy_char = csi ? "\e[A" : "\C-a" + @line_editor.input_key(Reline::Key.new(dummy_char, method_symbol, false)) end def input_keys(input, convert = true) - input = convert_str(input) if convert - input.chars.each do |c| - if c.bytesize == 1 - eighth_bit = 0b10000000 - byte = c.bytes.first - if byte.allbits?(eighth_bit) - @line_editor.input_key(Reline::Key.new(byte ^ eighth_bit, byte, true)) - else - @line_editor.input_key(Reline::Key.new(byte, byte, false)) - end - else - @line_editor.input_key(Reline::Key.new(c.ord, c.ord, false)) - end - end + # Reline does not support convert-meta, but test data includes \M-char. It should be converted to ESC+char. + # Note that mixing unicode chars and \M-char is not recommended. "\M-C\M-\C-A" is a single unicode character. + input = input.chars.map do |c| + c.valid_encoding? ? c : "\e#{(c.bytes[0] & 0x7f).chr}" + end.join + input_raw_keys(input, convert) end def input_raw_keys(input, convert = true) input = convert_str(input) if convert - input.chars.each do |c| - @line_editor.input_key(Reline::Key.new(c.ord, c.ord, false)) + key_stroke = Reline::KeyStroke.new(@config, @encoding) + input_bytes = input.bytes + until input_bytes.empty? + expanded, input_bytes = key_stroke.expand(input_bytes) + expanded.each do |key| + @line_editor.input_key(key) + end end end diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 988a073f2d..9fd19f6079 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -157,18 +157,18 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase end def test_em_kill_line - @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + input_key_by_symbol(:em_kill_line) assert_line_around_cursor('', '') input_keys('abc') - @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + input_key_by_symbol(:em_kill_line) assert_line_around_cursor('', '') input_keys('abc') input_keys("\C-b", false) - @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + input_key_by_symbol(:em_kill_line) assert_line_around_cursor('', '') input_keys('abc') input_keys("\C-a", false) - @line_editor.input_key(Reline::Key.new(:em_kill_line, :em_kill_line, false)) + input_key_by_symbol(:em_kill_line) assert_line_around_cursor('', '') end @@ -273,12 +273,12 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase def test_key_delete input_keys('abc') assert_line_around_cursor('abc', '') - @line_editor.input_key(Reline::Key.new(:key_delete, :key_delete, false)) + input_key_by_symbol(:key_delete) assert_line_around_cursor('abc', '') end def test_key_delete_does_not_end_editing - @line_editor.input_key(Reline::Key.new(:key_delete, :key_delete, false)) + input_key_by_symbol(:key_delete) assert_line_around_cursor('', '') refute(@line_editor.finished?) end @@ -287,7 +287,7 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase input_keys('abc') input_keys("\C-b", false) assert_line_around_cursor('ab', 'c') - @line_editor.input_key(Reline::Key.new(:key_delete, :key_delete, false)) + input_key_by_symbol(:key_delete) assert_line_around_cursor('ab', '') end @@ -731,10 +731,10 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase input_keys("\C-b", false) assert_line_around_cursor('foo', 'o') assert_equal(nil, @line_editor.instance_variable_get(:@menu_info)) - @line_editor.input_key(Reline::Key.new(:em_delete_or_list, :em_delete_or_list, false)) + input_key_by_symbol(:em_delete_or_list) assert_line_around_cursor('foo', '') assert_equal(nil, @line_editor.instance_variable_get(:@menu_info)) - @line_editor.input_key(Reline::Key.new(:em_delete_or_list, :em_delete_or_list, false)) + input_key_by_symbol(:em_delete_or_list) assert_line_around_cursor('foo', '') assert_equal(%w{foo_foo foo_bar foo_baz}, @line_editor.instance_variable_get(:@menu_info).list) end @@ -1363,7 +1363,7 @@ class Reline::KeyActor::EmacsTest < Reline::TestCase def test_incremental_search_history_cancel_by_symbol_key # ed_prev_char should move cursor left and cancel incremental search input_keys("abc\C-r") - input_key_by_symbol(:ed_prev_char) + input_key_by_symbol(:ed_prev_char, csi: true) input_keys('d') assert_line_around_cursor('abd', 'c') end diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index 9712ba89cc..6d5b7e20c4 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -112,6 +112,17 @@ class Reline::ViInsertTest < Reline::TestCase assert_line_around_cursor("か\u3099き\u3099", '') end + def test_ed_insert_ignore_in_vi_command + input_keys("\C-[") + chars_to_be_ignored = "\C-Oあ=".chars + input_keys(chars_to_be_ignored.join) + assert_line_around_cursor('', '') + input_keys(chars_to_be_ignored.map {|c| "5#{c}" }.join) + assert_line_around_cursor('', '') + input_keys('iい') + assert_line_around_cursor("い", '') + end + def test_ed_next_char input_keys("abcdef\C-[0") assert_line_around_cursor('', 'abcdef') @@ -648,7 +659,7 @@ class Reline::ViInsertTest < Reline::TestCase assert_line_around_cursor('Readline', '') input_keys("\C-i", false) assert_line_around_cursor('Regexp', '') - @line_editor.input_key(Reline::Key.new(:completion_journey_up, :completion_journey_up, false)) + input_key_by_symbol(:completion_journey_up) assert_line_around_cursor('Readline', '') ensure @config.autocompletion = false @@ -671,7 +682,7 @@ class Reline::ViInsertTest < Reline::TestCase assert_line_around_cursor('Readline', '') input_keys("\C-i", false) assert_line_around_cursor('Regexp', '') - @line_editor.input_key(Reline::Key.new(:menu_complete_backward, :menu_complete_backward, false)) + input_key_by_symbol(:menu_complete_backward) assert_line_around_cursor('Readline', '') ensure @config.autocompletion = false @@ -804,6 +815,14 @@ class Reline::ViInsertTest < Reline::TestCase assert_line_around_cursor(' f', 'oo foo') end + def test_waiting_operator_arg_including_zero + input_keys("a111111111111222222222222\C-[0") + input_keys('10df1') + assert_line_around_cursor('', '11222222222222') + input_keys('d10f2') + assert_line_around_cursor('', '22') + end + def test_vi_waiting_operator_cancel input_keys("aaa bbb ccc\C-[02w") assert_line_around_cursor('aaa bbb ', 'ccc') @@ -825,14 +844,14 @@ class Reline::ViInsertTest < Reline::TestCase assert_line_around_cursor('', 'aaa bbb lll') # ed_next_char should move cursor right and cancel vi_next_char input_keys('f') - input_key_by_symbol(:ed_next_char) + input_key_by_symbol(:ed_next_char, csi: true) input_keys('l') assert_line_around_cursor('aa', 'a bbb lll') - # ed_next_char should move cursor right and cancel delete_meta + # vi_delete_meta + ed_next_char should delete character input_keys('d') - input_key_by_symbol(:ed_next_char) + input_key_by_symbol(:ed_next_char, csi: true) input_keys('l') - assert_line_around_cursor('aaa ', 'bbb lll') + assert_line_around_cursor('aa ', 'bbb lll') end def test_unimplemented_vi_command_should_be_no_op diff --git a/test/reline/test_key_stroke.rb b/test/reline/test_key_stroke.rb index 8f5c767ca4..fb2cb1c8b8 100644 --- a/test/reline/test_key_stroke.rb +++ b/test/reline/test_key_stroke.rb @@ -1,18 +1,6 @@ require_relative 'helper' class Reline::KeyStroke::Test < Reline::TestCase - using Module.new { - refine Array do - def as_s - join - end - - def to_keys - map{ |b| Reline::Key.new(b, b, false) } - end - end - } - def encoding Reline.core.encoding end @@ -65,14 +53,14 @@ class Reline::KeyStroke::Test < Reline::TestCase def test_expand config = Reline::Config.new { - 'abc' => '123', - 'ab' => '456' + 'abc' => 'AB', + 'ab' => "1\C-a" }.each_pair do |key, func| config.add_default_key_binding(key.bytes, func.bytes) end stroke = Reline::KeyStroke.new(config, encoding) - assert_equal(['123'.bytes.map { |c| Reline::Key.new(c, c, false) }, 'de'.bytes], stroke.expand('abcde'.bytes)) - assert_equal(['456'.bytes.map { |c| Reline::Key.new(c, c, false) }, 'de'.bytes], stroke.expand('abde'.bytes)) + assert_equal([[Reline::Key.new('A', :ed_insert, false), Reline::Key.new('B', :ed_insert, false)], 'de'.bytes], stroke.expand('abcde'.bytes)) + assert_equal([[Reline::Key.new('1', :ed_digit, false), Reline::Key.new("\C-a", :ed_move_to_beg, false)], 'de'.bytes], stroke.expand('abde'.bytes)) # CSI sequence assert_equal([[], 'bc'.bytes], stroke.expand("\e[1;2;3;4;5abc".bytes)) assert_equal([[], 'BC'.bytes], stroke.expand("\e\e[ABC".bytes)) @@ -83,24 +71,17 @@ class Reline::KeyStroke::Test < Reline::TestCase def test_oneshot_key_bindings config = Reline::Config.new { - 'abc' => '123', - }.each_pair do |key, func| - config.add_default_key_binding(key.bytes, func.bytes) - end - stroke = Reline::KeyStroke.new(config, encoding) - assert_equal(Reline::KeyStroke::UNMATCHED, stroke.match_status('zzz'.bytes)) - assert_equal(Reline::KeyStroke::MATCHED, stroke.match_status('abc'.bytes)) - end - - def test_with_reline_key - config = Reline::Config.new - { + 'abc'.bytes => '123', + # IRB version <= 1.13.1 wrongly uses Reline::Key with wrong argument. It should be ignored without error. + [Reline::Key.new(nil, 0xE4, true)] => '012', "\eda".bytes => 'abc', # Alt+d a [195, 164] => 'def' }.each_pair do |key, func| config.add_oneshot_key_binding(key, func.bytes) end stroke = Reline::KeyStroke.new(config, encoding) + assert_equal(Reline::KeyStroke::UNMATCHED, stroke.match_status('zzz'.bytes)) + assert_equal(Reline::KeyStroke::MATCHED, stroke.match_status('abc'.bytes)) assert_equal(Reline::KeyStroke::UNMATCHED, stroke.match_status('da'.bytes)) assert_equal(Reline::KeyStroke::MATCHED, stroke.match_status("\eda".bytes)) assert_equal(Reline::KeyStroke::UNMATCHED, stroke.match_status(" \eda".bytes)) @@ -115,7 +96,7 @@ class Reline::KeyStroke::Test < Reline::TestCase end config = Reline::Config.new stroke = Reline::KeyStroke.new(config, encoding) - key = Reline::Key.new(char.ord, char.ord, false) + key = Reline::Key.new(char, :ed_insert, false) bytes = char.bytes assert_equal(Reline::KeyStroke::MATCHED, stroke.match_status(bytes)) assert_equal([[key], []], stroke.expand(bytes)) diff --git a/test/reline/test_macro.rb b/test/reline/test_macro.rb index bfee280c72..cacdb76c60 100644 --- a/test/reline/test_macro.rb +++ b/test/reline/test_macro.rb @@ -14,12 +14,12 @@ class Reline::MacroTest < Reline::TestCase Reline.test_reset end - def input_key(char, combined_char = char, with_meta = false) - @line_editor.input_key(Reline::Key.new(char, combined_char, with_meta)) + def input_key(char, method_symbol = :ed_insert) + @line_editor.input_key(Reline::Key.new(char, method_symbol, false)) end def input(str) - str.each_byte {|c| input_key(c)} + str.each_char {|c| input_key(c)} end def test_simple_input @@ -33,7 +33,7 @@ class Reline::MacroTest < Reline::TestCase end input('abc') assert_nothing_raised(ArgumentError) { - input_key(:delete_char) + input_key('x', :delete_char) } assert_equal 'ab', @line_editor.line end diff --git a/test/reline/test_reline_key.rb b/test/reline/test_reline_key.rb index 1e6b9fcb6c..b6260d57d6 100644 --- a/test/reline/test_reline_key.rb +++ b/test/reline/test_reline_key.rb @@ -3,9 +3,8 @@ require "reline" class Reline::TestKey < Reline::TestCase def test_match_symbol - assert(Reline::Key.new(:key1, :key1, false).match?(:key1)) - refute(Reline::Key.new(:key1, :key1, false).match?(:key2)) - refute(Reline::Key.new(:key1, :key1, false).match?(nil)) - refute(Reline::Key.new(1, 1, false).match?(:key1)) + assert(Reline::Key.new('a', :key1, false).match?(:key1)) + refute(Reline::Key.new('a', :key1, false).match?(:key2)) + refute(Reline::Key.new('a', :key1, false).match?(nil)) end end diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 93bec515d1..e9f9ee66d2 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -271,7 +271,7 @@ begin write("\e") # single ESC sleep 1 write("A") - write("B\eAC") # ESC + A (M-A, specified ed_unassigned in Reline::KeyActor::Emacs) + write("B\eAC") # ESC + A (M-A, no key specified in Reline::KeyActor::Emacs) assert_screen(<<~EOC) Multiline REPL. prompt> abcABCdef |