2019-06-01 18:39:12 -04:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class Reline::WithinPipeTest < Reline::TestCase
|
|
|
|
def setup
|
|
|
|
Reline.send(:test_mode)
|
2021-06-21 09:08:13 -04:00
|
|
|
@encoding = Reline::IOGate.encoding
|
|
|
|
@input_reader, @writer = IO.pipe(@encoding)
|
2020-05-11 06:51:29 -04:00
|
|
|
Reline.input = @input_reader
|
2021-06-21 09:08:13 -04:00
|
|
|
@reader, @output_writer = IO.pipe(@encoding)
|
2020-05-11 06:51:29 -04:00
|
|
|
@output = Reline.output = @output_writer
|
2019-07-14 14:08:36 -04:00
|
|
|
@config = Reline.send(:core).config
|
2021-01-14 01:36:45 -05:00
|
|
|
@config.keyseq_timeout *= 600 if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # for --jit-wait CI
|
2019-07-14 14:08:36 -04:00
|
|
|
@line_editor = Reline.send(:core).line_editor
|
2019-06-01 18:39:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Reline.input = STDIN
|
|
|
|
Reline.output = STDOUT
|
2020-03-02 00:42:33 -05:00
|
|
|
Reline.point = 0
|
2020-05-12 08:17:43 -04:00
|
|
|
Reline.delete_text
|
2020-05-11 06:51:29 -04:00
|
|
|
@input_reader.close
|
2019-06-01 18:39:12 -04:00
|
|
|
@writer.close
|
2020-05-11 06:51:29 -04:00
|
|
|
@reader.close
|
|
|
|
@output_writer.close
|
2019-06-01 18:39:12 -04:00
|
|
|
@config.reset
|
2021-05-29 09:46:22 -04:00
|
|
|
@config.reset_default_key_bindings
|
2021-06-21 09:06:33 -04:00
|
|
|
Reline.test_reset
|
2019-06-01 18:39:12 -04:00
|
|
|
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
|
2019-06-02 14:41:40 -04:00
|
|
|
|
|
|
|
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
|
2019-06-03 19:34:10 -04:00
|
|
|
|
2019-06-04 05:33:34 -04:00
|
|
|
def test_macro_commands_for_editing
|
2019-06-03 19:34:10 -04:00
|
|
|
@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
|
2021-03-22 11:56:32 -04:00
|
|
|
|
|
|
|
def test_delete_text_in_multiline
|
|
|
|
@writer.write("abc\ndef\nxyz\n")
|
|
|
|
result = Reline.readmultiline(&proc{ |str|
|
|
|
|
if str.include?('xyz')
|
|
|
|
Reline.delete_text
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
})
|
|
|
|
assert_equal "abc\ndef", result
|
|
|
|
end
|
2019-06-01 18:39:12 -04:00
|
|
|
end
|