From 38300af2bb84c3bd4a1be794c10cff650d7711a3 Mon Sep 17 00:00:00 2001 From: tompng Date: Thu, 2 Jan 2025 02:23:43 +0900 Subject: [PATCH] Omit unicode unnoralized input test in non-utf8 testcase --- test/reline/helper.rb | 14 ++++---------- test/reline/test_key_actor_emacs.rb | 18 +++++++++++++++--- test/reline/test_key_actor_vi.rb | 7 +++++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/test/reline/helper.rb b/test/reline/helper.rb index 552c21778f..f76a1c0b19 100644 --- a/test/reline/helper.rb +++ b/test/reline/helper.rb @@ -87,17 +87,11 @@ def test_rubybin class Reline::TestCase < Test::Unit::TestCase private def convert_str(input) - return nil if input.nil? input.encode(@line_editor.encoding, Encoding::UTF_8) - rescue Encoding::UndefinedConversionError - return input unless unicode?(input.encoding) - - input = input.unicode_normalize(:nfc) - begin - input.encode(@line_editor.encoding, Encoding::UTF_8) - rescue Encoding::UndefinedConversionError - input.encode(@line_editor.encoding, Encoding::UTF_8, undef: :replace, replace: '?') - end + 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) diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 43794205a1..a67119e052 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -38,11 +38,13 @@ def test_ed_insert_mbchar_two 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 @@ -74,6 +76,7 @@ def test_move_next_and_prev_for_mbchar end def test_move_next_and_prev_for_mbchar_by_plural_code_points + omit_unless_utf8 input_keys("か\u3099き\u3099け\u3099") assert_line_around_cursor("か\u3099き\u3099け\u3099", '') input_keys("\C-b") @@ -132,6 +135,7 @@ def test_em_delete_prev_char_for_mbchar end def test_em_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") @@ -254,6 +258,7 @@ def test_em_delete_for_mbchar end def test_em_delete_for_mbchar_by_plural_code_points + omit_unless_utf8 input_keys("か\u3099き\u3099") assert_line_around_cursor("か\u3099き\u3099", '') input_keys("\C-a") @@ -336,6 +341,7 @@ def test_em_next_word_for_mbchar end def test_em_next_word_for_mbchar_by_plural_code_points + omit_unless_utf8 assert_line_around_cursor("", "") input_keys("あいう か\u3099き\u3099く\u3099{さしす}たちつ") input_keys("\C-a\eF") @@ -381,6 +387,7 @@ def test_em_prev_word_for_mbchar end def test_em_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("\eB") @@ -424,6 +431,7 @@ def test_em_delete_next_word_for_mbchar end def test_em_delete_next_word_for_mbchar_by_plural_code_points + omit_unless_utf8 input_keys("あいう か\u3099き\u3099く\u3099{さしす}たちつ") input_keys("\C-a") assert_line_around_cursor('', "あいう か\u3099き\u3099く\u3099{さしす}たちつ") @@ -464,6 +472,7 @@ def test_ed_delete_prev_word_for_mbchar 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("\e\C-H") @@ -505,6 +514,7 @@ def test_ed_transpose_chars_for_mbchar end def test_ed_transpose_chars_for_mbchar_by_plural_code_points + omit_unless_utf8 input_keys("あか\u3099さ") input_keys("\C-a") assert_line_around_cursor('', "あか\u3099さ") @@ -642,6 +652,7 @@ def test_ed_next_and_prev_char_for_mbchar end def test_ed_next_and_prev_char_for_mbchar_by_plural_code_points + omit_unless_utf8 input_keys("か\u3099き\u3099く\u3099") assert_line_around_cursor("か\u3099き\u3099く\u3099", '') input_keys("\C-b") @@ -1407,7 +1418,7 @@ def test_incremental_search_history_saves_and_restores_last_input # Unicode emoji test def test_ed_insert_for_include_zwj_emoji - omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8 + omit_unless_utf8 # U+1F468 U+200D U+1F469 U+200D U+1F467 U+200D U+1F466 is family: man, woman, girl, boy "👨‍👩‍👧‍👦" input_keys("\u{1F468}") # U+1F468 is man "👨" assert_line_around_cursor('👨', '') @@ -1429,7 +1440,7 @@ def test_ed_insert_for_include_zwj_emoji end def test_ed_insert_for_include_valiation_selector - omit "This test is for UTF-8 but the locale is #{Reline.core.encoding}" if Reline.core.encoding != Encoding::UTF_8 + omit_unless_utf8 # U+0030 U+FE00 is DIGIT ZERO + VARIATION SELECTOR-1 "0︀" input_keys("\u0030") # U+0030 is DIGIT ZERO assert_line_around_cursor('0', '') @@ -1503,7 +1514,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 + omit_unless_utf8 input_keys('ガギゲゴ') assert_line_around_cursor('ガギゲゴ', '') input_keys("\C-b\C-b") @@ -1513,6 +1524,7 @@ def test_halfwidth_kana_width_dakuten end def test_input_unknown_char + omit_unless_utf8 input_keys('͸') # U+0378 (unassigned) assert_line_around_cursor('͸', '') end diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index 56c51c0b9e..083433f9a8 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -103,11 +103,13 @@ def test_ed_insert_mbchar_two 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 @@ def test_vi_paste_next_for_mbchar 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 @@ def test_vi_paste_prev_for_mbchar_by_plural_code_points 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 @@ def test_vi_delete_next_char_for_mbchar 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 @@ def test_vi_delete_prev_char_for_mbchar 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 @@ def test_ed_delete_prev_word_for_mbchar 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")