mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
![aycabta](/assets/img/avatar_default.png)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
require_relative 'helper'
|
|
|
|
class Reline::KeyStroke::Test < Reline::TestCase
|
|
using Module.new {
|
|
refine Array do
|
|
def as_s
|
|
map(&:chr).join
|
|
end
|
|
end
|
|
}
|
|
|
|
def test_input_to!
|
|
config = {
|
|
key_mapping: {
|
|
"a" => "xx",
|
|
"ab" => "y",
|
|
"abc" => "z",
|
|
"x" => "rr"
|
|
}
|
|
}
|
|
stroke = Reline::KeyStroke.new(config)
|
|
result = ("abzwabk".bytes).map { |char|
|
|
stroke.input_to!(char)&.then { |result|
|
|
"#{result.as_s}"
|
|
}
|
|
}
|
|
assert_equal(result, [nil, nil, "yz", "w", nil, nil, "yk"])
|
|
end
|
|
|
|
def test_input_to
|
|
config = {
|
|
key_mapping: {
|
|
"a" => "xx",
|
|
"ab" => "y",
|
|
"abc" => "z",
|
|
"x" => "rr"
|
|
}
|
|
}
|
|
stroke = Reline::KeyStroke.new(config)
|
|
assert_equal(stroke.input_to("a".bytes)&.as_s, nil)
|
|
assert_equal(stroke.input_to("ab".bytes)&.as_s, nil)
|
|
assert_equal(stroke.input_to("abc".bytes)&.as_s, "z")
|
|
assert_equal(stroke.input_to("abz".bytes)&.as_s, "yz")
|
|
assert_equal(stroke.input_to("abx".bytes)&.as_s, "yrr")
|
|
assert_equal(stroke.input_to("ac".bytes)&.as_s, "rrrrc")
|
|
assert_equal(stroke.input_to("aa".bytes)&.as_s, "rrrrrrrr")
|
|
assert_equal(stroke.input_to("x".bytes)&.as_s, "rr")
|
|
assert_equal(stroke.input_to("m".bytes)&.as_s, "m")
|
|
assert_equal(stroke.input_to("abzwabk".bytes)&.as_s, "yzwabk")
|
|
end
|
|
end
|