diff options
author | aycabta <aycabta@gmail.com> | 2019-04-27 14:53:09 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-04-30 11:44:20 +0900 |
commit | 17350c7e5534c8678097d70698fe08614a6c3997 (patch) | |
tree | 0f41959093014a97d50aeb06a052f5450b4cb6b1 /test/reline/test_key_stroke.rb | |
parent | eb45ba61160dbae412407f232fe9b3252eb99362 (diff) |
Add Reline as a fallback library for Readline
* lib/reine.rb, lib/reline/*: Reline is a readline stdlib compatible
library.
* lib/readline.rb: Readline uses a fallback to Reline when ext/readline
doesn't exist.
* tool/sync_default_gems.rb: add ruby/reline as a default gem.
* appveyor.yml: add "set RELINE_TEST_ENCODING=Windows-31J" for test suit
of Reline, and add "--exclude readline" to "nmake test-all" on Visual
Studio builds because of strange behavior.
* spec/ruby/library/readline/spec_helper.rb: skip Reline as with
RbReadline.
Diffstat (limited to 'test/reline/test_key_stroke.rb')
-rw-r--r-- | test/reline/test_key_stroke.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/reline/test_key_stroke.rb b/test/reline/test_key_stroke.rb new file mode 100644 index 0000000000..b6d5ce4150 --- /dev/null +++ b/test/reline/test_key_stroke.rb @@ -0,0 +1,51 @@ +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 |