[ruby/reline] Refactor utf-8 strings and invalid strings in test
code (https://github.com/ruby/reline/pull/800) * Remove invalid encoding string "\M-[char]" from test code, remove unused code/arg/options * Omit unicode unnoralized input test in non-utf8 testcase * Remove helper method and constant no longer used in testcode * Change key binding test to use realistic bytes instead of invalid byte sequence * Remove invalid byte sequence input from rendering test yamatanooroti handles invalid byte sequence input "\M-[char]" and converts it to "\e[char]" We don't need to use these invalid byte sequence and rely on the hack implemented in yamatanooroti https://github.com/ruby/reline/commit/f09e7b154c
This commit is contained in:
parent
9a15672614
commit
a70206c439
@ -34,7 +34,6 @@ class Reline::Unicode
|
||||
0x1F => '^_', # C-_ C-7
|
||||
0x7F => '^?', # C-? C-8
|
||||
}
|
||||
EscapedChars = EscapedPairs.keys.map(&:chr)
|
||||
|
||||
NON_PRINTING_START = "\1"
|
||||
NON_PRINTING_END = "\2"
|
||||
|
@ -86,26 +86,12 @@ module Reline
|
||||
end
|
||||
|
||||
class Reline::TestCase < Test::Unit::TestCase
|
||||
private def convert_str(input, options = {}, normalized = nil)
|
||||
return nil if input.nil?
|
||||
input = input.chars.map { |c|
|
||||
if Reline::Unicode::EscapedChars.include?(c.ord)
|
||||
c
|
||||
else
|
||||
c.encode(@line_editor.encoding, Encoding::UTF_8, **options)
|
||||
end
|
||||
}.join
|
||||
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
|
||||
if unicode?(input.encoding)
|
||||
input = input.unicode_normalize(:nfc)
|
||||
if normalized
|
||||
options[:undef] = :replace
|
||||
options[:replace] = '?'
|
||||
end
|
||||
normalized = true
|
||||
retry
|
||||
end
|
||||
input
|
||||
private def convert_str(input)
|
||||
input.encode(@line_editor.encoding, Encoding::UTF_8)
|
||||
end
|
||||
|
||||
def omit_unless_utf8
|
||||
omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8
|
||||
end
|
||||
|
||||
def input_key_by_symbol(method_symbol, char: nil, csi: false)
|
||||
@ -113,17 +99,9 @@ class Reline::TestCase < Test::Unit::TestCase
|
||||
@line_editor.input_key(Reline::Key.new(char, method_symbol, false))
|
||||
end
|
||||
|
||||
def input_keys(input, convert = true)
|
||||
# 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_keys(input)
|
||||
input = convert_str(input)
|
||||
|
||||
def input_raw_keys(input, convert = true)
|
||||
input = convert_str(input) if convert
|
||||
key_stroke = Reline::KeyStroke.new(@config, @encoding)
|
||||
input_bytes = input.bytes
|
||||
until input_bytes.empty?
|
||||
@ -177,8 +155,4 @@ class Reline::TestCase < Test::Unit::TestCase
|
||||
assert_equal(method_symbol, @config.editing_mode.get(input.bytes))
|
||||
end
|
||||
end
|
||||
|
||||
private def unicode?(encoding)
|
||||
[Encoding::UTF_8, Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(encoding)
|
||||
end
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -103,11 +103,13 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_ed_insert_for_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("か\u3099")
|
||||
assert_line_around_cursor("か\u3099", '')
|
||||
end
|
||||
|
||||
def test_ed_insert_for_plural_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("か\u3099き\u3099")
|
||||
assert_line_around_cursor("か\u3099き\u3099", '')
|
||||
end
|
||||
@ -208,6 +210,7 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_vi_paste_prev_for_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("か\u3099き\u3099く\u3099け\u3099こ\u3099\C-[3h")
|
||||
assert_line_around_cursor("か\u3099", "き\u3099く\u3099け\u3099こ\u3099")
|
||||
input_keys('P')
|
||||
@ -221,6 +224,7 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_vi_paste_next_for_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("か\u3099き\u3099く\u3099け\u3099こ\u3099\C-[3h")
|
||||
assert_line_around_cursor("か\u3099", "き\u3099く\u3099け\u3099こ\u3099")
|
||||
input_keys('p')
|
||||
@ -438,6 +442,7 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_vi_delete_next_char_for_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("か\u3099き\u3099く\u3099\C-[h")
|
||||
assert_line_around_cursor("か\u3099", "き\u3099く\u3099")
|
||||
input_keys('x')
|
||||
@ -465,6 +470,7 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_vi_delete_prev_char_for_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("か\u3099き\u3099")
|
||||
assert_line_around_cursor("か\u3099き\u3099", '')
|
||||
input_keys("\C-h")
|
||||
@ -509,6 +515,7 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_ed_delete_prev_word_for_mbchar_by_plural_code_points
|
||||
omit_unless_utf8
|
||||
input_keys("あいう か\u3099き\u3099く\u3099{さしす}たちつ")
|
||||
assert_line_around_cursor("あいう か\u3099き\u3099く\u3099{さしす}たちつ", '')
|
||||
input_keys("\C-w")
|
||||
@ -659,9 +666,9 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
}
|
||||
input_keys('Re')
|
||||
assert_line_around_cursor('Re', '')
|
||||
input_keys("\C-i", false)
|
||||
input_keys("\C-i")
|
||||
assert_line_around_cursor('Readline', '')
|
||||
input_keys("\C-i", false)
|
||||
input_keys("\C-i")
|
||||
assert_line_around_cursor('Regexp', '')
|
||||
input_key_by_symbol(:completion_journey_up)
|
||||
assert_line_around_cursor('Readline', '')
|
||||
@ -682,9 +689,9 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
}
|
||||
input_keys('Re')
|
||||
assert_line_around_cursor('Re', '')
|
||||
input_keys("\C-i", false)
|
||||
input_keys("\C-i")
|
||||
assert_line_around_cursor('Readline', '')
|
||||
input_keys("\C-i", false)
|
||||
input_keys("\C-i")
|
||||
assert_line_around_cursor('Regexp', '')
|
||||
input_key_by_symbol(:menu_complete_backward)
|
||||
assert_line_around_cursor('Readline', '')
|
||||
@ -924,16 +931,16 @@ class Reline::ViInsertTest < Reline::TestCase
|
||||
end
|
||||
|
||||
def test_vi_kill_line_prev
|
||||
input_keys("\C-u", false)
|
||||
input_keys("\C-u")
|
||||
assert_line_around_cursor('', '')
|
||||
input_keys('abc')
|
||||
assert_line_around_cursor('abc', '')
|
||||
input_keys("\C-u", false)
|
||||
input_keys("\C-u")
|
||||
assert_line_around_cursor('', '')
|
||||
input_keys('abc')
|
||||
input_keys("\C-[\C-u", false)
|
||||
input_keys("\C-[\C-u")
|
||||
assert_line_around_cursor('', 'c')
|
||||
input_keys("\C-u", false)
|
||||
input_keys("\C-u")
|
||||
assert_line_around_cursor('', 'c')
|
||||
end
|
||||
|
||||
|
@ -42,9 +42,9 @@ class Reline::WithinPipeTest < Reline::TestCase
|
||||
@config.add_default_key_binding("\C-x\C-e".bytes, :end_of_line)
|
||||
@config.add_default_key_binding("\C-x\C-f".bytes, :forward_char)
|
||||
@config.add_default_key_binding("\C-x\C-b".bytes, :backward_char)
|
||||
@config.add_default_key_binding("\C-x\M-f".bytes, :forward_word)
|
||||
@config.add_default_key_binding("\C-x\M-b".bytes, :backward_word)
|
||||
@writer.write(" def\C-x\C-aabc\C-x\C-e ghi\C-x\C-a\C-x\C-f\C-x\C-f_\C-x\C-b\C-x\C-b_\C-x\C-f\C-x\C-f\C-x\C-f\C-x\M-f_\C-x\M-b\n")
|
||||
@config.add_default_key_binding("\C-x\ef".bytes, :forward_word)
|
||||
@config.add_default_key_binding("\C-x\eb".bytes, :backward_word)
|
||||
@writer.write(" def\C-x\C-aabc\C-x\C-e ghi\C-x\C-a\C-x\C-f\C-x\C-f_\C-x\C-b\C-x\C-b_\C-x\C-f\C-x\C-f\C-x\C-f\C-x\ef_\C-x\eb\n")
|
||||
assert_equal 'a_b_c def_ ghi', Reline.readmultiline(&proc{ true })
|
||||
end
|
||||
|
||||
@ -54,11 +54,11 @@ class Reline::WithinPipeTest < Reline::TestCase
|
||||
@config.add_default_key_binding("\C-x\C-v".bytes, :quoted_insert)
|
||||
#@config.add_default_key_binding("\C-xa".bytes, :self_insert)
|
||||
@config.add_default_key_binding("\C-x\C-t".bytes, :transpose_chars)
|
||||
@config.add_default_key_binding("\C-x\M-t".bytes, :transpose_words)
|
||||
@config.add_default_key_binding("\C-x\M-u".bytes, :upcase_word)
|
||||
@config.add_default_key_binding("\C-x\M-l".bytes, :downcase_word)
|
||||
@config.add_default_key_binding("\C-x\M-c".bytes, :capitalize_word)
|
||||
@writer.write("abcde\C-b\C-b\C-b\C-x\C-d\C-x\C-h\C-x\C-v\C-a\C-f\C-f EF\C-x\C-t gh\C-x\M-t\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-x\M-u\C-x\M-l\C-x\M-c\n")
|
||||
@config.add_default_key_binding("\C-x\et".bytes, :transpose_words)
|
||||
@config.add_default_key_binding("\C-x\eu".bytes, :upcase_word)
|
||||
@config.add_default_key_binding("\C-x\el".bytes, :downcase_word)
|
||||
@config.add_default_key_binding("\C-x\ec".bytes, :capitalize_word)
|
||||
@writer.write("abcde\C-b\C-b\C-b\C-x\C-d\C-x\C-h\C-x\C-v\C-a\C-f\C-f EF\C-x\C-t gh\C-x\et\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-x\eu\C-x\el\C-x\ec\n")
|
||||
assert_equal "a\C-aDE gh Fe", Reline.readmultiline(&proc{ true })
|
||||
end
|
||||
|
||||
|
@ -571,7 +571,7 @@ begin
|
||||
Multiline REPL.
|
||||
prompt> abc
|
||||
EOC
|
||||
write("\M-\C-_")
|
||||
write("\e\C-_")
|
||||
assert_screen(<<~EOC)
|
||||
Multiline REPL.
|
||||
prompt> abcdef hoge
|
||||
@ -853,7 +853,7 @@ begin
|
||||
|
||||
def test_meta_key
|
||||
start_terminal(30, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
|
||||
write("def ge\M-bho")
|
||||
write("def ge\ebho")
|
||||
assert_screen(<<~EOC)
|
||||
Multiline REPL.
|
||||
prompt> def hoge
|
||||
@ -874,7 +874,7 @@ begin
|
||||
def test_force_enter
|
||||
start_terminal(30, 120, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
|
||||
write("def hoge\nend\C-p\C-e")
|
||||
write("\M-\x0D")
|
||||
write("\e\x0D")
|
||||
assert_screen(<<~EOC)
|
||||
Multiline REPL.
|
||||
prompt> def hoge
|
||||
@ -919,7 +919,7 @@ begin
|
||||
|
||||
def test_em_set_mark_and_em_exchange_mark
|
||||
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
|
||||
write("aaa bbb ccc ddd\M-b\M-b\M-\x20\M-b\C-x\C-xX\C-x\C-xY")
|
||||
write("aaa bbb ccc ddd\eb\eb\e\x20\eb\C-x\C-xX\C-x\C-xY")
|
||||
assert_screen(<<~'EOC')
|
||||
Multiline REPL.
|
||||
prompt> aaa Ybbb Xccc ddd
|
||||
@ -1519,7 +1519,7 @@ begin
|
||||
def test_rerender_argument_prompt_after_pasting
|
||||
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
|
||||
write('abcdef')
|
||||
write("\M-3\C-h")
|
||||
write("\e3\C-h")
|
||||
assert_screen(<<~'EOC')
|
||||
Multiline REPL.
|
||||
prompt> abc
|
||||
@ -1655,7 +1655,7 @@ begin
|
||||
write("class A\n def a\n 3\n end\nend")
|
||||
write("\n")
|
||||
write("\C-p\C-p\C-p\C-p\C-p\C-e\C-hS")
|
||||
write("\M-\x0D")
|
||||
write("\e\x0D")
|
||||
write(" 3")
|
||||
assert_screen(<<~'EOC')
|
||||
prompt> 3
|
||||
|
Loading…
x
Reference in New Issue
Block a user