2019-04-27 01:53:09 -04:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class Reline::KeyStroke::Test < Reline::TestCase
|
|
|
|
using Module.new {
|
|
|
|
refine Array do
|
|
|
|
def as_s
|
2019-05-24 10:38:40 -04:00
|
|
|
join
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_keys
|
|
|
|
map{ |b| Reline::Key.new(b, b, false) }
|
2019-04-27 01:53:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2019-05-24 10:38:40 -04:00
|
|
|
def test_match_status
|
2019-05-31 20:05:58 -04:00
|
|
|
config = Reline::Config.new
|
|
|
|
{
|
2020-07-12 10:21:36 -04:00
|
|
|
'a' => 'xx',
|
|
|
|
'ab' => 'y',
|
|
|
|
'abc' => 'z',
|
|
|
|
'x' => 'rr'
|
2019-05-31 20:05:58 -04:00
|
|
|
}.each_pair do |key, func|
|
|
|
|
config.add_default_key_binding(key.bytes, func.bytes)
|
|
|
|
end
|
2019-04-27 01:53:09 -04:00
|
|
|
stroke = Reline::KeyStroke.new(config)
|
2019-05-24 10:38:40 -04:00
|
|
|
assert_equal(:matching, stroke.match_status("a".bytes))
|
|
|
|
assert_equal(:matching, stroke.match_status("ab".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("abc".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("abz".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("abx".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("ac".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("aa".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("x".bytes))
|
|
|
|
assert_equal(:unmatched, stroke.match_status("m".bytes))
|
|
|
|
assert_equal(:matched, stroke.match_status("abzwabk".bytes))
|
2019-04-27 01:53:09 -04:00
|
|
|
end
|
2020-07-12 10:21:36 -04:00
|
|
|
|
2021-09-05 17:53:36 -04:00
|
|
|
def test_expand
|
2020-07-12 10:21:36 -04:00
|
|
|
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('123'.bytes, stroke.expand('abc'.bytes))
|
|
|
|
end
|
2021-09-05 18:01:46 -04:00
|
|
|
|
|
|
|
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
|
2019-04-27 01:53:09 -04:00
|
|
|
end
|