1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/reline/test_within_pipe.rb

58 lines
2.4 KiB
Ruby
Raw Normal View History

2019-06-01 18:39:12 -04:00
require_relative 'helper'
class Reline::WithinPipeTest < Reline::TestCase
def setup
Reline.send(:test_mode)
@reader, @writer = IO.pipe((RELINE_TEST_ENCODING rescue Encoding.default_external))
Reline.input = @reader
2019-06-02 14:38:39 -04:00
@output = Reline.output = File.open(IO::NULL, 'w')
2019-06-01 18:39:12 -04:00
@config = Reline.class_variable_get(:@@config)
@line_editor = Reline.class_variable_get(:@@line_editor)
end
def teardown
Reline.input = STDIN
Reline.output = STDOUT
@reader.close
@writer.close
2019-06-02 14:38:39 -04:00
@output.close
2019-06-01 18:39:12 -04:00
@config.reset
end
def test_simple_input
@writer.write("abc\n")
assert_equal 'abc', Reline.readmultiline(&proc{ true })
end
2019-06-01 19:50:01 -04:00
def test_unknown_macro
@config.add_default_key_binding('abc'.bytes, :unknown_macro)
@writer.write("abcd\n")
assert_equal 'd', Reline.readmultiline(&proc{ true })
end
def test_macro_commands_for_moving
@config.add_default_key_binding("\C-x\C-a".bytes, :beginning_of_line)
@config.add_default_key_binding("\C-x\C-e".bytes, :end_of_line)
@config.add_default_key_binding("\C-x\C-f".bytes, :forward_char)
@config.add_default_key_binding("\C-x\C-b".bytes, :backward_char)
@config.add_default_key_binding("\C-x\M-f".bytes, :forward_word)
@config.add_default_key_binding("\C-x\M-b".bytes, :backward_word)
@writer.write(" def\C-x\C-aabc\C-x\C-e ghi\C-x\C-a\C-x\C-f\C-x\C-f_\C-x\C-b\C-x\C-b_\C-x\C-f\C-x\C-f\C-x\C-f\C-x\M-f_\C-x\M-b\n")
assert_equal 'a_b_c def_ ghi', Reline.readmultiline(&proc{ true })
end
def test_macro_commands_for_moving
@config.add_default_key_binding("\C-x\C-d".bytes, :delete_char)
@config.add_default_key_binding("\C-x\C-h".bytes, :backward_delete_char)
@config.add_default_key_binding("\C-x\C-v".bytes, :quoted_insert)
#@config.add_default_key_binding("\C-xa".bytes, :self_insert)
@config.add_default_key_binding("\C-x\C-t".bytes, :transpose_chars)
@config.add_default_key_binding("\C-x\M-t".bytes, :transpose_words)
@config.add_default_key_binding("\C-x\M-u".bytes, :upcase_word)
@config.add_default_key_binding("\C-x\M-l".bytes, :downcase_word)
@config.add_default_key_binding("\C-x\M-c".bytes, :capitalize_word)
@writer.write("abcde\C-b\C-b\C-b\C-x\C-d\C-x\C-h\C-x\C-v\C-a\C-f\C-f EF\C-x\C-t gh\C-x\M-t\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-b\C-x\M-u\C-x\M-l\C-x\M-c\n")
assert_equal "a\C-aDE gh Fe", Reline.readmultiline(&proc{ true })
end
2019-06-01 18:39:12 -04:00
end