From c7ed7ae8488c29461405501f0192741453ffd3a7 Mon Sep 17 00:00:00 2001 From: Mari Imaizumi Date: Thu, 26 Sep 2024 15:22:14 +0900 Subject: [PATCH] wip --- test/reline/helper.rb | 21 ++++++++---- test/reline/test_key_actor_emacs.rb | 53 +++++++++++++++-------------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/test/reline/helper.rb b/test/reline/helper.rb index a76a360ec7..b22e6bbe5d 100644 --- a/test/reline/helper.rb +++ b/test/reline/helper.rb @@ -88,7 +88,7 @@ def test_rubybin class Reline::TestCase < Test::Unit::TestCase private def convert_str(input, options = {}, normalized = nil) return nil if input.nil? - input.chars.map { |c| + input = input.chars.map { |c| if Reline::Unicode::EscapedChars.include?(c.ord) c else @@ -96,13 +96,16 @@ class Reline::TestCase < Test::Unit::TestCase end }.join rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError - input = input.unicode_normalize(:nfc) - if normalized - options[:undef] = :replace - options[:replace] = '?' + if unicode?(input.encoding) + input = input.unicode_normalize(:nfc) + if normalized + options[:undef] = :replace + options[:replace] = '?' + end + normalized = true + retry end - normalized = true - retry + input end def input_key_by_symbol(input) @@ -171,4 +174,8 @@ def assert_key_binding(input, method_symbol, editing_modes = [:emacs, :vi_insert assert_equal(method_symbol, @config.editing_mode.get(input.bytes)) end end + + private def unicode?(encoding) + encoding == Encoding::UTF_8 || encoding == Encoding::UTF_16BE || encoding == Encoding::UTF_16LE || encoding == Encoding::UTF_32BE || encoding == Encoding::UTF_32LE + end end diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 4dddf9c890..45025d9346 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -1424,6 +1424,7 @@ def test_ed_argument_digit_by_meta_num end def test_halfwidth_kana_width_dakuten + omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8 input_raw_keys('ガギゲゴ') assert_line_around_cursor('ガギゲゴ', '') input_keys("\C-b\C-b", false) @@ -1456,31 +1457,31 @@ def test_vi_editing_mode def test_undo input_keys("\C-_", false) assert_line_around_cursor('', '') - input_keys("aあb\C-h\C-h\C-h", false) - assert_line_around_cursor('', '') + input_keys("aあb\C-h\C-h\C-h".encode(@encoding), false) + assert_line_around_cursor(''.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('a', '') + assert_line_around_cursor('a'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('aあ', '') + assert_line_around_cursor('aあ'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('aあb', '') + assert_line_around_cursor('aあb'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('aあ', '') + assert_line_around_cursor('aあ'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('a', '') + assert_line_around_cursor('a'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('', '') + assert_line_around_cursor(''.encode(@encoding), '') end def test_undo_with_cursor_position - input_keys("abc\C-b\C-h", false) - assert_line_around_cursor('a', 'c') - input_keys("\C-_", false) - assert_line_around_cursor('ab', 'c') - input_keys("あいう\C-b\C-h", false) - assert_line_around_cursor('abあ', 'うc') - input_keys("\C-_", false) - assert_line_around_cursor('abあい', 'うc') + input_keys("abc\C-b\C-h".encode(@encoding), false) + assert_line_around_cursor('a'.encode(@encoding), 'c'.encode(@encoding)) + input_keys("\C-_".encode(@encoding), false) + assert_line_around_cursor('ab'.encode(@encoding), 'c'.encode(@encoding)) + input_keys("あいう\C-b\C-h".encode(@encoding), false) + assert_line_around_cursor('abあ'.encode(@encoding), 'うc'.encode(@encoding)) + input_keys("\C-_".encode(@encoding), false) + assert_line_around_cursor('abあい'.encode(@encoding), 'うc'.encode(@encoding)) end def test_undo_with_multiline @@ -1522,24 +1523,24 @@ def test_undo_with_many_times end def test_redo - input_keys("aあb", false) - assert_line_around_cursor('aあb', '') + input_keys("aあb".encode(@encoding), false) + assert_line_around_cursor('aあb'.encode(@encoding), '') input_keys("\M-\C-_", false) - assert_line_around_cursor('aあb', '') + assert_line_around_cursor('aあb'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('aあ', '') + assert_line_around_cursor('aあ'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('a', '') + assert_line_around_cursor('a'.encode(@encoding), '') input_keys("\M-\C-_", false) - assert_line_around_cursor('aあ', '') + assert_line_around_cursor('aあ'.encode(@encoding), '') input_keys("\M-\C-_", false) - assert_line_around_cursor('aあb', '') + assert_line_around_cursor('aあb'.encode(@encoding), '') input_keys("\C-_", false) - assert_line_around_cursor('aあ', '') + assert_line_around_cursor('aあ'.encode(@encoding), '') input_keys("c", false) - assert_line_around_cursor('aあc', '') + assert_line_around_cursor('aあc'.encode(@encoding), '') input_keys("\M-\C-_", false) - assert_line_around_cursor('aあc', '') + assert_line_around_cursor('aあc'.encode(@encoding), '') end def test_redo_with_cursor_position