Skip to content

Commit

Permalink
Merge pull request #334 from aycabta/add-tests-for-unicode
Browse files Browse the repository at this point in the history
Add tests for Unicode and key bindings
  • Loading branch information
aycabta committed Sep 5, 2021
2 parents 0291be5 + cadbd57 commit 86f3dfb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/reline/test_key_stroke.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_match_status
assert_equal(:matched, stroke.match_status("abzwabk".bytes))
end

def test_aaa
def test_expand
config = Reline::Config.new
{
'abc' => '123',
Expand All @@ -46,4 +46,34 @@ def test_aaa
stroke = Reline::KeyStroke.new(config)
assert_equal('123'.bytes, stroke.expand('abc'.bytes))
end

def test_oneshot_key_bindings
config = Reline::Config.new
{
'abc' => '123',
}.each_pair do |key, func|
config.add_default_key_binding(key.bytes, func.bytes)
end
stroke = Reline::KeyStroke.new(config)
assert_equal(:unmatched, stroke.match_status('zzz'.bytes))
assert_equal(:matched, stroke.match_status('abc'.bytes))
end

def test_with_reline_key
config = Reline::Config.new
{
[
Reline::Key.new(100, 228, true), # Alt+d
Reline::Key.new(97, 97, false) # a
] => 'abc',
[195, 164] => 'def'
}.each_pair do |key, func|
config.add_oneshot_key_binding(key, func.bytes)
end
stroke = Reline::KeyStroke.new(config)
assert_equal(:unmatched, stroke.match_status('da'.bytes))
assert_equal(:matched, stroke.match_status("\M-da".bytes))
assert_equal(:unmatched, stroke.match_status([32, 195, 164]))
assert_equal(:matched, stroke.match_status([195, 164]))
end
end
5 changes: 5 additions & 0 deletions test/reline/test_unicode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ def test_get_mbchar_width
def test_ambiguous_width
assert_equal 2, Reline::Unicode.calculate_width('√', true)
end

def test_take_range
assert_equal 'cdef', Reline::Unicode.take_range('abcdefghi', 2, 4)
assert_equal 'いう', Reline::Unicode.take_range('あいうえお', 2, 4)
end
end

0 comments on commit 86f3dfb

Please sign in to comment.