@@ -59,6 +59,35 @@ def test_retrieve_completion_quote
5959 end
6060 end
6161
62+ class CursorPositionTest < Reline ::TestCase
63+ def setup
64+ @line_editor = Reline ::LineEditor . new ( nil )
65+ @line_editor . instance_variable_set ( :@config , Reline ::Config . new )
66+ end
67+
68+ def test_cursor_position_with_escaped_input
69+ @line_editor . instance_variable_set ( :@screen_size , [ 4 , 16 ] )
70+ @line_editor . instance_variable_set ( :@prompt , "\e [1mprompt\e [0m> " )
71+ @line_editor . instance_variable_set ( :@buffer_of_lines , [ "\e [1m\0 \1 \2 \3 \4 \5 \6 \7 abcd" ] )
72+ @line_editor . instance_variable_set ( :@line_index , 0 )
73+ # prompt> ^[[1m^@^
74+ # A^B^C^D^E^F^Gabc
75+ # d
76+ @line_editor . instance_variable_set ( :@byte_pointer , 0 )
77+ assert_equal [ 8 , 0 ] , @line_editor . wrapped_cursor_position
78+ @line_editor . instance_variable_set ( :@byte_pointer , 5 )
79+ assert_equal [ 15 , 0 ] , @line_editor . wrapped_cursor_position
80+ @line_editor . instance_variable_set ( :@byte_pointer , 6 )
81+ assert_equal [ 1 , 1 ] , @line_editor . wrapped_cursor_position
82+ @line_editor . instance_variable_set ( :@byte_pointer , 14 )
83+ assert_equal [ 15 , 1 ] , @line_editor . wrapped_cursor_position
84+ @line_editor . instance_variable_set ( :@byte_pointer , 15 )
85+ assert_equal [ 0 , 2 ] , @line_editor . wrapped_cursor_position
86+ @line_editor . instance_variable_set ( :@byte_pointer , 16 )
87+ assert_equal [ 1 , 2 ] , @line_editor . wrapped_cursor_position
88+ end
89+ end
90+
6291 class RenderLineDifferentialTest < Reline ::TestCase
6392 class TestIO < Reline ::IO
6493 def write ( string )
0 commit comments