mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 14:05:02 +02:00
[ruby/reline] Reline 0.5.0.pre
(https://github.com/ruby/reline/pull/614)
* Re-architecture LineEditor's internal state and rendering
* Fix test related to LineEditor re-architecture
* Bump to 0.5.0.pre.1
* Hide cursor only when updating screen. Frequent hide&show makes cursor flickering.
* Simplify rerender call from reline.rb
* Simplify handle_cleared
It only need to clear screen. line_editor.rerender will be called later.
* Add description of updating pasting_state inserts continuous_insertion_buffer
* Use meaningful block parameter
Co-authored-by: Stan Lo <stan001212@gmail.com>
* Fix use of `@cursor_y`
Fix bug updating `@cursor_y`. Do not use `@cursor_y` while updating dialog because it is not current cursor position but cursor position at last rendered time.
* Remove useless instance_variable_set in test
These instance variables are already removed from LineEditor
* Always initialize instance variables to avoid ruby 2.7 warning, remove unused instance variable
* Call update_dialogs from reline.rb before first render
* Combine state representing rendered screen information into `@rendered_screen`
* Rename editor_cursor_ to wrapped_cursor
It represents cursor position of word wrapped whole content
* Remove unused code, tweak, add comment
---------
3fa376217d
Co-authored-by: Stan Lo <stan001212@gmail.com>
This commit is contained in:
parent
e127289632
commit
d7bc6f0eff
11 changed files with 824 additions and 1424 deletions
|
@ -78,7 +78,6 @@ module Reline
|
|||
@dialog_proc_list = {}
|
||||
yield self
|
||||
@completion_quote_character = nil
|
||||
@bracketed_paste_finished = false
|
||||
end
|
||||
|
||||
def io_gate
|
||||
|
@ -278,8 +277,13 @@ module Reline
|
|||
Reline::HISTORY << whole_buffer
|
||||
end
|
||||
|
||||
line_editor.reset_line if line_editor.whole_buffer.nil?
|
||||
whole_buffer
|
||||
if line_editor.eof?
|
||||
line_editor.reset_line
|
||||
# Return nil if the input is aborted by C-d.
|
||||
nil
|
||||
else
|
||||
whole_buffer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -326,7 +330,7 @@ module Reline
|
|||
line_editor.prompt_proc = prompt_proc
|
||||
line_editor.auto_indent_proc = auto_indent_proc
|
||||
line_editor.dig_perfect_match_proc = dig_perfect_match_proc
|
||||
line_editor.pre_input_hook = pre_input_hook
|
||||
pre_input_hook&.call
|
||||
@dialog_proc_list.each_pair do |name_sym, d|
|
||||
line_editor.add_dialog_proc(name_sym, d.dialog_proc, d.context)
|
||||
end
|
||||
|
@ -337,30 +341,24 @@ module Reline
|
|||
io_gate.set_default_key_bindings(config)
|
||||
end
|
||||
|
||||
line_editor.print_nomultiline_prompt(prompt)
|
||||
line_editor.update_dialogs
|
||||
line_editor.rerender
|
||||
|
||||
begin
|
||||
line_editor.set_signal_handlers
|
||||
prev_pasting_state = false
|
||||
loop do
|
||||
prev_pasting_state = io_gate.in_pasting?
|
||||
read_io(config.keyseq_timeout) { |inputs|
|
||||
line_editor.set_pasting_state(io_gate.in_pasting?)
|
||||
inputs.each { |c|
|
||||
line_editor.input_key(c)
|
||||
line_editor.rerender
|
||||
}
|
||||
if @bracketed_paste_finished
|
||||
line_editor.rerender_all
|
||||
@bracketed_paste_finished = false
|
||||
end
|
||||
inputs.each { |key| line_editor.update(key) }
|
||||
}
|
||||
if prev_pasting_state == true and not io_gate.in_pasting? and not line_editor.finished?
|
||||
line_editor.set_pasting_state(false)
|
||||
prev_pasting_state = false
|
||||
line_editor.rerender_all
|
||||
if line_editor.finished?
|
||||
line_editor.render_finished
|
||||
break
|
||||
else
|
||||
line_editor.set_pasting_state(io_gate.in_pasting?)
|
||||
line_editor.rerender
|
||||
end
|
||||
break if line_editor.finished?
|
||||
end
|
||||
io_gate.move_cursor_column(0)
|
||||
rescue Errno::EIO
|
||||
|
@ -395,7 +393,6 @@ module Reline
|
|||
c = io_gate.getc(Float::INFINITY)
|
||||
if c == -1
|
||||
result = :unmatched
|
||||
@bracketed_paste_finished = true
|
||||
else
|
||||
buffer << c
|
||||
result = key_stroke.match_status(buffer)
|
||||
|
|
|
@ -57,7 +57,7 @@ class Reline::GeneralIO
|
|||
end
|
||||
|
||||
def self.get_screen_size
|
||||
[1, 1]
|
||||
[24, 80]
|
||||
end
|
||||
|
||||
def self.cursor_pos
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,3 +1,3 @@
|
|||
module Reline
|
||||
VERSION = '0.4.3'
|
||||
VERSION = '0.5.0.pre.1'
|
||||
end
|
||||
|
|
|
@ -29,12 +29,19 @@ module Reline
|
|||
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]
|
||||
end
|
||||
Reline::GeneralIO.reset(encoding: encoding) unless ansi
|
||||
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
|
||||
|
@ -147,11 +154,22 @@ class Reline::TestCase < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def assert_cursor(expected)
|
||||
assert_equal(expected, @line_editor.instance_variable_get(:@cursor))
|
||||
# This test satisfies nothing because there is no `@cursor` anymore
|
||||
# Test editor_cursor_position instead
|
||||
cursor_x = @line_editor.instance_eval do
|
||||
line_before_cursor = whole_lines[@line_index].byteslice(0, @byte_pointer)
|
||||
Reline::Unicode.calculate_width(line_before_cursor)
|
||||
end
|
||||
assert_equal(expected, cursor_x)
|
||||
end
|
||||
|
||||
def assert_cursor_max(expected)
|
||||
assert_equal(expected, @line_editor.instance_variable_get(:@cursor_max))
|
||||
# This test satisfies nothing because there is no `@cursor_max` anymore
|
||||
cursor_max = @line_editor.instance_eval do
|
||||
line = whole_lines[@line_index]
|
||||
Reline::Unicode.calculate_width(line)
|
||||
end
|
||||
assert_equal(expected, cursor_max)
|
||||
end
|
||||
|
||||
def assert_line_index(expected)
|
||||
|
|
|
@ -1737,19 +1737,19 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-r123")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('1234')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-ha")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-h3")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('1235')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_to_front
|
||||
|
@ -1764,19 +1764,19 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-s123")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('1235')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-ha")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-h3")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('1234')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_front_and_back
|
||||
|
@ -1791,24 +1791,24 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-s12")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('1235')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-s")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-r")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-r")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('1235')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_back_and_front
|
||||
|
@ -1823,24 +1823,24 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-r12")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('1234')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-r")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-s")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-s")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('1234')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_to_back_in_the_middle_of_histories
|
||||
|
@ -1877,14 +1877,14 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-r123")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('1234')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-r")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('1235')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_by_last_determined
|
||||
|
@ -1899,9 +1899,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-r123")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('1234')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys("\C-j")
|
||||
assert_line('1234')
|
||||
assert_byte_pointer_size('')
|
||||
|
@ -1919,9 +1919,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-r")
|
||||
assert_line('1235')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_byte_pointer_size('1235')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
end
|
||||
|
||||
def test_search_history_with_isearch_terminator
|
||||
|
@ -1939,9 +1939,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor_max(0)
|
||||
input_keys("\C-r12a")
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0) # doesn't determine yet
|
||||
assert_byte_pointer_size('12aa')
|
||||
assert_cursor(4)
|
||||
assert_cursor_max(4)
|
||||
input_keys('Y')
|
||||
assert_line('12aa')
|
||||
assert_byte_pointer_size('')
|
||||
|
@ -2013,7 +2013,7 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
$VERBOSE = verbose
|
||||
@line_editor.output_modifier_proc = proc { |output| Reline::Unicode.escape_for_print(output) }
|
||||
input_keys("abcdef\n")
|
||||
result = @line_editor.__send__(:modify_lines, @line_editor.whole_lines)
|
||||
result = @line_editor.__send__(:modify_lines, @line_editor.whole_lines, @line_editor.finished?)
|
||||
$/ = nil
|
||||
assert_equal(['abcdef'], result)
|
||||
ensure
|
||||
|
|
|
@ -1,13 +1,124 @@
|
|||
require_relative 'helper'
|
||||
require 'reline/line_editor'
|
||||
require 'stringio'
|
||||
|
||||
class Reline::LineEditor::Test < Reline::TestCase
|
||||
def test_range_subtract
|
||||
dummy_config = nil
|
||||
editor = Reline::LineEditor.new(dummy_config, 'ascii-8bit')
|
||||
base_ranges = [3...5, 4...10, 6...8, 12...15, 15...20]
|
||||
subtract_ranges = [5...7, 8...9, 11...13, 17...18, 18...19]
|
||||
expected_result = [3...5, 7...8, 9...10, 13...17, 19...20]
|
||||
assert_equal expected_result, editor.send(:range_subtract, base_ranges, subtract_ranges)
|
||||
class Reline::LineEditor
|
||||
class RenderLineDifferentialTest < Reline::TestCase
|
||||
def setup
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
@line_editor = Reline::LineEditor.new(nil, Encoding::UTF_8)
|
||||
@original_iogate = Reline::IOGate
|
||||
@output = StringIO.new
|
||||
@line_editor.instance_variable_set(:@screen_size, [24, 80])
|
||||
@line_editor.instance_variable_set(:@output, @output)
|
||||
Reline.send(:remove_const, :IOGate)
|
||||
Reline.const_set(:IOGate, Object.new)
|
||||
Reline::IOGate.instance_variable_set(:@output, @output)
|
||||
def (Reline::IOGate).move_cursor_column(col)
|
||||
@output << "[COL_#{col}]"
|
||||
end
|
||||
def (Reline::IOGate).erase_after_cursor
|
||||
@output << '[ERASE]'
|
||||
end
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
|
||||
def assert_output(expected)
|
||||
@output.reopen(+'')
|
||||
yield
|
||||
actual = @output.string
|
||||
assert_equal(expected, actual.gsub("\e[0m", ''))
|
||||
end
|
||||
|
||||
def teardown
|
||||
Reline.send(:remove_const, :IOGate)
|
||||
Reline.const_set(:IOGate, @original_iogate)
|
||||
end
|
||||
|
||||
def test_line_increase_decrease
|
||||
assert_output '[COL_0]bb' do
|
||||
@line_editor.render_line_differential([[0, 1, 'a']], [[0, 2, 'bb']])
|
||||
end
|
||||
|
||||
assert_output '[COL_0]b[COL_1][ERASE]' do
|
||||
@line_editor.render_line_differential([[0, 2, 'aa']], [[0, 1, 'b']])
|
||||
end
|
||||
end
|
||||
|
||||
def test_dialog_appear_disappear
|
||||
assert_output '[COL_3]dialog' do
|
||||
@line_editor.render_line_differential([[0, 1, 'a']], [[0, 1, 'a'], [3, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_3]dialog' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10]], [[0, 10, 'a' * 10], [3, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_1][ERASE]' do
|
||||
@line_editor.render_line_differential([[0, 1, 'a'], [3, 6, 'dialog']], [[0, 1, 'a']])
|
||||
end
|
||||
|
||||
assert_output '[COL_3]aaaaaa' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'a' * 10]])
|
||||
end
|
||||
end
|
||||
|
||||
def test_dialog_change
|
||||
assert_output '[COL_3]DIALOG' do
|
||||
@line_editor.render_line_differential([[0, 2, 'a'], [3, 6, 'dialog']], [[0, 2, 'a'], [3, 6, 'DIALOG']])
|
||||
end
|
||||
|
||||
assert_output '[COL_3]DIALOG' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'a' * 10], [3, 6, 'DIALOG']])
|
||||
end
|
||||
end
|
||||
|
||||
def test_update_under_dialog
|
||||
assert_output '[COL_0]b[COL_1] ' do
|
||||
@line_editor.render_line_differential([[0, 2, 'aa'], [4, 6, 'dialog']], [[0, 1, 'b'], [4, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_0]bbb[COL_9]b' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'b' * 10], [3, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_0]b[COL_1] [COL_9][ERASE]' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 1, 'b'], [3, 6, 'dialog']])
|
||||
end
|
||||
end
|
||||
|
||||
def test_dialog_move
|
||||
assert_output '[COL_3]dialog[COL_9][ERASE]' do
|
||||
@line_editor.render_line_differential([[0, 1, 'a'], [4, 6, 'dialog']], [[0, 1, 'a'], [3, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_4] [COL_5]dialog' do
|
||||
@line_editor.render_line_differential([[0, 1, 'a'], [4, 6, 'dialog']], [[0, 1, 'a'], [5, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_2]dialog[COL_8]a' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'a' * 10], [2, 6, 'dialog']])
|
||||
end
|
||||
|
||||
assert_output '[COL_2]a[COL_3]dialog' do
|
||||
@line_editor.render_line_differential([[0, 10, 'a' * 10], [2, 6, 'dialog']], [[0, 10, 'a' * 10], [3, 6, 'dialog']])
|
||||
end
|
||||
end
|
||||
|
||||
def test_complicated
|
||||
state_a = [nil, [19, 7, 'bbbbbbb'], [15, 8, 'cccccccc'], [10, 5, 'ddddd'], [18, 4, 'eeee'], [1, 3, 'fff'], [17, 2, 'gg'], [7, 1, 'h']]
|
||||
state_b = [[5, 9, 'aaaaaaaaa'], nil, [15, 8, 'cccccccc'], nil, [18, 4, 'EEEE'], [25, 4, 'ffff'], [17, 2, 'gg'], [2, 2, 'hh']]
|
||||
# state_a: " fff h dddddccggeeecbbb"
|
||||
# state_b: " hh aaaaaaaaa ccggEEEc ffff"
|
||||
|
||||
assert_output '[COL_1] [COL_2]hh[COL_5]aaaaaaaaa[COL_14] [COL_19]EEE[COL_23] [COL_25]ffff' do
|
||||
@line_editor.render_line_differential(state_a, state_b)
|
||||
end
|
||||
|
||||
assert_output '[COL_1]fff[COL_5] [COL_7]h[COL_8] [COL_10]ddddd[COL_19]eee[COL_23]bbb[COL_26][ERASE]' do
|
||||
@line_editor.render_line_differential(state_b, state_a)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,6 @@ class Reline::MacroTest < Reline::TestCase
|
|||
@config = Reline::Config.new
|
||||
@encoding = Reline.core.encoding
|
||||
@line_editor = Reline::LineEditor.new(@config, @encoding)
|
||||
@line_editor.instance_variable_set(:@screen_size, [24, 80])
|
||||
@output = @line_editor.output = File.open(IO::NULL, "w")
|
||||
end
|
||||
|
||||
|
|
|
@ -30,10 +30,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
|
|||
|
||||
@line_editor.instance_variable_set(:@is_multiline, true)
|
||||
@line_editor.instance_variable_set(:@buffer_of_lines, buf)
|
||||
@line_editor.instance_variable_set(:@line, buf[1])
|
||||
@line_editor.instance_variable_set(:@byte_pointer, 3)
|
||||
@line_editor.instance_variable_set(:@cursor, 3)
|
||||
@line_editor.instance_variable_set(:@cursor_max, 11)
|
||||
@line_editor.instance_variable_set(:@line_index, 1)
|
||||
@line_editor.instance_variable_set(:@completion_proc, proc { |target|
|
||||
assert_equal('p', target)
|
||||
|
@ -42,10 +39,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
|
|||
|
||||
@line_editor.instance_variable_set(:@is_multiline, true)
|
||||
@line_editor.instance_variable_set(:@buffer_of_lines, buf)
|
||||
@line_editor.instance_variable_set(:@line, buf[1])
|
||||
@line_editor.instance_variable_set(:@byte_pointer, 6)
|
||||
@line_editor.instance_variable_set(:@cursor, 6)
|
||||
@line_editor.instance_variable_set(:@cursor_max, 11)
|
||||
@line_editor.instance_variable_set(:@line_index, 1)
|
||||
@line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
|
||||
assert_equal('puts', target)
|
||||
|
@ -54,10 +48,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
|
|||
})
|
||||
@line_editor.__send__(:call_completion_proc)
|
||||
|
||||
@line_editor.instance_variable_set(:@line, buf[0])
|
||||
@line_editor.instance_variable_set(:@byte_pointer, 6)
|
||||
@line_editor.instance_variable_set(:@cursor, 6)
|
||||
@line_editor.instance_variable_set(:@cursor_max, 8)
|
||||
@line_editor.instance_variable_set(:@line_index, 0)
|
||||
@line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
|
||||
assert_equal('ho', target)
|
||||
|
@ -66,10 +57,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
|
|||
})
|
||||
@line_editor.__send__(:call_completion_proc)
|
||||
|
||||
@line_editor.instance_variable_set(:@line, buf[2])
|
||||
@line_editor.instance_variable_set(:@byte_pointer, 1)
|
||||
@line_editor.instance_variable_set(:@cursor, 1)
|
||||
@line_editor.instance_variable_set(:@cursor_max, 3)
|
||||
@line_editor.instance_variable_set(:@line_index, 2)
|
||||
@line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
|
||||
assert_equal('e', target)
|
||||
|
|
|
@ -9,10 +9,6 @@ require 'optparse'
|
|||
require_relative 'termination_checker'
|
||||
|
||||
opt = OptionParser.new
|
||||
opt.on('--prompt-list-cache-timeout VAL') { |v|
|
||||
Reline::LineEditor.__send__(:remove_const, :PROMPT_LIST_CACHE_TIMEOUT)
|
||||
Reline::LineEditor::PROMPT_LIST_CACHE_TIMEOUT = v.to_f
|
||||
}
|
||||
opt.on('--dynamic-prompt') {
|
||||
Reline.prompt_proc = proc { |lines|
|
||||
lines.each_with_index.map { |l, i|
|
||||
|
|
|
@ -464,6 +464,9 @@ begin
|
|||
write("def a\n 8\nend\ndef b\n 3\nend\C-s8")
|
||||
close
|
||||
assert_screen(<<~EOC)
|
||||
prompt> 8
|
||||
prompt> end
|
||||
=> :a
|
||||
(i-search)`8'def a
|
||||
(i-search)`8' 8
|
||||
(i-search)`8'end
|
||||
|
@ -475,6 +478,9 @@ begin
|
|||
write("def a\n 8\nend\ndef b\n 3\nend\C-r8\C-j")
|
||||
close
|
||||
assert_screen(<<~EOC)
|
||||
prompt> 8
|
||||
prompt> end
|
||||
=> :a
|
||||
prompt> def a
|
||||
prompt> 8
|
||||
prompt> end
|
||||
|
@ -495,18 +501,6 @@ begin
|
|||
EOC
|
||||
end
|
||||
|
||||
def test_prompt_list_caching
|
||||
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --prompt-list-cache-timeout 10 --dynamic-prompt}, startup_message: 'Multiline REPL.')
|
||||
write("def hoge\n 3\nend")
|
||||
close
|
||||
assert_screen(<<~EOC)
|
||||
Multiline REPL.
|
||||
[0000]> def hoge
|
||||
[0001]> 3
|
||||
[0002]> end
|
||||
EOC
|
||||
end
|
||||
|
||||
def test_broken_prompt_list
|
||||
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --broken-dynamic-prompt}, startup_message: 'Multiline REPL.')
|
||||
write("def hoge\n 3\nend")
|
||||
|
@ -1026,8 +1020,8 @@ begin
|
|||
iterate_over_face_configs do |config_name, config_file|
|
||||
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib -r#{config_file.path} #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
|
||||
write("\n" * 10)
|
||||
write("if 1\n sSt\nend")
|
||||
write("\C-p\C-h\C-e")
|
||||
write("if 1\n sSts\nend")
|
||||
write("\C-p\C-h\C-e\C-h")
|
||||
close
|
||||
assert_screen(<<~'EOC')
|
||||
prompt>
|
||||
|
@ -1054,8 +1048,8 @@ begin
|
|||
prompt> 2
|
||||
prompt> 3#
|
||||
prompt> 4
|
||||
prompt> 5
|
||||
prompt> 6 Ruby is...
|
||||
prompt> 5 Ruby is...
|
||||
prompt> 6 A dynamic, open source programming
|
||||
EOC
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue