diff options
| author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-12-10 19:28:16 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-12-10 10:28:22 +0000 |
| commit | 3568e7aef7ace192297693deb770c10928ade314 (patch) | |
| tree | a7e1eec37893810066f2ad1a21b7261a0bb65c37 /test | |
| parent | ebb80c26b34525eb5630e17e195313943acc421c (diff) | |
[ruby/reline] Fix line wrapped cursor position
(https://github.com/ruby/reline/pull/791)
Cursor position calculation was wrong when the input line contains "\1" or CSI escape sequence.
https://github.com/ruby/reline/commit/a1943daaf4
Diffstat (limited to 'test')
| -rw-r--r-- | test/reline/test_line_editor.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/reline/test_line_editor.rb b/test/reline/test_line_editor.rb index 85a814a799..28fcbfa6df 100644 --- a/test/reline/test_line_editor.rb +++ b/test/reline/test_line_editor.rb @@ -59,6 +59,35 @@ class Reline::LineEditor end end + class CursorPositionTest < Reline::TestCase + def setup + @line_editor = Reline::LineEditor.new(nil) + @line_editor.instance_variable_set(:@config, Reline::Config.new) + end + + def test_cursor_position_with_escaped_input + @line_editor.instance_variable_set(:@screen_size, [4, 16]) + @line_editor.instance_variable_set(:@prompt, "\e[1mprompt\e[0m> ") + @line_editor.instance_variable_set(:@buffer_of_lines, ["\e[1m\0\1\2\3\4\5\6\7abcd"]) + @line_editor.instance_variable_set(:@line_index, 0) + # prompt> ^[[1m^@^ + # A^B^C^D^E^F^Gabc + # d + @line_editor.instance_variable_set(:@byte_pointer, 0) + assert_equal [8, 0], @line_editor.wrapped_cursor_position + @line_editor.instance_variable_set(:@byte_pointer, 5) + assert_equal [15, 0], @line_editor.wrapped_cursor_position + @line_editor.instance_variable_set(:@byte_pointer, 6) + assert_equal [1, 1], @line_editor.wrapped_cursor_position + @line_editor.instance_variable_set(:@byte_pointer, 14) + assert_equal [15, 1], @line_editor.wrapped_cursor_position + @line_editor.instance_variable_set(:@byte_pointer, 15) + assert_equal [0, 2], @line_editor.wrapped_cursor_position + @line_editor.instance_variable_set(:@byte_pointer, 16) + assert_equal [1, 2], @line_editor.wrapped_cursor_position + end + end + class RenderLineDifferentialTest < Reline::TestCase class TestIO < Reline::IO def write(string) |
