Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ima1zumi committed Sep 26, 2024
1 parent 171bf20 commit c7ed7ae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
21 changes: 14 additions & 7 deletions test/reline/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ 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
c.encode(@line_editor.instance_variable_get(:@encoding), Encoding::UTF_8, **options)
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)
Expand Down Expand Up @@ -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
53 changes: 27 additions & 26 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7ed7ae

Please sign in to comment.