summaryrefslogtreecommitdiff
path: root/test/reline/helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/reline/helper.rb')
-rw-r--r--test/reline/helper.rb33
1 files changed, 20 insertions, 13 deletions
diff --git a/test/reline/helper.rb b/test/reline/helper.rb
index f2f3421ded..9a346a17a1 100644
--- a/test/reline/helper.rb
+++ b/test/reline/helper.rb
@@ -22,29 +22,36 @@ module Reline
class <<self
def test_mode(ansi: false)
@original_iogate = IOGate
- remove_const('IOGate')
- const_set('IOGate', ansi ? Reline::ANSI : Reline::GeneralIO)
+
if ENV['RELINE_TEST_ENCODING']
encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
else
encoding = Encoding::UTF_8
end
- @original_get_screen_size = IOGate.method(:get_screen_size)
- IOGate.singleton_class.remove_method(:get_screen_size)
- def IOGate.get_screen_size
- [24, 80]
+
+ if ansi
+ new_io_gate = ANSI.new
+ # Setting ANSI gate's screen size through set_screen_size will also change the tester's stdin's screen size
+ # Let's avoid that side-effect by stubbing the get_screen_size method
+ new_io_gate.define_singleton_method(:get_screen_size) do
+ [24, 80]
+ end
+ new_io_gate.define_singleton_method(:encoding) do
+ encoding
+ end
+ else
+ new_io_gate = Dumb.new(encoding: encoding)
end
- Reline::GeneralIO.reset(encoding: encoding) unless ansi
+
+ remove_const('IOGate')
+ const_set('IOGate', new_io_gate)
core.config.instance_variable_set(:@test_mode, true)
core.config.reset
end
def test_reset
- IOGate.singleton_class.remove_method(:get_screen_size)
- IOGate.define_singleton_method(:get_screen_size, @original_get_screen_size)
remove_const('IOGate')
const_set('IOGate', @original_iogate)
- Reline::GeneralIO.reset
Reline.instance_variable_set(:@core, nil)
end
@@ -131,7 +138,7 @@ class Reline::TestCase < Test::Unit::TestCase
def assert_line_around_cursor(before, after)
before = convert_str(before)
after = convert_str(after)
- line = @line_editor.line
+ line = @line_editor.current_line
byte_pointer = @line_editor.instance_variable_get(:@byte_pointer)
actual_before = line.byteslice(0, byte_pointer)
actual_after = line.byteslice(byte_pointer..)
@@ -146,7 +153,7 @@ class Reline::TestCase < Test::Unit::TestCase
expected.bytesize, byte_pointer,
<<~EOM)
<#{expected.inspect} (#{expected.encoding.inspect})> expected but was
- <#{chunk.inspect} (#{chunk.encoding.inspect})> in <Terminal #{Reline::GeneralIO.encoding.inspect}>
+ <#{chunk.inspect} (#{chunk.encoding.inspect})> in <Terminal #{Reline::Dumb.new.encoding.inspect}>
EOM
end
@@ -161,7 +168,7 @@ class Reline::TestCase < Test::Unit::TestCase
def assert_key_binding(input, method_symbol, editing_modes = [:emacs, :vi_insert, :vi_command])
editing_modes.each do |editing_mode|
@config.editing_mode = editing_mode
- assert_equal(method_symbol, @config.editing_mode.default_key_bindings[input.bytes])
+ assert_equal(method_symbol, @config.editing_mode.get(input.bytes))
end
end
end