Skip to content

Commit e477380

Browse files
authored
Refactor key actor test (#645)
* Add assertion assert_cursor_line to test helper * Autofix key_actor test to use assert_cursor_line * Rename the assertion to assert_line_around_cursor and remove other assertions for line and cursor
1 parent 3719702 commit e477380

File tree

3 files changed

+649
-2311
lines changed

3 files changed

+649
-2311
lines changed

test/reline/helper.rb

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,14 @@ def input_raw_keys(input, convert = true)
136136
end
137137
end
138138

139-
def assert_line(expected)
140-
expected = convert_str(expected)
141-
assert_equal(expected, @line_editor.line)
139+
def assert_line_around_cursor(before, after)
140+
before = convert_str(before)
141+
after = convert_str(after)
142+
line = @line_editor.line
143+
byte_pointer = @line_editor.instance_variable_get(:@byte_pointer)
144+
actual_before = line.byteslice(0, byte_pointer)
145+
actual_after = line.byteslice(byte_pointer..)
146+
assert_equal([before, after], [actual_before, actual_after])
142147
end
143148

144149
def assert_byte_pointer_size(expected)
@@ -153,25 +158,6 @@ def assert_byte_pointer_size(expected)
153158
EOM
154159
end
155160

156-
def assert_cursor(expected)
157-
# This test satisfies nothing because there is no `@cursor` anymore
158-
# Test editor_cursor_position instead
159-
cursor_x = @line_editor.instance_eval do
160-
line_before_cursor = whole_lines[@line_index].byteslice(0, @byte_pointer)
161-
Reline::Unicode.calculate_width(line_before_cursor)
162-
end
163-
assert_equal(expected, cursor_x)
164-
end
165-
166-
def assert_cursor_max(expected)
167-
# This test satisfies nothing because there is no `@cursor_max` anymore
168-
cursor_max = @line_editor.instance_eval do
169-
line = whole_lines[@line_index]
170-
Reline::Unicode.calculate_width(line)
171-
end
172-
assert_equal(expected, cursor_max)
173-
end
174-
175161
def assert_line_index(expected)
176162
assert_equal(expected, @line_editor.instance_variable_get(:@line_index))
177163
end

0 commit comments

Comments
 (0)