Skip to content

Commit

Permalink
Omit unicode unnoralized input test in non-utf8 testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 1, 2025
1 parent 0692782 commit 38300af
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
14 changes: 4 additions & 10 deletions test/reline/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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{さしす}たちつ")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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さ")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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('👨', '')
Expand All @@ -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', '')
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/reline/test_key_actor_vi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 38300af

Please sign in to comment.