1 -- major tests for text editing flows
3 function test_initial_state()
4 io
.write('\ntest_initial_state')
5 App
.screen
.init
{width
=120, height
=60}
6 Editor_state
= edit
.initialize_test_state()
7 Editor_state
.lines
= load_array
{}
8 Text
.redraw_all(Editor_state
)
9 edit
.draw(Editor_state
)
10 check_eq(#Editor_state
.lines
, 1, 'F - test_initial_state/#lines')
11 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_initial_state/cursor:line')
12 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_initial_state/cursor:pos')
13 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_initial_state/screen_top:line')
14 check_eq(Editor_state
.screen_top1
.pos
, 1, 'F - test_initial_state/screen_top:pos')
17 function test_click_to_create_drawing()
18 io
.write('\ntest_click_to_create_drawing')
19 App
.screen
.init
{width
=120, height
=60}
20 Editor_state
= edit
.initialize_test_state()
21 Editor_state
.lines
= load_array
{}
22 Text
.redraw_all(Editor_state
)
23 edit
.draw(Editor_state
)
24 edit
.run_after_mouse_click(Editor_state
, 8,Editor_state
.top
+8, 1)
25 -- cursor skips drawing to always remain on text
26 check_eq(#Editor_state
.lines
, 2, 'F - test_click_to_create_drawing/#lines')
27 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_click_to_create_drawing/cursor')
30 function test_backspace_to_delete_drawing()
31 io
.write('\ntest_backspace_to_delete_drawing')
32 -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
33 App
.screen
.init
{width
=120, height
=60}
34 Editor_state
= edit
.initialize_test_state()
35 Editor_state
.lines
= load_array
{'```lines', '```', ''}
36 Text
.redraw_all(Editor_state
)
37 -- cursor is on text as always (outside tests this will get initialized correctly)
38 Editor_state
.cursor1
.line
= 2
39 -- backspacing deletes the drawing
40 edit
.run_after_keychord(Editor_state
, 'backspace')
41 check_eq(#Editor_state
.lines
, 1, 'F - test_backspace_to_delete_drawing/#lines')
42 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_backspace_to_delete_drawing/cursor')
45 function test_backspace_from_start_of_final_line()
46 io
.write('\ntest_backspace_from_start_of_final_line')
47 -- display final line of text with cursor at start of it
48 App
.screen
.init
{width
=120, height
=60}
49 Editor_state
= edit
.initialize_test_state()
50 Editor_state
.lines
= load_array
{'abc', 'def'}
51 Editor_state
.screen_top1
= {line
=2, pos
=1}
52 Editor_state
.cursor1
= {line
=2, pos
=1}
53 Text
.redraw_all(Editor_state
)
54 -- backspace scrolls up
55 edit
.run_after_keychord(Editor_state
, 'backspace')
56 check_eq(#Editor_state
.lines
, 1, 'F - test_backspace_from_start_of_final_line/#lines')
57 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_backspace_from_start_of_final_line/cursor')
58 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_backspace_from_start_of_final_line/screen_top')
61 function test_insert_first_character()
62 io
.write('\ntest_insert_first_character')
63 App
.screen
.init
{width
=120, height
=60}
64 Editor_state
= edit
.initialize_test_state()
65 Editor_state
.lines
= load_array
{}
66 Text
.redraw_all(Editor_state
)
67 edit
.draw(Editor_state
)
68 edit
.run_after_textinput(Editor_state
, 'a')
69 local y
= Editor_state
.top
70 App
.screen
.check(y
, 'a', 'F - test_insert_first_character/screen:1')
73 function test_press_ctrl()
74 io
.write('\ntest_press_ctrl')
75 -- press ctrl while the cursor is on text
76 App
.screen
.init
{width
=50, height
=80}
77 Editor_state
= edit
.initialize_test_state()
78 Editor_state
.lines
= load_array
{''}
79 Text
.redraw_all(Editor_state
)
80 Editor_state
.cursor1
= {line
=1, pos
=1}
81 Editor_state
.screen_top1
= {line
=1, pos
=1}
82 Editor_state
.screen_bottom1
= {}
83 edit
.run_after_keychord(Editor_state
, 'C-m')
86 function test_move_left()
87 io
.write('\ntest_move_left')
88 App
.screen
.init
{width
=120, height
=60}
89 Editor_state
= edit
.initialize_test_state()
90 Editor_state
.lines
= load_array
{'a'}
91 Text
.redraw_all(Editor_state
)
92 Editor_state
.cursor1
= {line
=1, pos
=2}
93 edit
.draw(Editor_state
)
94 edit
.run_after_keychord(Editor_state
, 'left')
95 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_move_left')
98 function test_move_right()
99 io
.write('\ntest_move_right')
100 App
.screen
.init
{width
=120, height
=60}
101 Editor_state
= edit
.initialize_test_state()
102 Editor_state
.lines
= load_array
{'a'}
103 Text
.redraw_all(Editor_state
)
104 Editor_state
.cursor1
= {line
=1, pos
=1}
105 edit
.draw(Editor_state
)
106 edit
.run_after_keychord(Editor_state
, 'right')
107 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_move_right')
110 function test_move_left_to_previous_line()
111 io
.write('\ntest_move_left_to_previous_line')
112 App
.screen
.init
{width
=120, height
=60}
113 Editor_state
= edit
.initialize_test_state()
114 Editor_state
.lines
= load_array
{'abc', 'def'}
115 Text
.redraw_all(Editor_state
)
116 Editor_state
.cursor1
= {line
=2, pos
=1}
117 edit
.draw(Editor_state
)
118 edit
.run_after_keychord(Editor_state
, 'left')
119 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_move_left_to_previous_line/line')
120 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_move_left_to_previous_line/pos') -- past end of line
123 function test_move_right_to_next_line()
124 io
.write('\ntest_move_right_to_next_line')
125 App
.screen
.init
{width
=120, height
=60}
126 Editor_state
= edit
.initialize_test_state()
127 Editor_state
.lines
= load_array
{'abc', 'def'}
128 Text
.redraw_all(Editor_state
)
129 Editor_state
.cursor1
= {line
=1, pos
=4} -- past end of line
130 edit
.draw(Editor_state
)
131 edit
.run_after_keychord(Editor_state
, 'right')
132 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_move_right_to_next_line/line')
133 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_move_right_to_next_line/pos')
136 function test_move_to_start_of_word()
137 io
.write('\ntest_move_to_start_of_word')
138 App
.screen
.init
{width
=120, height
=60}
139 Editor_state
= edit
.initialize_test_state()
140 Editor_state
.lines
= load_array
{'abc'}
141 Text
.redraw_all(Editor_state
)
142 Editor_state
.cursor1
= {line
=1, pos
=3}
143 edit
.draw(Editor_state
)
144 edit
.run_after_keychord(Editor_state
, 'M-left')
145 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_move_to_start_of_word')
148 function test_move_to_start_of_previous_word()
149 io
.write('\ntest_move_to_start_of_previous_word')
150 App
.screen
.init
{width
=120, height
=60}
151 Editor_state
= edit
.initialize_test_state()
152 Editor_state
.lines
= load_array
{'abc def'}
153 Text
.redraw_all(Editor_state
)
154 Editor_state
.cursor1
= {line
=1, pos
=4} -- at the space between words
155 edit
.draw(Editor_state
)
156 edit
.run_after_keychord(Editor_state
, 'M-left')
157 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_move_to_start_of_previous_word')
160 function test_skip_to_previous_word()
161 io
.write('\ntest_skip_to_previous_word')
162 App
.screen
.init
{width
=120, height
=60}
163 Editor_state
= edit
.initialize_test_state()
164 Editor_state
.lines
= load_array
{'abc def'}
165 Text
.redraw_all(Editor_state
)
166 Editor_state
.cursor1
= {line
=1, pos
=5} -- at the start of second word
167 edit
.draw(Editor_state
)
168 edit
.run_after_keychord(Editor_state
, 'M-left')
169 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_skip_to_previous_word')
172 function test_skip_past_tab_to_previous_word()
173 io
.write('\ntest_skip_past_tab_to_previous_word')
174 App
.screen
.init
{width
=120, height
=60}
175 Editor_state
= edit
.initialize_test_state()
176 Editor_state
.lines
= load_array
{'abc def\tghi'}
177 Text
.redraw_all(Editor_state
)
178 Editor_state
.cursor1
= {line
=1, pos
=10} -- within third word
179 edit
.draw(Editor_state
)
180 edit
.run_after_keychord(Editor_state
, 'M-left')
181 check_eq(Editor_state
.cursor1
.pos
, 9, 'F - test_skip_past_tab_to_previous_word')
184 function test_skip_multiple_spaces_to_previous_word()
185 io
.write('\ntest_skip_multiple_spaces_to_previous_word')
186 App
.screen
.init
{width
=120, height
=60}
187 Editor_state
= edit
.initialize_test_state()
188 Editor_state
.lines
= load_array
{'abc def'}
189 Text
.redraw_all(Editor_state
)
190 Editor_state
.cursor1
= {line
=1, pos
=6} -- at the start of second word
191 edit
.draw(Editor_state
)
192 edit
.run_after_keychord(Editor_state
, 'M-left')
193 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_skip_multiple_spaces_to_previous_word')
196 function test_move_to_start_of_word_on_previous_line()
197 io
.write('\ntest_move_to_start_of_word_on_previous_line')
198 App
.screen
.init
{width
=120, height
=60}
199 Editor_state
= edit
.initialize_test_state()
200 Editor_state
.lines
= load_array
{'abc def', 'ghi'}
201 Text
.redraw_all(Editor_state
)
202 Editor_state
.cursor1
= {line
=2, pos
=1}
203 edit
.draw(Editor_state
)
204 edit
.run_after_keychord(Editor_state
, 'M-left')
205 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_move_to_start_of_word_on_previous_line/line')
206 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_move_to_start_of_word_on_previous_line/pos')
209 function test_move_past_end_of_word()
210 io
.write('\ntest_move_past_end_of_word')
211 App
.screen
.init
{width
=120, height
=60}
212 Editor_state
= edit
.initialize_test_state()
213 Editor_state
.lines
= load_array
{'abc def'}
214 Text
.redraw_all(Editor_state
)
215 Editor_state
.cursor1
= {line
=1, pos
=1}
216 edit
.draw(Editor_state
)
217 edit
.run_after_keychord(Editor_state
, 'M-right')
218 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_move_past_end_of_word')
221 function test_skip_to_next_word()
222 io
.write('\ntest_skip_to_next_word')
223 App
.screen
.init
{width
=120, height
=60}
224 Editor_state
= edit
.initialize_test_state()
225 Editor_state
.lines
= load_array
{'abc def'}
226 Text
.redraw_all(Editor_state
)
227 Editor_state
.cursor1
= {line
=1, pos
=4} -- at the space between words
228 edit
.draw(Editor_state
)
229 edit
.run_after_keychord(Editor_state
, 'M-right')
230 check_eq(Editor_state
.cursor1
.pos
, 8, 'F - test_skip_to_next_word')
233 function test_skip_past_tab_to_next_word()
234 io
.write('\ntest_skip_past_tab_to_next_word')
235 App
.screen
.init
{width
=120, height
=60}
236 Editor_state
= edit
.initialize_test_state()
237 Editor_state
.lines
= load_array
{'abc\tdef'}
238 Text
.redraw_all(Editor_state
)
239 Editor_state
.cursor1
= {line
=1, pos
=1} -- at the space between words
240 edit
.draw(Editor_state
)
241 edit
.run_after_keychord(Editor_state
, 'M-right')
242 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_skip_past_tab_to_next_word')
245 function test_skip_multiple_spaces_to_next_word()
246 io
.write('\ntest_skip_multiple_spaces_to_next_word')
247 App
.screen
.init
{width
=120, height
=60}
248 Editor_state
= edit
.initialize_test_state()
249 Editor_state
.lines
= load_array
{'abc def'}
250 Text
.redraw_all(Editor_state
)
251 Editor_state
.cursor1
= {line
=1, pos
=4} -- at the start of second word
252 edit
.draw(Editor_state
)
253 edit
.run_after_keychord(Editor_state
, 'M-right')
254 check_eq(Editor_state
.cursor1
.pos
, 9, 'F - test_skip_multiple_spaces_to_next_word')
257 function test_move_past_end_of_word_on_next_line()
258 io
.write('\ntest_move_past_end_of_word_on_next_line')
259 App
.screen
.init
{width
=120, height
=60}
260 Editor_state
= edit
.initialize_test_state()
261 Editor_state
.lines
= load_array
{'abc def', 'ghi'}
262 Text
.redraw_all(Editor_state
)
263 Editor_state
.cursor1
= {line
=1, pos
=8}
264 edit
.draw(Editor_state
)
265 edit
.run_after_keychord(Editor_state
, 'M-right')
266 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_move_past_end_of_word_on_next_line/line')
267 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_move_past_end_of_word_on_next_line/pos')
270 function test_click_with_mouse()
271 io
.write('\ntest_click_with_mouse')
272 -- display two lines with cursor on one of them
273 App
.screen
.init
{width
=50, height
=80}
274 Editor_state
= edit
.initialize_test_state()
275 Editor_state
.lines
= load_array
{'abc', 'def'}
276 Text
.redraw_all(Editor_state
)
277 Editor_state
.cursor1
= {line
=2, pos
=1}
278 Editor_state
.screen_top1
= {line
=1, pos
=1}
279 Editor_state
.screen_bottom1
= {}
280 -- click on the other line
281 edit
.draw(Editor_state
)
282 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
284 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_with_mouse/cursor:line')
285 check_nil(Editor_state
.selection1
.line
, 'F - test_click_with_mouse/selection is empty to avoid perturbing future edits')
288 function test_click_with_mouse_to_left_of_line()
289 io
.write('\ntest_click_with_mouse_to_left_of_line')
290 -- display a line with the cursor in the middle
291 App
.screen
.init
{width
=50, height
=80}
292 Editor_state
= edit
.initialize_test_state()
293 Editor_state
.lines
= load_array
{'abc'}
294 Text
.redraw_all(Editor_state
)
295 Editor_state
.cursor1
= {line
=1, pos
=3}
296 Editor_state
.screen_top1
= {line
=1, pos
=1}
297 Editor_state
.screen_bottom1
= {}
298 -- click to the left of the line
299 edit
.draw(Editor_state
)
300 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
-4,Editor_state
.top
+5, 1)
301 -- cursor moves to start of line
302 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:line')
303 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:pos')
304 check_nil(Editor_state
.selection1
.line
, 'F - test_click_with_mouse_to_left_of_line/selection is empty to avoid perturbing future edits')
307 function test_click_with_mouse_takes_margins_into_account()
308 io
.write('\ntest_click_with_mouse_takes_margins_into_account')
309 -- display two lines with cursor on one of them
310 App
.screen
.init
{width
=100, height
=80}
311 Editor_state
= edit
.initialize_test_state()
312 Editor_state
.left
= 50 -- occupy only right side of screen
313 Editor_state
.lines
= load_array
{'abc', 'def'}
314 Text
.redraw_all(Editor_state
)
315 Editor_state
.cursor1
= {line
=2, pos
=1}
316 Editor_state
.screen_top1
= {line
=1, pos
=1}
317 Editor_state
.screen_bottom1
= {}
318 -- click on the other line
319 edit
.draw(Editor_state
)
320 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
322 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_with_mouse_takes_margins_into_account/cursor:line')
323 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_click_with_mouse_takes_margins_into_account/cursor:pos')
324 check_nil(Editor_state
.selection1
.line
, 'F - test_click_with_mouse_takes_margins_into_account/selection is empty to avoid perturbing future edits')
327 function test_click_with_mouse_on_empty_line()
328 io
.write('\ntest_click_with_mouse_on_empty_line')
329 -- display two lines with the first one empty
330 App
.screen
.init
{width
=50, height
=80}
331 Editor_state
= edit
.initialize_test_state()
332 Editor_state
.lines
= load_array
{'', 'def'}
333 Text
.redraw_all(Editor_state
)
334 Editor_state
.cursor1
= {line
=2, pos
=1}
335 Editor_state
.screen_top1
= {line
=1, pos
=1}
336 Editor_state
.screen_bottom1
= {}
337 -- click on the empty line
338 edit
.draw(Editor_state
)
339 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
341 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_with_mouse_on_empty_line/cursor')
344 function test_draw_text()
345 io
.write('\ntest_draw_text')
346 App
.screen
.init
{width
=120, height
=60}
347 Editor_state
= edit
.initialize_test_state()
348 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi'}
349 Text
.redraw_all(Editor_state
)
350 Editor_state
.cursor1
= {line
=1, pos
=1}
351 Editor_state
.screen_top1
= {line
=1, pos
=1}
352 Editor_state
.screen_bottom1
= {}
353 edit
.draw(Editor_state
)
354 local y
= Editor_state
.top
355 App
.screen
.check(y
, 'abc', 'F - test_draw_text/screen:1')
356 y
= y
+ Editor_state
.line_height
357 App
.screen
.check(y
, 'def', 'F - test_draw_text/screen:2')
358 y
= y
+ Editor_state
.line_height
359 App
.screen
.check(y
, 'ghi', 'F - test_draw_text/screen:3')
362 function test_draw_wrapping_text()
363 io
.write('\ntest_draw_wrapping_text')
364 App
.screen
.init
{width
=50, height
=60}
365 Editor_state
= edit
.initialize_test_state()
366 Editor_state
.lines
= load_array
{'abc', 'defgh', 'xyz'}
367 Text
.redraw_all(Editor_state
)
368 Editor_state
.cursor1
= {line
=1, pos
=1}
369 Editor_state
.screen_top1
= {line
=1, pos
=1}
370 Editor_state
.screen_bottom1
= {}
371 edit
.draw(Editor_state
)
372 local y
= Editor_state
.top
373 App
.screen
.check(y
, 'abc', 'F - test_draw_wrapping_text/screen:1')
374 y
= y
+ Editor_state
.line_height
375 App
.screen
.check(y
, 'de', 'F - test_draw_wrapping_text/screen:2')
376 y
= y
+ Editor_state
.line_height
377 App
.screen
.check(y
, 'fgh', 'F - test_draw_wrapping_text/screen:3')
380 function test_draw_word_wrapping_text()
381 io
.write('\ntest_draw_word_wrapping_text')
382 App
.screen
.init
{width
=60, height
=60}
383 Editor_state
= edit
.initialize_test_state()
384 Editor_state
.lines
= load_array
{'abc def ghi', 'jkl'}
385 Text
.redraw_all(Editor_state
)
386 Editor_state
.cursor1
= {line
=1, pos
=1}
387 Editor_state
.screen_top1
= {line
=1, pos
=1}
388 Editor_state
.screen_bottom1
= {}
389 edit
.draw(Editor_state
)
390 local y
= Editor_state
.top
391 App
.screen
.check(y
, 'abc ', 'F - test_draw_word_wrapping_text/screen:1')
392 y
= y
+ Editor_state
.line_height
393 App
.screen
.check(y
, 'def ', 'F - test_draw_word_wrapping_text/screen:2')
394 y
= y
+ Editor_state
.line_height
395 App
.screen
.check(y
, 'ghi', 'F - test_draw_word_wrapping_text/screen:3')
398 function test_click_with_mouse_on_wrapping_line()
399 io
.write('\ntest_click_with_mouse_on_wrapping_line')
400 -- display two lines with cursor on one of them
401 App
.screen
.init
{width
=50, height
=80}
402 Editor_state
= edit
.initialize_test_state()
403 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr stu'}
404 Text
.redraw_all(Editor_state
)
405 Editor_state
.cursor1
= {line
=1, pos
=20}
406 Editor_state
.screen_top1
= {line
=1, pos
=1}
407 Editor_state
.screen_bottom1
= {}
408 -- click on the other line
409 edit
.draw(Editor_state
)
410 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
412 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_with_mouse_on_wrapping_line/cursor:line')
413 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_click_with_mouse_on_wrapping_line/cursor:pos')
414 check_nil(Editor_state
.selection1
.line
, 'F - test_click_with_mouse_on_wrapping_line/selection is empty to avoid perturbing future edits')
417 function test_click_with_mouse_on_wrapping_line_takes_margins_into_account()
418 io
.write('\ntest_click_with_mouse_on_wrapping_line_takes_margins_into_account')
419 -- display two lines with cursor on one of them
420 App
.screen
.init
{width
=100, height
=80}
421 Editor_state
= edit
.initialize_test_state()
422 Editor_state
.left
= 50 -- occupy only right side of screen
423 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr stu'}
424 Text
.redraw_all(Editor_state
)
425 Editor_state
.cursor1
= {line
=1, pos
=20}
426 Editor_state
.screen_top1
= {line
=1, pos
=1}
427 Editor_state
.screen_bottom1
= {}
428 -- click on the other line
429 edit
.draw(Editor_state
)
430 edit
.run_after_mouse_click(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
432 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:line')
433 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:pos')
434 check_nil(Editor_state
.selection1
.line
, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/selection is empty to avoid perturbing future edits')
437 function test_draw_text_wrapping_within_word()
438 -- arrange a screen line that needs to be split within a word
439 io
.write('\ntest_draw_text_wrapping_within_word')
440 App
.screen
.init
{width
=60, height
=60}
441 Editor_state
= edit
.initialize_test_state()
442 Editor_state
.lines
= load_array
{'abcd e fghijk', 'xyz'}
443 Text
.redraw_all(Editor_state
)
444 Editor_state
.cursor1
= {line
=1, pos
=1}
445 Editor_state
.screen_top1
= {line
=1, pos
=1}
446 Editor_state
.screen_bottom1
= {}
447 edit
.draw(Editor_state
)
448 local y
= Editor_state
.top
449 App
.screen
.check(y
, 'abcd ', 'F - test_draw_text_wrapping_within_word/screen:1')
450 y
= y
+ Editor_state
.line_height
451 App
.screen
.check(y
, 'e fgh', 'F - test_draw_text_wrapping_within_word/screen:2')
452 y
= y
+ Editor_state
.line_height
453 App
.screen
.check(y
, 'ijk', 'F - test_draw_text_wrapping_within_word/screen:3')
456 function test_draw_wrapping_text_containing_non_ascii()
457 -- draw a long line containing non-ASCII
458 io
.write('\ntest_draw_wrapping_text_containing_non_ascii')
459 App
.screen
.init
{width
=60, height
=60}
460 Editor_state
= edit
.initialize_test_state()
461 Editor_state
.lines
= load_array
{'madam I’m adam', 'xyz'} -- notice the non-ASCII apostrophe
462 Text
.redraw_all(Editor_state
)
463 Editor_state
.cursor1
= {line
=1, pos
=1}
464 Editor_state
.screen_top1
= {line
=1, pos
=1}
465 Editor_state
.screen_bottom1
= {}
466 edit
.draw(Editor_state
)
467 local y
= Editor_state
.top
468 App
.screen
.check(y
, 'mad', 'F - test_draw_wrapping_text_containing_non_ascii/screen:1')
469 y
= y
+ Editor_state
.line_height
470 App
.screen
.check(y
, 'am I', 'F - test_draw_wrapping_text_containing_non_ascii/screen:2')
471 y
= y
+ Editor_state
.line_height
472 App
.screen
.check(y
, '’m a', 'F - test_draw_wrapping_text_containing_non_ascii/screen:3')
475 function test_click_on_wrapping_line()
476 io
.write('\ntest_click_on_wrapping_line')
477 -- display a wrapping line
478 App
.screen
.init
{width
=75, height
=80}
479 Editor_state
= edit
.initialize_test_state()
481 Editor_state
.lines
= load_array
{"madam I'm adam"}
482 Text
.redraw_all(Editor_state
)
483 Editor_state
.cursor1
= {line
=1, pos
=1}
484 Editor_state
.screen_top1
= {line
=1, pos
=1}
485 Editor_state
.screen_bottom1
= {}
486 edit
.draw(Editor_state
)
487 local y
= Editor_state
.top
488 App
.screen
.check(y
, 'madam ', 'F - test_click_on_wrapping_line/baseline/screen:1')
489 y
= y
+ Editor_state
.line_height
490 App
.screen
.check(y
, "I'm ad", 'F - test_click_on_wrapping_line/baseline/screen:2')
491 y
= y
+ Editor_state
.line_height
492 -- click past end of second screen line
493 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
494 -- cursor moves to end of screen line
495 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_on_wrapping_line/cursor:line')
496 check_eq(Editor_state
.cursor1
.pos
, 12, 'F - test_click_on_wrapping_line/cursor:pos')
499 function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen()
500 io
.write('\ntest_click_on_wrapping_line_rendered_from_partway_at_top_of_screen')
501 -- display a wrapping line from its second screen line
502 App
.screen
.init
{width
=75, height
=80}
503 Editor_state
= edit
.initialize_test_state()
505 Editor_state
.lines
= load_array
{"madam I'm adam"}
506 Text
.redraw_all(Editor_state
)
507 Editor_state
.cursor1
= {line
=1, pos
=8}
508 Editor_state
.screen_top1
= {line
=1, pos
=7}
509 Editor_state
.screen_bottom1
= {}
510 edit
.draw(Editor_state
)
511 local y
= Editor_state
.top
512 App
.screen
.check(y
, "I'm ad", 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/baseline/screen:2')
513 y
= y
+ Editor_state
.line_height
514 -- click past end of second screen line
515 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
516 -- cursor moves to end of screen line
517 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/cursor:line')
518 check_eq(Editor_state
.cursor1
.pos
, 12, 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/cursor:pos')
521 function test_click_past_end_of_wrapping_line()
522 io
.write('\ntest_click_past_end_of_wrapping_line')
523 -- display a wrapping line
524 App
.screen
.init
{width
=75, height
=80}
525 Editor_state
= edit
.initialize_test_state()
527 Editor_state
.lines
= load_array
{"madam I'm adam"}
528 Text
.redraw_all(Editor_state
)
529 Editor_state
.cursor1
= {line
=1, pos
=1}
530 Editor_state
.screen_top1
= {line
=1, pos
=1}
531 Editor_state
.screen_bottom1
= {}
532 edit
.draw(Editor_state
)
533 local y
= Editor_state
.top
534 App
.screen
.check(y
, 'madam ', 'F - test_click_past_end_of_wrapping_line/baseline/screen:1')
535 y
= y
+ Editor_state
.line_height
536 App
.screen
.check(y
, "I'm ad", 'F - test_click_past_end_of_wrapping_line/baseline/screen:2')
537 y
= y
+ Editor_state
.line_height
538 App
.screen
.check(y
, 'am', 'F - test_click_past_end_of_wrapping_line/baseline/screen:3')
539 y
= y
+ Editor_state
.line_height
540 -- click past the end of it
541 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
542 -- cursor moves to end of line
543 check_eq(Editor_state
.cursor1
.pos
, 15, 'F - test_click_past_end_of_wrapping_line/cursor') -- one more than the number of UTF-8 code-points
546 function test_click_past_end_of_wrapping_line_containing_non_ascii()
547 io
.write('\ntest_click_past_end_of_wrapping_line_containing_non_ascii')
548 -- display a wrapping line containing non-ASCII
549 App
.screen
.init
{width
=75, height
=80}
550 Editor_state
= edit
.initialize_test_state()
552 Editor_state
.lines
= load_array
{'madam I’m adam'} -- notice the non-ASCII apostrophe
553 Text
.redraw_all(Editor_state
)
554 Editor_state
.cursor1
= {line
=1, pos
=1}
555 Editor_state
.screen_top1
= {line
=1, pos
=1}
556 Editor_state
.screen_bottom1
= {}
557 edit
.draw(Editor_state
)
558 local y
= Editor_state
.top
559 App
.screen
.check(y
, 'madam ', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:1')
560 y
= y
+ Editor_state
.line_height
561 App
.screen
.check(y
, 'I’m ad', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:2')
562 y
= y
+ Editor_state
.line_height
563 App
.screen
.check(y
, 'am', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:3')
564 y
= y
+ Editor_state
.line_height
565 -- click past the end of it
566 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
567 -- cursor moves to end of line
568 check_eq(Editor_state
.cursor1
.pos
, 15, 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points
571 function test_click_past_end_of_word_wrapping_line()
572 io
.write('\ntest_click_past_end_of_word_wrapping_line')
573 -- display a long line wrapping at a word boundary on a screen of more realistic length
574 App
.screen
.init
{width
=160, height
=80}
575 Editor_state
= edit
.initialize_test_state()
577 -- 123456789012345678901
578 Editor_state
.lines
= load_array
{'the quick brown fox jumped over the lazy dog'}
579 Text
.redraw_all(Editor_state
)
580 Editor_state
.cursor1
= {line
=1, pos
=1}
581 Editor_state
.screen_top1
= {line
=1, pos
=1}
582 Editor_state
.screen_bottom1
= {}
583 edit
.draw(Editor_state
)
584 local y
= Editor_state
.top
585 App
.screen
.check(y
, 'the quick brown fox ', 'F - test_click_past_end_of_word_wrapping_line/baseline/screen:1')
586 y
= y
+ Editor_state
.line_height
587 -- click past the end of the screen line
588 edit
.run_after_mouse_click(Editor_state
, App
.screen
.width
-2,y
-2, 1)
589 -- cursor moves to end of screen line
590 check_eq(Editor_state
.cursor1
.pos
, 20, 'F - test_click_past_end_of_word_wrapping_line/cursor')
593 function test_select_text()
594 io
.write('\ntest_select_text')
595 -- display a line of text
596 App
.screen
.init
{width
=75, height
=80}
597 Editor_state
= edit
.initialize_test_state()
598 Editor_state
.lines
= load_array
{'abc def'}
599 Text
.redraw_all(Editor_state
)
600 Editor_state
.cursor1
= {line
=1, pos
=1}
601 Editor_state
.screen_top1
= {line
=1, pos
=1}
602 Editor_state
.screen_bottom1
= {}
603 edit
.draw(Editor_state
)
605 App
.fake_key_press('lshift')
606 edit
.run_after_keychord(Editor_state
, 'S-right')
607 App
.fake_key_release('lshift')
608 edit
.key_released(Editor_state
, 'lshift')
609 -- selection persists even after shift is released
610 check_eq(Editor_state
.selection1
.line
, 1, 'F - test_select_text/selection:line')
611 check_eq(Editor_state
.selection1
.pos
, 1, 'F - test_select_text/selection:pos')
612 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_select_text/cursor:line')
613 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_select_text/cursor:pos')
616 function test_cursor_movement_without_shift_resets_selection()
617 io
.write('\ntest_cursor_movement_without_shift_resets_selection')
618 -- display a line of text with some part selected
619 App
.screen
.init
{width
=75, height
=80}
620 Editor_state
= edit
.initialize_test_state()
621 Editor_state
.lines
= load_array
{'abc'}
622 Text
.redraw_all(Editor_state
)
623 Editor_state
.cursor1
= {line
=1, pos
=1}
624 Editor_state
.selection1
= {line
=1, pos
=2}
625 Editor_state
.screen_top1
= {line
=1, pos
=1}
626 Editor_state
.screen_bottom1
= {}
627 edit
.draw(Editor_state
)
628 -- press an arrow key without shift
629 edit
.run_after_keychord(Editor_state
, 'right')
630 -- no change to data, selection is reset
631 check_nil(Editor_state
.selection1
.line
, 'F - test_cursor_movement_without_shift_resets_selection')
632 check_eq(Editor_state
.lines
[1].data
, 'abc', 'F - test_cursor_movement_without_shift_resets_selection/data')
635 function test_edit_deletes_selection()
636 io
.write('\ntest_edit_deletes_selection')
637 -- display a line of text with some part selected
638 App
.screen
.init
{width
=75, height
=80}
639 Editor_state
= edit
.initialize_test_state()
640 Editor_state
.lines
= load_array
{'abc'}
641 Text
.redraw_all(Editor_state
)
642 Editor_state
.cursor1
= {line
=1, pos
=1}
643 Editor_state
.selection1
= {line
=1, pos
=2}
644 Editor_state
.screen_top1
= {line
=1, pos
=1}
645 Editor_state
.screen_bottom1
= {}
646 edit
.draw(Editor_state
)
648 edit
.run_after_textinput(Editor_state
, 'x')
649 -- selected text is deleted and replaced with the key
650 check_eq(Editor_state
.lines
[1].data
, 'xbc', 'F - test_edit_deletes_selection')
653 function test_edit_with_shift_key_deletes_selection()
654 io
.write('\ntest_edit_with_shift_key_deletes_selection')
655 -- display a line of text with some part selected
656 App
.screen
.init
{width
=75, height
=80}
657 Editor_state
= edit
.initialize_test_state()
658 Editor_state
.lines
= load_array
{'abc'}
659 Text
.redraw_all(Editor_state
)
660 Editor_state
.cursor1
= {line
=1, pos
=1}
661 Editor_state
.selection1
= {line
=1, pos
=2}
662 Editor_state
.screen_top1
= {line
=1, pos
=1}
663 Editor_state
.screen_bottom1
= {}
664 edit
.draw(Editor_state
)
665 -- mimic precise keypresses for a capital letter
666 App
.fake_key_press('lshift')
667 edit
.keychord_pressed(Editor_state
, 'd', 'd')
668 edit
.textinput(Editor_state
, 'D')
669 edit
.key_released(Editor_state
, 'd')
670 App
.fake_key_release('lshift')
671 -- selected text is deleted and replaced with the key
672 check_nil(Editor_state
.selection1
.line
, 'F - test_edit_with_shift_key_deletes_selection')
673 check_eq(Editor_state
.lines
[1].data
, 'Dbc', 'F - test_edit_with_shift_key_deletes_selection/data')
676 function test_copy_does_not_reset_selection()
677 io
.write('\ntest_copy_does_not_reset_selection')
678 -- display a line of text with a selection
679 App
.screen
.init
{width
=75, height
=80}
680 Editor_state
= edit
.initialize_test_state()
681 Editor_state
.lines
= load_array
{'abc'}
682 Text
.redraw_all(Editor_state
)
683 Editor_state
.cursor1
= {line
=1, pos
=1}
684 Editor_state
.selection1
= {line
=1, pos
=2}
685 Editor_state
.screen_top1
= {line
=1, pos
=1}
686 Editor_state
.screen_bottom1
= {}
687 edit
.draw(Editor_state
)
689 edit
.run_after_keychord(Editor_state
, 'C-c')
690 check_eq(App
.clipboard
, 'a', 'F - test_copy_does_not_reset_selection/clipboard')
691 -- selection is reset since shift key is not pressed
692 check(Editor_state
.selection1
.line
, 'F - test_copy_does_not_reset_selection')
696 io
.write('\ntest_cut')
697 -- display a line of text with some part selected
698 App
.screen
.init
{width
=75, height
=80}
699 Editor_state
= edit
.initialize_test_state()
700 Editor_state
.lines
= load_array
{'abc'}
701 Text
.redraw_all(Editor_state
)
702 Editor_state
.cursor1
= {line
=1, pos
=1}
703 Editor_state
.selection1
= {line
=1, pos
=2}
704 Editor_state
.screen_top1
= {line
=1, pos
=1}
705 Editor_state
.screen_bottom1
= {}
706 edit
.draw(Editor_state
)
708 edit
.run_after_keychord(Editor_state
, 'C-x')
709 check_eq(App
.clipboard
, 'a', 'F - test_cut/clipboard')
710 -- selected text is deleted
711 check_eq(Editor_state
.lines
[1].data
, 'bc', 'F - test_cut/data')
714 function test_paste_replaces_selection()
715 io
.write('\ntest_paste_replaces_selection')
716 -- display a line of text with a selection
717 App
.screen
.init
{width
=75, height
=80}
718 Editor_state
= edit
.initialize_test_state()
719 Editor_state
.lines
= load_array
{'abc', 'def'}
720 Text
.redraw_all(Editor_state
)
721 Editor_state
.cursor1
= {line
=2, pos
=1}
722 Editor_state
.selection1
= {line
=1, pos
=1}
723 Editor_state
.screen_top1
= {line
=1, pos
=1}
724 Editor_state
.screen_bottom1
= {}
725 edit
.draw(Editor_state
)
727 App
.clipboard
= 'xyz'
729 edit
.run_after_keychord(Editor_state
, 'C-v')
730 -- selection is reset since shift key is not pressed
731 -- selection includes the newline, so it's also deleted
732 check_eq(Editor_state
.lines
[1].data
, 'xyzdef', 'F - test_paste_replaces_selection')
735 function test_deleting_selection_may_scroll()
736 io
.write('\ntest_deleting_selection_may_scroll')
737 -- display lines 2/3/4
738 App
.screen
.init
{width
=120, height
=60}
739 Editor_state
= edit
.initialize_test_state()
740 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
741 Text
.redraw_all(Editor_state
)
742 Editor_state
.cursor1
= {line
=3, pos
=2}
743 Editor_state
.screen_top1
= {line
=2, pos
=1}
744 Editor_state
.screen_bottom1
= {}
745 edit
.draw(Editor_state
)
746 local y
= Editor_state
.top
747 App
.screen
.check(y
, 'def', 'F - test_deleting_selection_may_scroll/baseline/screen:1')
748 y
= y
+ Editor_state
.line_height
749 App
.screen
.check(y
, 'ghi', 'F - test_deleting_selection_may_scroll/baseline/screen:2')
750 y
= y
+ Editor_state
.line_height
751 App
.screen
.check(y
, 'jkl', 'F - test_deleting_selection_may_scroll/baseline/screen:3')
752 -- set up a selection starting above the currently displayed page
753 Editor_state
.selection1
= {line
=1, pos
=2}
755 edit
.run_after_keychord(Editor_state
, 'backspace')
757 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_deleting_selection_may_scroll')
758 check_eq(Editor_state
.lines
[1].data
, 'ahi', 'F - test_deleting_selection_may_scroll/data')
761 function test_edit_wrapping_text()
762 io
.write('\ntest_edit_wrapping_text')
763 App
.screen
.init
{width
=50, height
=60}
764 Editor_state
= edit
.initialize_test_state()
765 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
766 Text
.redraw_all(Editor_state
)
767 Editor_state
.cursor1
= {line
=2, pos
=4}
768 Editor_state
.screen_top1
= {line
=1, pos
=1}
769 Editor_state
.screen_bottom1
= {}
770 edit
.draw(Editor_state
)
771 edit
.run_after_textinput(Editor_state
, 'g')
772 local y
= Editor_state
.top
773 App
.screen
.check(y
, 'abc', 'F - test_edit_wrapping_text/screen:1')
774 y
= y
+ Editor_state
.line_height
775 App
.screen
.check(y
, 'de', 'F - test_edit_wrapping_text/screen:2')
776 y
= y
+ Editor_state
.line_height
777 App
.screen
.check(y
, 'fg', 'F - test_edit_wrapping_text/screen:3')
780 function test_insert_newline()
781 io
.write('\ntest_insert_newline')
782 -- display a few lines
783 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
784 Editor_state
= edit
.initialize_test_state()
785 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
786 Text
.redraw_all(Editor_state
)
787 Editor_state
.cursor1
= {line
=1, pos
=2}
788 Editor_state
.screen_top1
= {line
=1, pos
=1}
789 Editor_state
.screen_bottom1
= {}
790 edit
.draw(Editor_state
)
791 local y
= Editor_state
.top
792 App
.screen
.check(y
, 'abc', 'F - test_insert_newline/baseline/screen:1')
793 y
= y
+ Editor_state
.line_height
794 App
.screen
.check(y
, 'def', 'F - test_insert_newline/baseline/screen:2')
795 y
= y
+ Editor_state
.line_height
796 App
.screen
.check(y
, 'ghi', 'F - test_insert_newline/baseline/screen:3')
797 -- hitting the enter key splits the line
798 edit
.run_after_keychord(Editor_state
, 'return')
799 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_insert_newline/screen_top')
800 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_insert_newline/cursor:line')
801 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_insert_newline/cursor:pos')
803 App
.screen
.check(y
, 'a', 'F - test_insert_newline/screen:1')
804 y
= y
+ Editor_state
.line_height
805 App
.screen
.check(y
, 'bc', 'F - test_insert_newline/screen:2')
806 y
= y
+ Editor_state
.line_height
807 App
.screen
.check(y
, 'def', 'F - test_insert_newline/screen:3')
810 function test_insert_newline_at_start_of_line()
811 io
.write('\ntest_insert_newline_at_start_of_line')
813 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
814 Editor_state
= edit
.initialize_test_state()
815 Editor_state
.lines
= load_array
{'abc'}
816 Text
.redraw_all(Editor_state
)
817 Editor_state
.cursor1
= {line
=1, pos
=1}
818 Editor_state
.screen_top1
= {line
=1, pos
=1}
819 Editor_state
.screen_bottom1
= {}
820 -- hitting the enter key splits the line
821 edit
.run_after_keychord(Editor_state
, 'return')
822 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_insert_newline_at_start_of_line/cursor:line')
823 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_insert_newline_at_start_of_line/cursor:pos')
824 check_eq(Editor_state
.lines
[1].data
, '', 'F - test_insert_newline_at_start_of_line/data:1')
825 check_eq(Editor_state
.lines
[2].data
, 'abc', 'F - test_insert_newline_at_start_of_line/data:2')
828 function test_insert_from_clipboard()
829 io
.write('\ntest_insert_from_clipboard')
830 -- display a few lines
831 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
832 Editor_state
= edit
.initialize_test_state()
833 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
834 Text
.redraw_all(Editor_state
)
835 Editor_state
.cursor1
= {line
=1, pos
=2}
836 Editor_state
.screen_top1
= {line
=1, pos
=1}
837 Editor_state
.screen_bottom1
= {}
838 edit
.draw(Editor_state
)
839 local y
= Editor_state
.top
840 App
.screen
.check(y
, 'abc', 'F - test_insert_from_clipboard/baseline/screen:1')
841 y
= y
+ Editor_state
.line_height
842 App
.screen
.check(y
, 'def', 'F - test_insert_from_clipboard/baseline/screen:2')
843 y
= y
+ Editor_state
.line_height
844 App
.screen
.check(y
, 'ghi', 'F - test_insert_from_clipboard/baseline/screen:3')
845 -- paste some text including a newline, check that new line is created
846 App
.clipboard
= 'xy\nz'
847 edit
.run_after_keychord(Editor_state
, 'C-v')
848 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_insert_from_clipboard/screen_top')
849 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_insert_from_clipboard/cursor:line')
850 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_insert_from_clipboard/cursor:pos')
852 App
.screen
.check(y
, 'axy', 'F - test_insert_from_clipboard/screen:1')
853 y
= y
+ Editor_state
.line_height
854 App
.screen
.check(y
, 'zbc', 'F - test_insert_from_clipboard/screen:2')
855 y
= y
+ Editor_state
.line_height
856 App
.screen
.check(y
, 'def', 'F - test_insert_from_clipboard/screen:3')
859 function test_move_cursor_using_mouse()
860 io
.write('\ntest_move_cursor_using_mouse')
861 App
.screen
.init
{width
=50, height
=60}
862 Editor_state
= edit
.initialize_test_state()
863 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
864 Text
.redraw_all(Editor_state
)
865 Editor_state
.cursor1
= {line
=1, pos
=1}
866 Editor_state
.screen_top1
= {line
=1, pos
=1}
867 Editor_state
.screen_bottom1
= {}
868 Editor_state
.selection1
= {}
869 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
870 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
871 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_move_cursor_using_mouse/cursor:line')
872 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_move_cursor_using_mouse/cursor:pos')
873 check_nil(Editor_state
.selection1
.line
, 'F - test_move_cursor_using_mouse/selection:line')
874 check_nil(Editor_state
.selection1
.pos
, 'F - test_move_cursor_using_mouse/selection:pos')
877 function test_select_text_using_mouse()
878 io
.write('\ntest_select_text_using_mouse')
879 App
.screen
.init
{width
=50, height
=60}
880 Editor_state
= edit
.initialize_test_state()
881 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
882 Text
.redraw_all(Editor_state
)
883 Editor_state
.cursor1
= {line
=1, pos
=1}
884 Editor_state
.screen_top1
= {line
=1, pos
=1}
885 Editor_state
.screen_bottom1
= {}
886 Editor_state
.selection1
= {}
887 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
888 -- press and hold on first location
889 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
890 -- drag and release somewhere else
891 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+Editor_state
.line_height
+5, 1)
892 check_eq(Editor_state
.selection1
.line
, 1, 'F - test_select_text_using_mouse/selection:line')
893 check_eq(Editor_state
.selection1
.pos
, 2, 'F - test_select_text_using_mouse/selection:pos')
894 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_select_text_using_mouse/cursor:line')
895 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_select_text_using_mouse/cursor:pos')
898 function test_select_text_using_mouse_and_shift()
899 io
.write('\ntest_select_text_using_mouse_and_shift')
900 App
.screen
.init
{width
=50, height
=60}
901 Editor_state
= edit
.initialize_test_state()
902 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
903 Text
.redraw_all(Editor_state
)
904 Editor_state
.cursor1
= {line
=1, pos
=1}
905 Editor_state
.screen_top1
= {line
=1, pos
=1}
906 Editor_state
.screen_bottom1
= {}
907 Editor_state
.selection1
= {}
908 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
909 -- click on first location
910 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
911 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
912 -- hold down shift and click somewhere else
913 App
.fake_key_press('lshift')
914 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+5, 1)
915 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+Editor_state
.line_height
+5, 1)
916 App
.fake_key_release('lshift')
917 check_eq(Editor_state
.selection1
.line
, 1, 'F - test_select_text_using_mouse_and_shift/selection:line')
918 check_eq(Editor_state
.selection1
.pos
, 2, 'F - test_select_text_using_mouse_and_shift/selection:pos')
919 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_select_text_using_mouse_and_shift/cursor:line')
920 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_select_text_using_mouse_and_shift/cursor:pos')
923 function test_select_text_repeatedly_using_mouse_and_shift()
924 io
.write('\ntest_select_text_repeatedly_using_mouse_and_shift')
925 App
.screen
.init
{width
=50, height
=60}
926 Editor_state
= edit
.initialize_test_state()
927 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
928 Text
.redraw_all(Editor_state
)
929 Text
.redraw_all(Editor_state
)
930 Editor_state
.cursor1
= {line
=1, pos
=1}
931 Editor_state
.screen_top1
= {line
=1, pos
=1}
932 Editor_state
.screen_bottom1
= {}
933 Editor_state
.selection1
= {}
934 edit
.draw(Editor_state
) -- populate line_cache.starty for each line Editor_state.line_cache
935 -- click on first location
936 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
937 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+5, 1)
938 -- hold down shift and click on a second location
939 App
.fake_key_press('lshift')
940 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+5, 1)
941 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+Editor_state
.line_height
+5, 1)
942 -- hold down shift and click at a third location
943 App
.fake_key_press('lshift')
944 edit
.run_after_mouse_press(Editor_state
, Editor_state
.left
+20,Editor_state
.top
+5, 1)
945 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+Editor_state
.line_height
+5, 1)
946 App
.fake_key_release('lshift')
947 -- selection is between first and third location. forget the second location, not the first.
948 check_eq(Editor_state
.selection1
.line
, 1, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:line')
949 check_eq(Editor_state
.selection1
.pos
, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:pos')
950 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/cursor:line')
951 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_select_text_repeatedly_using_mouse_and_shift/cursor:pos')
954 function test_cut_without_selection()
955 io
.write('\ntest_cut_without_selection')
956 -- display a few lines
957 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
958 Editor_state
= edit
.initialize_test_state()
959 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
960 Text
.redraw_all(Editor_state
)
961 Editor_state
.cursor1
= {line
=1, pos
=2}
962 Editor_state
.screen_top1
= {line
=1, pos
=1}
963 Editor_state
.screen_bottom1
= {}
964 Editor_state
.selection1
= {}
965 edit
.draw(Editor_state
)
966 -- try to cut without selecting text
967 edit
.run_after_keychord(Editor_state
, 'C-x')
969 check_nil(Editor_state
.selection1
.line
, 'F - test_cut_without_selection')
972 function test_pagedown()
973 io
.write('\ntest_pagedown')
974 App
.screen
.init
{width
=120, height
=45}
975 Editor_state
= edit
.initialize_test_state()
976 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi'}
977 Text
.redraw_all(Editor_state
)
978 Editor_state
.cursor1
= {line
=1, pos
=1}
979 Editor_state
.screen_top1
= {line
=1, pos
=1}
980 Editor_state
.screen_bottom1
= {}
981 -- initially the first two lines are displayed
982 edit
.draw(Editor_state
)
983 local y
= Editor_state
.top
984 App
.screen
.check(y
, 'abc', 'F - test_pagedown/baseline/screen:1')
985 y
= y
+ Editor_state
.line_height
986 App
.screen
.check(y
, 'def', 'F - test_pagedown/baseline/screen:2')
987 -- after pagedown the bottom line becomes the top
988 edit
.run_after_keychord(Editor_state
, 'pagedown')
989 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_pagedown/screen_top')
990 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_pagedown/cursor')
992 App
.screen
.check(y
, 'def', 'F - test_pagedown/screen:1')
993 y
= y
+ Editor_state
.line_height
994 App
.screen
.check(y
, 'ghi', 'F - test_pagedown/screen:2')
997 function test_pagedown_skips_drawings()
998 io
.write('\ntest_pagedown_skips_drawings')
999 -- some lines of text with a drawing intermixed
1000 local drawing_width
= 50
1001 App
.screen
.init
{width
=Editor_state
.left
+drawing_width
, height
=80}
1002 Editor_state
= edit
.initialize_test_state()
1003 Editor_state
.lines
= load_array
{'abc', -- height 15
1004 '```lines', '```', -- height 25
1007 Text
.redraw_all(Editor_state
)
1008 check_eq(Editor_state
.lines
[2].mode
, 'drawing', 'F - test_pagedown_skips_drawings/baseline/lines')
1009 Editor_state
.cursor1
= {line
=1, pos
=1}
1010 Editor_state
.screen_top1
= {line
=1, pos
=1}
1011 Editor_state
.screen_bottom1
= {}
1012 local drawing_height
= Drawing_padding_height
+ drawing_width
/2 -- default
1013 -- initially the screen displays the first line and the drawing
1014 -- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80px
1015 edit
.draw(Editor_state
)
1016 local y
= Editor_state
.top
1017 App
.screen
.check(y
, 'abc', 'F - test_pagedown_skips_drawings/baseline/screen:1')
1018 -- after pagedown the screen draws the drawing up top
1019 -- 15px margin + 10px margin + 25px drawing + 10px margin + 15px line3 = 75px < screen height 80px
1020 edit
.run_after_keychord(Editor_state
, 'pagedown')
1021 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_pagedown_skips_drawings/screen_top')
1022 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_pagedown_skips_drawings/cursor')
1023 y
= Editor_state
.top
+ drawing_height
1024 App
.screen
.check(y
, 'def', 'F - test_pagedown_skips_drawings/screen:1')
1027 function test_pagedown_often_shows_start_of_wrapping_line()
1028 io
.write('\ntest_pagedown_often_shows_start_of_wrapping_line')
1029 -- draw a few lines ending in part of a wrapping line
1030 App
.screen
.init
{width
=50, height
=60}
1031 Editor_state
= edit
.initialize_test_state()
1032 Editor_state
.lines
= load_array
{'abc', 'def ghi jkl', 'mno'}
1033 Text
.redraw_all(Editor_state
)
1034 Editor_state
.cursor1
= {line
=1, pos
=1}
1035 Editor_state
.screen_top1
= {line
=1, pos
=1}
1036 Editor_state
.screen_bottom1
= {}
1037 edit
.draw(Editor_state
)
1038 local y
= Editor_state
.top
1039 App
.screen
.check(y
, 'abc', 'F - test_pagedown_often_shows_start_of_wrapping_line/baseline/screen:1')
1040 y
= y
+ Editor_state
.line_height
1041 App
.screen
.check(y
, 'def ', 'F - test_pagedown_often_shows_start_of_wrapping_line/baseline/screen:2')
1042 y
= y
+ Editor_state
.line_height
1043 App
.screen
.check(y
, 'ghi ', 'F - test_pagedown_often_shows_start_of_wrapping_line/baseline/screen:3')
1044 -- after pagedown we start drawing from the bottom _line_ (multiple screen lines)
1045 edit
.run_after_keychord(Editor_state
, 'pagedown')
1046 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_pagedown_often_shows_start_of_wrapping_line/screen_top:line')
1047 check_eq(Editor_state
.screen_top1
.pos
, 1, 'F - test_pagedown_often_shows_start_of_wrapping_line/screen_top:pos')
1048 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_pagedown_often_shows_start_of_wrapping_line/cursor:line')
1049 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_pagedown_often_shows_start_of_wrapping_line/cursor:pos')
1050 y
= Editor_state
.top
1051 App
.screen
.check(y
, 'def ', 'F - test_pagedown_often_shows_start_of_wrapping_line/screen:1')
1052 y
= y
+ Editor_state
.line_height
1053 App
.screen
.check(y
, 'ghi ', 'F - test_pagedown_often_shows_start_of_wrapping_line/screen:2')
1054 y
= y
+ Editor_state
.line_height
1055 App
.screen
.check(y
, 'jkl', 'F - test_pagedown_often_shows_start_of_wrapping_line/screen:3')
1058 function test_pagedown_can_start_from_middle_of_long_wrapping_line()
1059 io
.write('\ntest_pagedown_can_start_from_middle_of_long_wrapping_line')
1060 -- draw a few lines starting from a very long wrapping line
1061 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1062 Editor_state
= edit
.initialize_test_state()
1063 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr stu vwx yza bcd efg hij', 'XYZ'}
1064 Text
.redraw_all(Editor_state
)
1065 Editor_state
.cursor1
= {line
=1, pos
=2}
1066 Editor_state
.screen_top1
= {line
=1, pos
=1}
1067 Editor_state
.screen_bottom1
= {}
1068 edit
.draw(Editor_state
)
1069 local y
= Editor_state
.top
1070 App
.screen
.check(y
, 'abc ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/baseline/screen:1')
1071 y
= y
+ Editor_state
.line_height
1072 App
.screen
.check(y
, 'def ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/baseline/screen:2')
1073 y
= y
+ Editor_state
.line_height
1074 App
.screen
.check(y
, 'ghi ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/baseline/screen:3')
1075 -- after pagedown we scroll down the very long wrapping line
1076 edit
.run_after_keychord(Editor_state
, 'pagedown')
1077 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen_top:line')
1078 check_eq(Editor_state
.screen_top1
.pos
, 9, 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen_top:pos')
1079 y
= Editor_state
.top
1080 App
.screen
.check(y
, 'ghi ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen:1')
1081 y
= y
+ Editor_state
.line_height
1082 App
.screen
.check(y
, 'jkl ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen:2')
1083 y
= y
+ Editor_state
.line_height
1084 App
.screen
.check(y
, 'mno ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen:3')
1087 function test_pagedown_never_moves_up()
1088 io
.write('\ntest_pagedown_never_moves_up')
1089 -- draw the final screen line of a wrapping line
1090 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1091 Editor_state
= edit
.initialize_test_state()
1092 Editor_state
.lines
= load_array
{'abc def ghi'}
1093 Text
.redraw_all(Editor_state
)
1094 Editor_state
.cursor1
= {line
=1, pos
=9}
1095 Editor_state
.screen_top1
= {line
=1, pos
=9}
1096 Editor_state
.screen_bottom1
= {}
1097 edit
.draw(Editor_state
)
1098 -- pagedown makes no change
1099 edit
.run_after_keychord(Editor_state
, 'pagedown')
1100 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_pagedown_never_moves_up/screen_top:line')
1101 check_eq(Editor_state
.screen_top1
.pos
, 9, 'F - test_pagedown_never_moves_up/screen_top:pos')
1104 function test_down_arrow_moves_cursor()
1105 io
.write('\ntest_down_arrow_moves_cursor')
1106 App
.screen
.init
{width
=120, height
=60}
1107 Editor_state
= edit
.initialize_test_state()
1108 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1109 Text
.redraw_all(Editor_state
)
1110 Editor_state
.cursor1
= {line
=1, pos
=1}
1111 Editor_state
.screen_top1
= {line
=1, pos
=1}
1112 Editor_state
.screen_bottom1
= {}
1113 -- initially the first three lines are displayed
1114 edit
.draw(Editor_state
)
1115 local y
= Editor_state
.top
1116 App
.screen
.check(y
, 'abc', 'F - test_down_arrow_moves_cursor/baseline/screen:1')
1117 y
= y
+ Editor_state
.line_height
1118 App
.screen
.check(y
, 'def', 'F - test_down_arrow_moves_cursor/baseline/screen:2')
1119 y
= y
+ Editor_state
.line_height
1120 App
.screen
.check(y
, 'ghi', 'F - test_down_arrow_moves_cursor/baseline/screen:3')
1121 -- after hitting the down arrow, the cursor moves down by 1 line
1122 edit
.run_after_keychord(Editor_state
, 'down')
1123 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_down_arrow_moves_cursor/screen_top')
1124 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_down_arrow_moves_cursor/cursor')
1125 -- the screen is unchanged
1126 y
= Editor_state
.top
1127 App
.screen
.check(y
, 'abc', 'F - test_down_arrow_moves_cursor/screen:1')
1128 y
= y
+ Editor_state
.line_height
1129 App
.screen
.check(y
, 'def', 'F - test_down_arrow_moves_cursor/screen:2')
1130 y
= y
+ Editor_state
.line_height
1131 App
.screen
.check(y
, 'ghi', 'F - test_down_arrow_moves_cursor/screen:3')
1134 function test_down_arrow_scrolls_down_by_one_line()
1135 io
.write('\ntest_down_arrow_scrolls_down_by_one_line')
1136 -- display the first three lines with the cursor on the bottom line
1137 App
.screen
.init
{width
=120, height
=60}
1138 Editor_state
= edit
.initialize_test_state()
1139 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1140 Text
.redraw_all(Editor_state
)
1141 Editor_state
.cursor1
= {line
=3, pos
=1}
1142 Editor_state
.screen_top1
= {line
=1, pos
=1}
1143 Editor_state
.screen_bottom1
= {}
1144 edit
.draw(Editor_state
)
1145 local y
= Editor_state
.top
1146 App
.screen
.check(y
, 'abc', 'F - test_down_arrow_scrolls_down_by_one_line/baseline/screen:1')
1147 y
= y
+ Editor_state
.line_height
1148 App
.screen
.check(y
, 'def', 'F - test_down_arrow_scrolls_down_by_one_line/baseline/screen:2')
1149 y
= y
+ Editor_state
.line_height
1150 App
.screen
.check(y
, 'ghi', 'F - test_down_arrow_scrolls_down_by_one_line/baseline/screen:3')
1151 -- after hitting the down arrow the screen scrolls down by one line
1152 edit
.run_after_keychord(Editor_state
, 'down')
1153 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_down_arrow_scrolls_down_by_one_line/screen_top')
1154 check_eq(Editor_state
.cursor1
.line
, 4, 'F - test_down_arrow_scrolls_down_by_one_line/cursor')
1155 y
= Editor_state
.top
1156 App
.screen
.check(y
, 'def', 'F - test_down_arrow_scrolls_down_by_one_line/screen:1')
1157 y
= y
+ Editor_state
.line_height
1158 App
.screen
.check(y
, 'ghi', 'F - test_down_arrow_scrolls_down_by_one_line/screen:2')
1159 y
= y
+ Editor_state
.line_height
1160 App
.screen
.check(y
, 'jkl', 'F - test_down_arrow_scrolls_down_by_one_line/screen:3')
1163 function test_down_arrow_scrolls_down_by_one_screen_line()
1164 io
.write('\ntest_down_arrow_scrolls_down_by_one_screen_line')
1165 -- display the first three lines with the cursor on the bottom line
1166 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1167 Editor_state
= edit
.initialize_test_state()
1168 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1169 Text
.redraw_all(Editor_state
)
1170 Editor_state
.cursor1
= {line
=3, pos
=1}
1171 Editor_state
.screen_top1
= {line
=1, pos
=1}
1172 Editor_state
.screen_bottom1
= {}
1173 edit
.draw(Editor_state
)
1174 local y
= Editor_state
.top
1175 App
.screen
.check(y
, 'abc', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:1')
1176 y
= y
+ Editor_state
.line_height
1177 App
.screen
.check(y
, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:2')
1178 y
= y
+ Editor_state
.line_height
1179 App
.screen
.check(y
, 'ghi ', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
1180 -- after hitting the down arrow the screen scrolls down by one line
1181 edit
.run_after_keychord(Editor_state
, 'down')
1182 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen_top')
1183 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_down_arrow_scrolls_down_by_one_screen_line/cursor:line')
1184 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_down_arrow_scrolls_down_by_one_screen_line/cursor:pos')
1185 y
= Editor_state
.top
1186 App
.screen
.check(y
, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen:1')
1187 y
= y
+ Editor_state
.line_height
1188 App
.screen
.check(y
, 'ghi ', 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen:2')
1189 y
= y
+ Editor_state
.line_height
1190 App
.screen
.check(y
, 'jkl', 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen:3')
1193 function test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word()
1194 io
.write('\ntest_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word')
1195 -- display the first three lines with the cursor on the bottom line
1196 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1197 Editor_state
= edit
.initialize_test_state()
1198 Editor_state
.lines
= load_array
{'abc', 'def', 'ghijkl', 'mno'}
1199 Text
.redraw_all(Editor_state
)
1200 Editor_state
.cursor1
= {line
=3, pos
=1}
1201 Editor_state
.screen_top1
= {line
=1, pos
=1}
1202 Editor_state
.screen_bottom1
= {}
1203 edit
.draw(Editor_state
)
1204 local y
= Editor_state
.top
1205 App
.screen
.check(y
, 'abc', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:1')
1206 y
= y
+ Editor_state
.line_height
1207 App
.screen
.check(y
, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:2')
1208 y
= y
+ Editor_state
.line_height
1209 App
.screen
.check(y
, 'ghij', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:3')
1210 -- after hitting the down arrow the screen scrolls down by one line
1211 edit
.run_after_keychord(Editor_state
, 'down')
1212 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen_top')
1213 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:line')
1214 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:pos')
1215 y
= Editor_state
.top
1216 App
.screen
.check(y
, 'def', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:1')
1217 y
= y
+ Editor_state
.line_height
1218 App
.screen
.check(y
, 'ghij', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:2')
1219 y
= y
+ Editor_state
.line_height
1220 App
.screen
.check(y
, 'kl', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:3')
1223 function test_page_down_followed_by_down_arrow_does_not_scroll_screen_up()
1224 io
.write('\ntest_page_down_followed_by_down_arrow_does_not_scroll_screen_up')
1225 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1226 Editor_state
= edit
.initialize_test_state()
1227 Editor_state
.lines
= load_array
{'abc', 'def', 'ghijkl', 'mno'}
1228 Text
.redraw_all(Editor_state
)
1229 Editor_state
.cursor1
= {line
=3, pos
=1}
1230 Editor_state
.screen_top1
= {line
=1, pos
=1}
1231 Editor_state
.screen_bottom1
= {}
1232 edit
.draw(Editor_state
)
1233 local y
= Editor_state
.top
1234 App
.screen
.check(y
, 'abc', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:1')
1235 y
= y
+ Editor_state
.line_height
1236 App
.screen
.check(y
, 'def', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:2')
1237 y
= y
+ Editor_state
.line_height
1238 App
.screen
.check(y
, 'ghij', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:3')
1239 -- after hitting pagedown the screen scrolls down to start of a long line
1240 edit
.run_after_keychord(Editor_state
, 'pagedown')
1241 check_eq(Editor_state
.screen_top1
.line
, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/screen_top')
1242 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/cursor:line')
1243 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/cursor:pos')
1244 -- after hitting down arrow the screen doesn't scroll down further, and certainly doesn't scroll up
1245 edit
.run_after_keychord(Editor_state
, 'down')
1246 check_eq(Editor_state
.screen_top1
.line
, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen_top')
1247 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:line')
1248 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:pos')
1249 y
= Editor_state
.top
1250 App
.screen
.check(y
, 'ghij', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:1')
1251 y
= y
+ Editor_state
.line_height
1252 App
.screen
.check(y
, 'kl', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:2')
1253 y
= y
+ Editor_state
.line_height
1254 App
.screen
.check(y
, 'mno', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:3')
1257 function test_up_arrow_moves_cursor()
1258 io
.write('\ntest_up_arrow_moves_cursor')
1259 -- display the first 3 lines with the cursor on the bottom line
1260 App
.screen
.init
{width
=120, height
=60}
1261 Editor_state
= edit
.initialize_test_state()
1262 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1263 Text
.redraw_all(Editor_state
)
1264 Editor_state
.cursor1
= {line
=3, pos
=1}
1265 Editor_state
.screen_top1
= {line
=1, pos
=1}
1266 Editor_state
.screen_bottom1
= {}
1267 edit
.draw(Editor_state
)
1268 local y
= Editor_state
.top
1269 App
.screen
.check(y
, 'abc', 'F - test_up_arrow_moves_cursor/baseline/screen:1')
1270 y
= y
+ Editor_state
.line_height
1271 App
.screen
.check(y
, 'def', 'F - test_up_arrow_moves_cursor/baseline/screen:2')
1272 y
= y
+ Editor_state
.line_height
1273 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_moves_cursor/baseline/screen:3')
1274 -- after hitting the up arrow the cursor moves up by 1 line
1275 edit
.run_after_keychord(Editor_state
, 'up')
1276 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_up_arrow_moves_cursor/screen_top')
1277 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_up_arrow_moves_cursor/cursor')
1278 -- the screen is unchanged
1279 y
= Editor_state
.top
1280 App
.screen
.check(y
, 'abc', 'F - test_up_arrow_moves_cursor/screen:1')
1281 y
= y
+ Editor_state
.line_height
1282 App
.screen
.check(y
, 'def', 'F - test_up_arrow_moves_cursor/screen:2')
1283 y
= y
+ Editor_state
.line_height
1284 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_moves_cursor/screen:3')
1287 function test_up_arrow_scrolls_up_by_one_line()
1288 io
.write('\ntest_up_arrow_scrolls_up_by_one_line')
1289 -- display the lines 2/3/4 with the cursor on line 2
1290 App
.screen
.init
{width
=120, height
=60}
1291 Editor_state
= edit
.initialize_test_state()
1292 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1293 Text
.redraw_all(Editor_state
)
1294 Editor_state
.cursor1
= {line
=2, pos
=1}
1295 Editor_state
.screen_top1
= {line
=2, pos
=1}
1296 Editor_state
.screen_bottom1
= {}
1297 edit
.draw(Editor_state
)
1298 local y
= Editor_state
.top
1299 App
.screen
.check(y
, 'def', 'F - test_up_arrow_scrolls_up_by_one_line/baseline/screen:1')
1300 y
= y
+ Editor_state
.line_height
1301 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_scrolls_up_by_one_line/baseline/screen:2')
1302 y
= y
+ Editor_state
.line_height
1303 App
.screen
.check(y
, 'jkl', 'F - test_up_arrow_scrolls_up_by_one_line/baseline/screen:3')
1304 -- after hitting the up arrow the screen scrolls up by one line
1305 edit
.run_after_keychord(Editor_state
, 'up')
1306 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_up_arrow_scrolls_up_by_one_line/screen_top')
1307 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_up_arrow_scrolls_up_by_one_line/cursor')
1308 y
= Editor_state
.top
1309 App
.screen
.check(y
, 'abc', 'F - test_up_arrow_scrolls_up_by_one_line/screen:1')
1310 y
= y
+ Editor_state
.line_height
1311 App
.screen
.check(y
, 'def', 'F - test_up_arrow_scrolls_up_by_one_line/screen:2')
1312 y
= y
+ Editor_state
.line_height
1313 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_scrolls_up_by_one_line/screen:3')
1316 function test_up_arrow_scrolls_up_by_one_screen_line()
1317 io
.write('\ntest_up_arrow_scrolls_up_by_one_screen_line')
1318 -- display lines starting from second screen line of a line
1319 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1320 Editor_state
= edit
.initialize_test_state()
1321 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1322 Text
.redraw_all(Editor_state
)
1323 Editor_state
.cursor1
= {line
=3, pos
=6}
1324 Editor_state
.screen_top1
= {line
=3, pos
=5}
1325 Editor_state
.screen_bottom1
= {}
1326 edit
.draw(Editor_state
)
1327 local y
= Editor_state
.top
1328 App
.screen
.check(y
, 'jkl', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:1')
1329 y
= y
+ Editor_state
.line_height
1330 App
.screen
.check(y
, 'mno', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:2')
1331 -- after hitting the up arrow the screen scrolls up to first screen line
1332 edit
.run_after_keychord(Editor_state
, 'up')
1333 y
= Editor_state
.top
1334 App
.screen
.check(y
, 'ghi ', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:1')
1335 y
= y
+ Editor_state
.line_height
1336 App
.screen
.check(y
, 'jkl', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:2')
1337 y
= y
+ Editor_state
.line_height
1338 App
.screen
.check(y
, 'mno', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:3')
1339 check_eq(Editor_state
.screen_top1
.line
, 3, 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen_top')
1340 check_eq(Editor_state
.screen_top1
.pos
, 1, 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen_top')
1341 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_up_arrow_scrolls_up_by_one_screen_line/cursor:line')
1342 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_up_arrow_scrolls_up_by_one_screen_line/cursor:pos')
1345 function test_up_arrow_scrolls_up_to_final_screen_line()
1346 io
.write('\ntest_up_arrow_scrolls_up_to_final_screen_line')
1347 -- display lines starting just after a long line
1348 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1349 Editor_state
= edit
.initialize_test_state()
1350 Editor_state
.lines
= load_array
{'abc def', 'ghi', 'jkl', 'mno'}
1351 Text
.redraw_all(Editor_state
)
1352 Editor_state
.cursor1
= {line
=2, pos
=1}
1353 Editor_state
.screen_top1
= {line
=2, pos
=1}
1354 Editor_state
.screen_bottom1
= {}
1355 edit
.draw(Editor_state
)
1356 local y
= Editor_state
.top
1357 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:1')
1358 y
= y
+ Editor_state
.line_height
1359 App
.screen
.check(y
, 'jkl', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:2')
1360 y
= y
+ Editor_state
.line_height
1361 App
.screen
.check(y
, 'mno', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:3')
1362 -- after hitting the up arrow the screen scrolls up to final screen line of previous line
1363 edit
.run_after_keychord(Editor_state
, 'up')
1364 y
= Editor_state
.top
1365 App
.screen
.check(y
, 'def', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:1')
1366 y
= y
+ Editor_state
.line_height
1367 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:2')
1368 y
= y
+ Editor_state
.line_height
1369 App
.screen
.check(y
, 'jkl', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:3')
1370 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen_top')
1371 check_eq(Editor_state
.screen_top1
.pos
, 5, 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen_top')
1372 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_up_arrow_scrolls_up_to_final_screen_line/cursor:line')
1373 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_up_arrow_scrolls_up_to_final_screen_line/cursor:pos')
1376 function test_up_arrow_scrolls_up_to_empty_line()
1377 io
.write('\ntest_up_arrow_scrolls_up_to_empty_line')
1378 -- display a screenful of text with an empty line just above it outside the screen
1379 App
.screen
.init
{width
=120, height
=60}
1380 Editor_state
= edit
.initialize_test_state()
1381 Editor_state
.lines
= load_array
{'', 'abc', 'def', 'ghi', 'jkl'}
1382 Text
.redraw_all(Editor_state
)
1383 Editor_state
.cursor1
= {line
=2, pos
=1}
1384 Editor_state
.screen_top1
= {line
=2, pos
=1}
1385 Editor_state
.screen_bottom1
= {}
1386 edit
.draw(Editor_state
)
1387 local y
= Editor_state
.top
1388 App
.screen
.check(y
, 'abc', 'F - test_up_arrow_scrolls_up_to_empty_line/baseline/screen:1')
1389 y
= y
+ Editor_state
.line_height
1390 App
.screen
.check(y
, 'def', 'F - test_up_arrow_scrolls_up_to_empty_line/baseline/screen:2')
1391 y
= y
+ Editor_state
.line_height
1392 App
.screen
.check(y
, 'ghi', 'F - test_up_arrow_scrolls_up_to_empty_line/baseline/screen:3')
1393 -- after hitting the up arrow the screen scrolls up by one line
1394 edit
.run_after_keychord(Editor_state
, 'up')
1395 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_up_arrow_scrolls_up_to_empty_line/screen_top')
1396 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_up_arrow_scrolls_up_to_empty_line/cursor')
1397 y
= Editor_state
.top
1399 y
= y
+ Editor_state
.line_height
1400 App
.screen
.check(y
, 'abc', 'F - test_up_arrow_scrolls_up_to_empty_line/screen:2')
1401 y
= y
+ Editor_state
.line_height
1402 App
.screen
.check(y
, 'def', 'F - test_up_arrow_scrolls_up_to_empty_line/screen:3')
1405 function test_pageup()
1406 io
.write('\ntest_pageup')
1407 App
.screen
.init
{width
=120, height
=45}
1408 Editor_state
= edit
.initialize_test_state()
1409 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi'}
1410 Text
.redraw_all(Editor_state
)
1411 Editor_state
.cursor1
= {line
=2, pos
=1}
1412 Editor_state
.screen_top1
= {line
=2, pos
=1}
1413 Editor_state
.screen_bottom1
= {}
1414 -- initially the last two lines are displayed
1415 edit
.draw(Editor_state
)
1416 local y
= Editor_state
.top
1417 App
.screen
.check(y
, 'def', 'F - test_pageup/baseline/screen:1')
1418 y
= y
+ Editor_state
.line_height
1419 App
.screen
.check(y
, 'ghi', 'F - test_pageup/baseline/screen:2')
1420 -- after pageup the cursor goes to first line
1421 edit
.run_after_keychord(Editor_state
, 'pageup')
1422 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_pageup/screen_top')
1423 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_pageup/cursor')
1424 y
= Editor_state
.top
1425 App
.screen
.check(y
, 'abc', 'F - test_pageup/screen:1')
1426 y
= y
+ Editor_state
.line_height
1427 App
.screen
.check(y
, 'def', 'F - test_pageup/screen:2')
1430 function test_pageup_scrolls_up_by_screen_line()
1431 io
.write('\ntest_pageup_scrolls_up_by_screen_line')
1432 -- display the first three lines with the cursor on the bottom line
1433 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1434 Editor_state
= edit
.initialize_test_state()
1435 Editor_state
.lines
= load_array
{'abc def', 'ghi', 'jkl', 'mno'}
1436 Text
.redraw_all(Editor_state
)
1437 Editor_state
.cursor1
= {line
=2, pos
=1}
1438 Editor_state
.screen_top1
= {line
=2, pos
=1}
1439 Editor_state
.screen_bottom1
= {}
1440 edit
.draw(Editor_state
)
1441 local y
= Editor_state
.top
1442 App
.screen
.check(y
, 'ghi', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:1')
1443 y
= y
+ Editor_state
.line_height
1444 App
.screen
.check(y
, 'jkl', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:2')
1445 y
= y
+ Editor_state
.line_height
1446 App
.screen
.check(y
, 'mno', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
1447 -- after hitting the page-up key the screen scrolls up to top
1448 edit
.run_after_keychord(Editor_state
, 'pageup')
1449 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_pageup_scrolls_up_by_screen_line/screen_top')
1450 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_pageup_scrolls_up_by_screen_line/cursor:line')
1451 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_pageup_scrolls_up_by_screen_line/cursor:pos')
1452 y
= Editor_state
.top
1453 App
.screen
.check(y
, 'abc ', 'F - test_pageup_scrolls_up_by_screen_line/screen:1')
1454 y
= y
+ Editor_state
.line_height
1455 App
.screen
.check(y
, 'def', 'F - test_pageup_scrolls_up_by_screen_line/screen:2')
1456 y
= y
+ Editor_state
.line_height
1457 App
.screen
.check(y
, 'ghi', 'F - test_pageup_scrolls_up_by_screen_line/screen:3')
1460 function test_pageup_scrolls_up_from_middle_screen_line()
1461 io
.write('\ntest_pageup_scrolls_up_from_middle_screen_line')
1462 -- display a few lines starting from the middle of a line (Editor_state.cursor1.pos > 1)
1463 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1464 Editor_state
= edit
.initialize_test_state()
1465 Editor_state
.lines
= load_array
{'abc def', 'ghi jkl', 'mno'}
1466 Text
.redraw_all(Editor_state
)
1467 Editor_state
.cursor1
= {line
=2, pos
=5}
1468 Editor_state
.screen_top1
= {line
=2, pos
=5}
1469 Editor_state
.screen_bottom1
= {}
1470 edit
.draw(Editor_state
)
1471 local y
= Editor_state
.top
1472 App
.screen
.check(y
, 'jkl', 'F - test_pageup_scrolls_up_from_middle_screen_line/baseline/screen:2')
1473 y
= y
+ Editor_state
.line_height
1474 App
.screen
.check(y
, 'mno', 'F - test_pageup_scrolls_up_from_middle_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
1475 -- after hitting the page-up key the screen scrolls up to top
1476 edit
.run_after_keychord(Editor_state
, 'pageup')
1477 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/screen_top')
1478 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/cursor:line')
1479 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/cursor:pos')
1480 y
= Editor_state
.top
1481 App
.screen
.check(y
, 'abc ', 'F - test_pageup_scrolls_up_from_middle_screen_line/screen:1')
1482 y
= y
+ Editor_state
.line_height
1483 App
.screen
.check(y
, 'def', 'F - test_pageup_scrolls_up_from_middle_screen_line/screen:2')
1484 y
= y
+ Editor_state
.line_height
1485 App
.screen
.check(y
, 'ghi ', 'F - test_pageup_scrolls_up_from_middle_screen_line/screen:3')
1488 function test_enter_on_bottom_line_scrolls_down()
1489 io
.write('\ntest_enter_on_bottom_line_scrolls_down')
1490 -- display a few lines with cursor on bottom line
1491 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1492 Editor_state
= edit
.initialize_test_state()
1493 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1494 Text
.redraw_all(Editor_state
)
1495 Editor_state
.cursor1
= {line
=3, pos
=2}
1496 Editor_state
.screen_top1
= {line
=1, pos
=1}
1497 Editor_state
.screen_bottom1
= {}
1498 edit
.draw(Editor_state
)
1499 local y
= Editor_state
.top
1500 App
.screen
.check(y
, 'abc', 'F - test_enter_on_bottom_line_scrolls_down/baseline/screen:1')
1501 y
= y
+ Editor_state
.line_height
1502 App
.screen
.check(y
, 'def', 'F - test_enter_on_bottom_line_scrolls_down/baseline/screen:2')
1503 y
= y
+ Editor_state
.line_height
1504 App
.screen
.check(y
, 'ghi', 'F - test_enter_on_bottom_line_scrolls_down/baseline/screen:3')
1505 -- after hitting the enter key the screen scrolls down
1506 edit
.run_after_keychord(Editor_state
, 'return')
1507 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_enter_on_bottom_line_scrolls_down/screen_top')
1508 check_eq(Editor_state
.cursor1
.line
, 4, 'F - test_enter_on_bottom_line_scrolls_down/cursor:line')
1509 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_enter_on_bottom_line_scrolls_down/cursor:pos')
1510 y
= Editor_state
.top
1511 App
.screen
.check(y
, 'def', 'F - test_enter_on_bottom_line_scrolls_down/screen:1')
1512 y
= y
+ Editor_state
.line_height
1513 App
.screen
.check(y
, 'g', 'F - test_enter_on_bottom_line_scrolls_down/screen:2')
1514 y
= y
+ Editor_state
.line_height
1515 App
.screen
.check(y
, 'hi', 'F - test_enter_on_bottom_line_scrolls_down/screen:3')
1518 function test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom()
1519 io
.write('\ntest_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom')
1520 -- display just the bottom line on screen
1521 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1522 Editor_state
= edit
.initialize_test_state()
1523 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1524 Text
.redraw_all(Editor_state
)
1525 Editor_state
.cursor1
= {line
=4, pos
=2}
1526 Editor_state
.screen_top1
= {line
=4, pos
=1}
1527 Editor_state
.screen_bottom1
= {}
1528 edit
.draw(Editor_state
)
1529 local y
= Editor_state
.top
1530 App
.screen
.check(y
, 'jkl', 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/baseline/screen:1')
1531 -- after hitting the enter key the screen does not scroll down
1532 edit
.run_after_keychord(Editor_state
, 'return')
1533 check_eq(Editor_state
.screen_top1
.line
, 4, 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top')
1534 check_eq(Editor_state
.cursor1
.line
, 5, 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line')
1535 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos')
1536 y
= Editor_state
.top
1537 App
.screen
.check(y
, 'j', 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen:1')
1538 y
= y
+ Editor_state
.line_height
1539 App
.screen
.check(y
, 'kl', 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen:2')
1542 function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom()
1543 io
.write('\ntest_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom')
1544 -- display just an empty bottom line on screen
1545 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1546 Editor_state
= edit
.initialize_test_state()
1547 Editor_state
.lines
= load_array
{'abc', ''}
1548 Text
.redraw_all(Editor_state
)
1549 Editor_state
.cursor1
= {line
=2, pos
=1}
1550 Editor_state
.screen_top1
= {line
=2, pos
=1}
1551 Editor_state
.screen_bottom1
= {}
1552 edit
.draw(Editor_state
)
1553 -- after hitting the inserting_text key the screen does not scroll down
1554 edit
.run_after_textinput(Editor_state
, 'a')
1555 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top')
1556 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line')
1557 check_eq(Editor_state
.cursor1
.pos
, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos')
1558 local y
= Editor_state
.top
1559 App
.screen
.check(y
, 'a', 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen:1')
1562 function test_typing_on_bottom_line_scrolls_down()
1563 io
.write('\ntest_typing_on_bottom_line_scrolls_down')
1564 -- display a few lines with cursor on bottom line
1565 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1566 Editor_state
= edit
.initialize_test_state()
1567 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1568 Text
.redraw_all(Editor_state
)
1569 Editor_state
.cursor1
= {line
=3, pos
=4}
1570 Editor_state
.screen_top1
= {line
=1, pos
=1}
1571 Editor_state
.screen_bottom1
= {}
1572 edit
.draw(Editor_state
)
1573 local y
= Editor_state
.top
1574 App
.screen
.check(y
, 'abc', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:1')
1575 y
= y
+ Editor_state
.line_height
1576 App
.screen
.check(y
, 'def', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:2')
1577 y
= y
+ Editor_state
.line_height
1578 App
.screen
.check(y
, 'ghi', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:3')
1579 -- after typing something the line wraps and the screen scrolls down
1580 edit
.run_after_textinput(Editor_state
, 'j')
1581 edit
.run_after_textinput(Editor_state
, 'k')
1582 edit
.run_after_textinput(Editor_state
, 'l')
1583 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_typing_on_bottom_line_scrolls_down/screen_top')
1584 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_typing_on_bottom_line_scrolls_down/cursor:line')
1585 check_eq(Editor_state
.cursor1
.pos
, 7, 'F - test_typing_on_bottom_line_scrolls_down/cursor:pos')
1586 y
= Editor_state
.top
1587 App
.screen
.check(y
, 'def', 'F - test_typing_on_bottom_line_scrolls_down/screen:1')
1588 y
= y
+ Editor_state
.line_height
1589 App
.screen
.check(y
, 'ghij', 'F - test_typing_on_bottom_line_scrolls_down/screen:2')
1590 y
= y
+ Editor_state
.line_height
1591 App
.screen
.check(y
, 'kl', 'F - test_typing_on_bottom_line_scrolls_down/screen:3')
1594 function test_left_arrow_scrolls_up_in_wrapped_line()
1595 io
.write('\ntest_left_arrow_scrolls_up_in_wrapped_line')
1596 -- display lines starting from second screen line of a line
1597 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1598 Editor_state
= edit
.initialize_test_state()
1599 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1600 Text
.redraw_all(Editor_state
)
1601 Editor_state
.screen_top1
= {line
=3, pos
=5}
1602 Editor_state
.screen_bottom1
= {}
1603 -- cursor is at top of screen
1604 Editor_state
.cursor1
= {line
=3, pos
=5}
1605 edit
.draw(Editor_state
)
1606 local y
= Editor_state
.top
1607 App
.screen
.check(y
, 'jkl', 'F - test_left_arrow_scrolls_up_in_wrapped_line/baseline/screen:1')
1608 y
= y
+ Editor_state
.line_height
1609 App
.screen
.check(y
, 'mno', 'F - test_left_arrow_scrolls_up_in_wrapped_line/baseline/screen:2')
1610 -- after hitting the left arrow the screen scrolls up to first screen line
1611 edit
.run_after_keychord(Editor_state
, 'left')
1612 y
= Editor_state
.top
1613 App
.screen
.check(y
, 'ghi ', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:1')
1614 y
= y
+ Editor_state
.line_height
1615 App
.screen
.check(y
, 'jkl', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:2')
1616 y
= y
+ Editor_state
.line_height
1617 App
.screen
.check(y
, 'mno', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:3')
1618 check_eq(Editor_state
.screen_top1
.line
, 3, 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen_top')
1619 check_eq(Editor_state
.screen_top1
.pos
, 1, 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen_top')
1620 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_left_arrow_scrolls_up_in_wrapped_line/cursor:line')
1621 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_left_arrow_scrolls_up_in_wrapped_line/cursor:pos')
1624 function test_right_arrow_scrolls_down_in_wrapped_line()
1625 io
.write('\ntest_right_arrow_scrolls_down_in_wrapped_line')
1626 -- display the first three lines with the cursor on the bottom line
1627 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1628 Editor_state
= edit
.initialize_test_state()
1629 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1630 Text
.redraw_all(Editor_state
)
1631 Editor_state
.screen_top1
= {line
=1, pos
=1}
1632 Editor_state
.screen_bottom1
= {}
1633 -- cursor is at bottom right of screen
1634 Editor_state
.cursor1
= {line
=3, pos
=5}
1635 edit
.draw(Editor_state
)
1636 local y
= Editor_state
.top
1637 App
.screen
.check(y
, 'abc', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:1')
1638 y
= y
+ Editor_state
.line_height
1639 App
.screen
.check(y
, 'def', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:2')
1640 y
= y
+ Editor_state
.line_height
1641 App
.screen
.check(y
, 'ghi ', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:3') -- line wrapping includes trailing whitespace
1642 -- after hitting the right arrow the screen scrolls down by one line
1643 edit
.run_after_keychord(Editor_state
, 'right')
1644 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen_top')
1645 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_right_arrow_scrolls_down_in_wrapped_line/cursor:line')
1646 check_eq(Editor_state
.cursor1
.pos
, 6, 'F - test_right_arrow_scrolls_down_in_wrapped_line/cursor:pos')
1647 y
= Editor_state
.top
1648 App
.screen
.check(y
, 'def', 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen:1')
1649 y
= y
+ Editor_state
.line_height
1650 App
.screen
.check(y
, 'ghi ', 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen:2')
1651 y
= y
+ Editor_state
.line_height
1652 App
.screen
.check(y
, 'jkl', 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen:3')
1655 function test_home_scrolls_up_in_wrapped_line()
1656 io
.write('\ntest_home_scrolls_up_in_wrapped_line')
1657 -- display lines starting from second screen line of a line
1658 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1659 Editor_state
= edit
.initialize_test_state()
1660 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1661 Text
.redraw_all(Editor_state
)
1662 Editor_state
.screen_top1
= {line
=3, pos
=5}
1663 Editor_state
.screen_bottom1
= {}
1664 -- cursor is at top of screen
1665 Editor_state
.cursor1
= {line
=3, pos
=5}
1666 edit
.draw(Editor_state
)
1667 local y
= Editor_state
.top
1668 App
.screen
.check(y
, 'jkl', 'F - test_home_scrolls_up_in_wrapped_line/baseline/screen:1')
1669 y
= y
+ Editor_state
.line_height
1670 App
.screen
.check(y
, 'mno', 'F - test_home_scrolls_up_in_wrapped_line/baseline/screen:2')
1671 -- after hitting home the screen scrolls up to first screen line
1672 edit
.run_after_keychord(Editor_state
, 'home')
1673 y
= Editor_state
.top
1674 App
.screen
.check(y
, 'ghi ', 'F - test_home_scrolls_up_in_wrapped_line/screen:1')
1675 y
= y
+ Editor_state
.line_height
1676 App
.screen
.check(y
, 'jkl', 'F - test_home_scrolls_up_in_wrapped_line/screen:2')
1677 y
= y
+ Editor_state
.line_height
1678 App
.screen
.check(y
, 'mno', 'F - test_home_scrolls_up_in_wrapped_line/screen:3')
1679 check_eq(Editor_state
.screen_top1
.line
, 3, 'F - test_home_scrolls_up_in_wrapped_line/screen_top')
1680 check_eq(Editor_state
.screen_top1
.pos
, 1, 'F - test_home_scrolls_up_in_wrapped_line/screen_top')
1681 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_home_scrolls_up_in_wrapped_line/cursor:line')
1682 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_home_scrolls_up_in_wrapped_line/cursor:pos')
1685 function test_end_scrolls_down_in_wrapped_line()
1686 io
.write('\ntest_end_scrolls_down_in_wrapped_line')
1687 -- display the first three lines with the cursor on the bottom line
1688 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1689 Editor_state
= edit
.initialize_test_state()
1690 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1691 Text
.redraw_all(Editor_state
)
1692 Editor_state
.screen_top1
= {line
=1, pos
=1}
1693 Editor_state
.screen_bottom1
= {}
1694 -- cursor is at bottom right of screen
1695 Editor_state
.cursor1
= {line
=3, pos
=5}
1696 edit
.draw(Editor_state
)
1697 local y
= Editor_state
.top
1698 App
.screen
.check(y
, 'abc', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:1')
1699 y
= y
+ Editor_state
.line_height
1700 App
.screen
.check(y
, 'def', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:2')
1701 y
= y
+ Editor_state
.line_height
1702 App
.screen
.check(y
, 'ghi ', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:3') -- line wrapping includes trailing whitespace
1703 -- after hitting end the screen scrolls down by one line
1704 edit
.run_after_keychord(Editor_state
, 'end')
1705 check_eq(Editor_state
.screen_top1
.line
, 2, 'F - test_end_scrolls_down_in_wrapped_line/screen_top')
1706 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_end_scrolls_down_in_wrapped_line/cursor:line')
1707 check_eq(Editor_state
.cursor1
.pos
, 8, 'F - test_end_scrolls_down_in_wrapped_line/cursor:pos')
1708 y
= Editor_state
.top
1709 App
.screen
.check(y
, 'def', 'F - test_end_scrolls_down_in_wrapped_line/screen:1')
1710 y
= y
+ Editor_state
.line_height
1711 App
.screen
.check(y
, 'ghi ', 'F - test_end_scrolls_down_in_wrapped_line/screen:2')
1712 y
= y
+ Editor_state
.line_height
1713 App
.screen
.check(y
, 'jkl', 'F - test_end_scrolls_down_in_wrapped_line/screen:3')
1716 function test_position_cursor_on_recently_edited_wrapping_line()
1717 -- draw a line wrapping over 2 screen lines
1718 io
.write('\ntest_position_cursor_on_recently_edited_wrapping_line')
1719 App
.screen
.init
{width
=100, height
=200}
1720 Editor_state
= edit
.initialize_test_state()
1721 Editor_state
.lines
= load_array
{'abc def ghi jkl mno pqr ', 'xyz'}
1722 Text
.redraw_all(Editor_state
)
1723 Editor_state
.cursor1
= {line
=1, pos
=25}
1724 Editor_state
.screen_top1
= {line
=1, pos
=1}
1725 Editor_state
.screen_bottom1
= {}
1726 edit
.draw(Editor_state
)
1727 local y
= Editor_state
.top
1728 App
.screen
.check(y
, 'abc def ghi ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:1')
1729 y
= y
+ Editor_state
.line_height
1730 App
.screen
.check(y
, 'jkl mno pqr ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:2')
1731 y
= y
+ Editor_state
.line_height
1732 App
.screen
.check(y
, 'xyz', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:3')
1733 -- add to the line until it's wrapping over 3 screen lines
1734 edit
.run_after_textinput(Editor_state
, 's')
1735 edit
.run_after_textinput(Editor_state
, 't')
1736 edit
.run_after_textinput(Editor_state
, 'u')
1737 check_eq(Editor_state
.cursor1
.pos
, 28, 'F - test_position_cursor_on_recently_edited_wrapping_line/cursor:pos')
1738 y
= Editor_state
.top
1739 App
.screen
.check(y
, 'abc def ghi ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:1')
1740 y
= y
+ Editor_state
.line_height
1741 App
.screen
.check(y
, 'jkl mno pqr ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:2')
1742 y
= y
+ Editor_state
.line_height
1743 App
.screen
.check(y
, 'stu', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:3')
1744 -- try to move the cursor earlier in the third screen line by clicking the mouse
1745 edit
.run_after_mouse_release(Editor_state
, Editor_state
.left
+8,Editor_state
.top
+Editor_state
.line_height
*2+5, 1)
1746 -- cursor should move
1747 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_position_cursor_on_recently_edited_wrapping_line/cursor:line')
1748 check_eq(Editor_state
.cursor1
.pos
, 26, 'F - test_position_cursor_on_recently_edited_wrapping_line/cursor:pos')
1751 function test_backspace_can_scroll_up()
1752 io
.write('\ntest_backspace_can_scroll_up')
1753 -- display the lines 2/3/4 with the cursor on line 2
1754 App
.screen
.init
{width
=120, height
=60}
1755 Editor_state
= edit
.initialize_test_state()
1756 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl'}
1757 Text
.redraw_all(Editor_state
)
1758 Editor_state
.cursor1
= {line
=2, pos
=1}
1759 Editor_state
.screen_top1
= {line
=2, pos
=1}
1760 Editor_state
.screen_bottom1
= {}
1761 edit
.draw(Editor_state
)
1762 local y
= Editor_state
.top
1763 App
.screen
.check(y
, 'def', 'F - test_backspace_can_scroll_up/baseline/screen:1')
1764 y
= y
+ Editor_state
.line_height
1765 App
.screen
.check(y
, 'ghi', 'F - test_backspace_can_scroll_up/baseline/screen:2')
1766 y
= y
+ Editor_state
.line_height
1767 App
.screen
.check(y
, 'jkl', 'F - test_backspace_can_scroll_up/baseline/screen:3')
1768 -- after hitting backspace the screen scrolls up by one line
1769 edit
.run_after_keychord(Editor_state
, 'backspace')
1770 check_eq(Editor_state
.screen_top1
.line
, 1, 'F - test_backspace_can_scroll_up/screen_top')
1771 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_backspace_can_scroll_up/cursor')
1772 y
= Editor_state
.top
1773 App
.screen
.check(y
, 'abcdef', 'F - test_backspace_can_scroll_up/screen:1')
1774 y
= y
+ Editor_state
.line_height
1775 App
.screen
.check(y
, 'ghi', 'F - test_backspace_can_scroll_up/screen:2')
1776 y
= y
+ Editor_state
.line_height
1777 App
.screen
.check(y
, 'jkl', 'F - test_backspace_can_scroll_up/screen:3')
1780 function test_backspace_can_scroll_up_screen_line()
1781 io
.write('\ntest_backspace_can_scroll_up_screen_line')
1782 -- display lines starting from second screen line of a line
1783 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1784 Editor_state
= edit
.initialize_test_state()
1785 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi jkl', 'mno'}
1786 Text
.redraw_all(Editor_state
)
1787 Editor_state
.cursor1
= {line
=3, pos
=5}
1788 Editor_state
.screen_top1
= {line
=3, pos
=5}
1789 Editor_state
.screen_bottom1
= {}
1790 edit
.draw(Editor_state
)
1791 local y
= Editor_state
.top
1792 App
.screen
.check(y
, 'jkl', 'F - test_backspace_can_scroll_up_screen_line/baseline/screen:1')
1793 y
= y
+ Editor_state
.line_height
1794 App
.screen
.check(y
, 'mno', 'F - test_backspace_can_scroll_up_screen_line/baseline/screen:2')
1795 -- after hitting backspace the screen scrolls up by one screen line
1796 edit
.run_after_keychord(Editor_state
, 'backspace')
1797 y
= Editor_state
.top
1798 App
.screen
.check(y
, 'ghij', 'F - test_backspace_can_scroll_up_screen_line/screen:1')
1799 y
= y
+ Editor_state
.line_height
1800 App
.screen
.check(y
, 'kl', 'F - test_backspace_can_scroll_up_screen_line/screen:2')
1801 y
= y
+ Editor_state
.line_height
1802 App
.screen
.check(y
, 'mno', 'F - test_backspace_can_scroll_up_screen_line/screen:3')
1803 check_eq(Editor_state
.screen_top1
.line
, 3, 'F - test_backspace_can_scroll_up_screen_line/screen_top')
1804 check_eq(Editor_state
.screen_top1
.pos
, 1, 'F - test_backspace_can_scroll_up_screen_line/screen_top')
1805 check_eq(Editor_state
.cursor1
.line
, 3, 'F - test_backspace_can_scroll_up_screen_line/cursor:line')
1806 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_backspace_can_scroll_up_screen_line/cursor:pos')
1809 function test_backspace_past_line_boundary()
1810 io
.write('\ntest_backspace_past_line_boundary')
1811 -- position cursor at start of a (non-first) line
1812 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1813 Editor_state
= edit
.initialize_test_state()
1814 Editor_state
.lines
= load_array
{'abc', 'def'}
1815 Text
.redraw_all(Editor_state
)
1816 Editor_state
.cursor1
= {line
=2, pos
=1}
1817 -- backspace joins with previous line
1818 edit
.run_after_keychord(Editor_state
, 'backspace')
1819 check_eq(Editor_state
.lines
[1].data
, 'abcdef', "F - test_backspace_past_line_boundary")
1822 -- some tests for operating over selections created using Shift- chords
1823 -- we're just testing delete_selection, and it works the same for all keys
1825 function test_backspace_over_selection()
1826 io
.write('\ntest_backspace_over_selection')
1827 -- select just one character within a line with cursor before selection
1828 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1829 Editor_state
= edit
.initialize_test_state()
1830 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1831 Text
.redraw_all(Editor_state
)
1832 Editor_state
.cursor1
= {line
=1, pos
=1}
1833 Editor_state
.selection1
= {line
=1, pos
=2}
1834 -- backspace deletes the selected character, even though it's after the cursor
1835 edit
.run_after_keychord(Editor_state
, 'backspace')
1836 check_eq(Editor_state
.lines
[1].data
, 'bc', "F - test_backspace_over_selection/data")
1837 -- cursor (remains) at start of selection
1838 check_eq(Editor_state
.cursor1
.line
, 1, "F - test_backspace_over_selection/cursor:line")
1839 check_eq(Editor_state
.cursor1
.pos
, 1, "F - test_backspace_over_selection/cursor:pos")
1840 -- selection is cleared
1841 check_nil(Editor_state
.selection1
.line
, "F - test_backspace_over_selection/selection")
1844 function test_backspace_over_selection_reverse()
1845 io
.write('\ntest_backspace_over_selection_reverse')
1846 -- select just one character within a line with cursor after selection
1847 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1848 Editor_state
= edit
.initialize_test_state()
1849 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1850 Text
.redraw_all(Editor_state
)
1851 Editor_state
.cursor1
= {line
=1, pos
=2}
1852 Editor_state
.selection1
= {line
=1, pos
=1}
1853 -- backspace deletes the selected character
1854 edit
.run_after_keychord(Editor_state
, 'backspace')
1855 check_eq(Editor_state
.lines
[1].data
, 'bc', "F - test_backspace_over_selection_reverse/data")
1856 -- cursor moves to start of selection
1857 check_eq(Editor_state
.cursor1
.line
, 1, "F - test_backspace_over_selection_reverse/cursor:line")
1858 check_eq(Editor_state
.cursor1
.pos
, 1, "F - test_backspace_over_selection_reverse/cursor:pos")
1859 -- selection is cleared
1860 check_nil(Editor_state
.selection1
.line
, "F - test_backspace_over_selection_reverse/selection")
1863 function test_backspace_over_multiple_lines()
1864 io
.write('\ntest_backspace_over_multiple_lines')
1865 -- select just one character within a line with cursor after selection
1866 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1867 Editor_state
= edit
.initialize_test_state()
1868 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1869 Text
.redraw_all(Editor_state
)
1870 Editor_state
.cursor1
= {line
=1, pos
=2}
1871 Editor_state
.selection1
= {line
=4, pos
=2}
1872 -- backspace deletes the region and joins the remaining portions of lines on either side
1873 edit
.run_after_keychord(Editor_state
, 'backspace')
1874 check_eq(Editor_state
.lines
[1].data
, 'akl', "F - test_backspace_over_multiple_lines/data:1")
1875 check_eq(Editor_state
.lines
[2].data
, 'mno', "F - test_backspace_over_multiple_lines/data:2")
1876 -- cursor remains at start of selection
1877 check_eq(Editor_state
.cursor1
.line
, 1, "F - test_backspace_over_multiple_lines/cursor:line")
1878 check_eq(Editor_state
.cursor1
.pos
, 2, "F - test_backspace_over_multiple_lines/cursor:pos")
1879 -- selection is cleared
1880 check_nil(Editor_state
.selection1
.line
, "F - test_backspace_over_multiple_lines/selection")
1883 function test_backspace_to_end_of_line()
1884 io
.write('\ntest_backspace_to_end_of_line')
1885 -- select region from cursor to end of line
1886 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1887 Editor_state
= edit
.initialize_test_state()
1888 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1889 Text
.redraw_all(Editor_state
)
1890 Editor_state
.cursor1
= {line
=1, pos
=2}
1891 Editor_state
.selection1
= {line
=1, pos
=4}
1892 -- backspace deletes rest of line without joining to any other line
1893 edit
.run_after_keychord(Editor_state
, 'backspace')
1894 check_eq(Editor_state
.lines
[1].data
, 'a', "F - test_backspace_to_start_of_line/data:1")
1895 check_eq(Editor_state
.lines
[2].data
, 'def', "F - test_backspace_to_start_of_line/data:2")
1896 -- cursor remains at start of selection
1897 check_eq(Editor_state
.cursor1
.line
, 1, "F - test_backspace_to_start_of_line/cursor:line")
1898 check_eq(Editor_state
.cursor1
.pos
, 2, "F - test_backspace_to_start_of_line/cursor:pos")
1899 -- selection is cleared
1900 check_nil(Editor_state
.selection1
.line
, "F - test_backspace_to_start_of_line/selection")
1903 function test_backspace_to_start_of_line()
1904 io
.write('\ntest_backspace_to_start_of_line')
1905 -- select region from cursor to start of line
1906 App
.screen
.init
{width
=Editor_state
.left
+30, height
=60}
1907 Editor_state
= edit
.initialize_test_state()
1908 Editor_state
.lines
= load_array
{'abc', 'def', 'ghi', 'jkl', 'mno'}
1909 Text
.redraw_all(Editor_state
)
1910 Editor_state
.cursor1
= {line
=2, pos
=1}
1911 Editor_state
.selection1
= {line
=2, pos
=3}
1912 -- backspace deletes beginning of line without joining to any other line
1913 edit
.run_after_keychord(Editor_state
, 'backspace')
1914 check_eq(Editor_state
.lines
[1].data
, 'abc', "F - test_backspace_to_start_of_line/data:1")
1915 check_eq(Editor_state
.lines
[2].data
, 'f', "F - test_backspace_to_start_of_line/data:2")
1916 -- cursor remains at start of selection
1917 check_eq(Editor_state
.cursor1
.line
, 2, "F - test_backspace_to_start_of_line/cursor:line")
1918 check_eq(Editor_state
.cursor1
.pos
, 1, "F - test_backspace_to_start_of_line/cursor:pos")
1919 -- selection is cleared
1920 check_nil(Editor_state
.selection1
.line
, "F - test_backspace_to_start_of_line/selection")
1923 function test_undo_insert_text()
1924 io
.write('\ntest_undo_insert_text')
1925 App
.screen
.init
{width
=120, height
=60}
1926 Editor_state
= edit
.initialize_test_state()
1927 Editor_state
.lines
= load_array
{'abc', 'def', 'xyz'}
1928 Text
.redraw_all(Editor_state
)
1929 Editor_state
.cursor1
= {line
=2, pos
=4}
1930 Editor_state
.screen_top1
= {line
=1, pos
=1}
1931 Editor_state
.screen_bottom1
= {}
1932 -- insert a character
1933 edit
.draw(Editor_state
)
1934 edit
.run_after_textinput(Editor_state
, 'g')
1935 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_undo_insert_text/baseline/cursor:line')
1936 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_undo_insert_text/baseline/cursor:pos')
1937 check_nil(Editor_state
.selection1
.line
, 'F - test_undo_insert_text/baseline/selection:line')
1938 check_nil(Editor_state
.selection1
.pos
, 'F - test_undo_insert_text/baseline/selection:pos')
1939 local y
= Editor_state
.top
1940 App
.screen
.check(y
, 'abc', 'F - test_undo_insert_text/baseline/screen:1')
1941 y
= y
+ Editor_state
.line_height
1942 App
.screen
.check(y
, 'defg', 'F - test_undo_insert_text/baseline/screen:2')
1943 y
= y
+ Editor_state
.line_height
1944 App
.screen
.check(y
, 'xyz', 'F - test_undo_insert_text/baseline/screen:3')
1946 edit
.run_after_keychord(Editor_state
, 'C-z')
1947 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_undo_insert_text/cursor:line')
1948 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_undo_insert_text/cursor:pos')
1949 check_nil(Editor_state
.selection1
.line
, 'F - test_undo_insert_text/selection:line')
1950 check_nil(Editor_state
.selection1
.pos
, 'F - test_undo_insert_text/selection:pos')
1951 y
= Editor_state
.top
1952 App
.screen
.check(y
, 'abc', 'F - test_undo_insert_text/screen:1')
1953 y
= y
+ Editor_state
.line_height
1954 App
.screen
.check(y
, 'def', 'F - test_undo_insert_text/screen:2')
1955 y
= y
+ Editor_state
.line_height
1956 App
.screen
.check(y
, 'xyz', 'F - test_undo_insert_text/screen:3')
1959 function test_undo_delete_text()
1960 io
.write('\ntest_undo_delete_text')
1961 App
.screen
.init
{width
=120, height
=60}
1962 Editor_state
= edit
.initialize_test_state()
1963 Editor_state
.lines
= load_array
{'abc', 'defg', 'xyz'}
1964 Text
.redraw_all(Editor_state
)
1965 Editor_state
.cursor1
= {line
=2, pos
=5}
1966 Editor_state
.screen_top1
= {line
=1, pos
=1}
1967 Editor_state
.screen_bottom1
= {}
1968 -- delete a character
1969 edit
.run_after_keychord(Editor_state
, 'backspace')
1970 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_undo_delete_text/baseline/cursor:line')
1971 check_eq(Editor_state
.cursor1
.pos
, 4, 'F - test_undo_delete_text/baseline/cursor:pos')
1972 check_nil(Editor_state
.selection1
.line
, 'F - test_undo_delete_text/baseline/selection:line')
1973 check_nil(Editor_state
.selection1
.pos
, 'F - test_undo_delete_text/baseline/selection:pos')
1974 local y
= Editor_state
.top
1975 App
.screen
.check(y
, 'abc', 'F - test_undo_delete_text/baseline/screen:1')
1976 y
= y
+ Editor_state
.line_height
1977 App
.screen
.check(y
, 'def', 'F - test_undo_delete_text/baseline/screen:2')
1978 y
= y
+ Editor_state
.line_height
1979 App
.screen
.check(y
, 'xyz', 'F - test_undo_delete_text/baseline/screen:3')
1981 --? -- after undo, the backspaced key is selected
1982 edit
.run_after_keychord(Editor_state
, 'C-z')
1983 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_undo_delete_text/cursor:line')
1984 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_undo_delete_text/cursor:pos')
1985 check_nil(Editor_state
.selection1
.line
, 'F - test_undo_delete_text/selection:line')
1986 check_nil(Editor_state
.selection1
.pos
, 'F - test_undo_delete_text/selection:pos')
1987 --? check_eq(Editor_state.selection1.line, 2, 'F - test_undo_delete_text/selection:line')
1988 --? check_eq(Editor_state.selection1.pos, 4, 'F - test_undo_delete_text/selection:pos')
1989 y
= Editor_state
.top
1990 App
.screen
.check(y
, 'abc', 'F - test_undo_delete_text/screen:1')
1991 y
= y
+ Editor_state
.line_height
1992 App
.screen
.check(y
, 'defg', 'F - test_undo_delete_text/screen:2')
1993 y
= y
+ Editor_state
.line_height
1994 App
.screen
.check(y
, 'xyz', 'F - test_undo_delete_text/screen:3')
1997 function test_undo_restores_selection()
1998 io
.write('\ntest_undo_restores_selection')
1999 -- display a line of text with some part selected
2000 App
.screen
.init
{width
=75, height
=80}
2001 Editor_state
= edit
.initialize_test_state()
2002 Editor_state
.lines
= load_array
{'abc'}
2003 Text
.redraw_all(Editor_state
)
2004 Editor_state
.cursor1
= {line
=1, pos
=1}
2005 Editor_state
.selection1
= {line
=1, pos
=2}
2006 Editor_state
.screen_top1
= {line
=1, pos
=1}
2007 Editor_state
.screen_bottom1
= {}
2008 edit
.draw(Editor_state
)
2009 -- delete selected text
2010 edit
.run_after_textinput(Editor_state
, 'x')
2011 check_eq(Editor_state
.lines
[1].data
, 'xbc', 'F - test_undo_restores_selection/baseline')
2012 check_nil(Editor_state
.selection1
.line
, 'F - test_undo_restores_selection/baseline:selection')
2014 edit
.run_after_keychord(Editor_state
, 'C-z')
2015 edit
.run_after_keychord(Editor_state
, 'C-z')
2016 -- selection is restored
2017 check_eq(Editor_state
.selection1
.line
, 1, 'F - test_undo_restores_selection/line')
2018 check_eq(Editor_state
.selection1
.pos
, 2, 'F - test_undo_restores_selection/pos')
2021 function test_search()
2022 io
.write('\ntest_search')
2023 App
.screen
.init
{width
=120, height
=60}
2024 Editor_state
= edit
.initialize_test_state()
2025 Editor_state
.lines
= load_array
{'```lines', '```', 'def', 'ghi', 'deg'}
2026 Text
.redraw_all(Editor_state
)
2027 Editor_state
.cursor1
= {line
=1, pos
=1}
2028 Editor_state
.screen_top1
= {line
=1, pos
=1}
2029 Editor_state
.screen_bottom1
= {}
2030 edit
.draw(Editor_state
)
2031 -- search for a string
2032 edit
.run_after_keychord(Editor_state
, 'C-f')
2033 edit
.run_after_textinput(Editor_state
, 'd')
2034 edit
.run_after_keychord(Editor_state
, 'return')
2035 check_eq(Editor_state
.cursor1
.line
, 2, 'F - test_search/1/cursor:line')
2036 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_search/1/cursor:pos')
2038 Editor_state
.cursor1
= {line
=1, pos
=1}
2039 Editor_state
.screen_top1
= {line
=1, pos
=1}
2040 -- search for second occurrence
2041 edit
.run_after_keychord(Editor_state
, 'C-f')
2042 edit
.run_after_textinput(Editor_state
, 'de')
2043 edit
.run_after_keychord(Editor_state
, 'down')
2044 edit
.run_after_keychord(Editor_state
, 'return')
2045 check_eq(Editor_state
.cursor1
.line
, 4, 'F - test_search/2/cursor:line')
2046 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_search/2/cursor:pos')
2049 function test_search_upwards()
2050 io
.write('\ntest_search_upwards')
2051 App
.screen
.init
{width
=120, height
=60}
2052 Editor_state
= edit
.initialize_test_state()
2053 Editor_state
.lines
= load_array
{'abc abd'}
2054 Text
.redraw_all(Editor_state
)
2055 Editor_state
.cursor1
= {line
=1, pos
=2}
2056 Editor_state
.screen_top1
= {line
=1, pos
=1}
2057 Editor_state
.screen_bottom1
= {}
2058 edit
.draw(Editor_state
)
2059 -- search for a string
2060 edit
.run_after_keychord(Editor_state
, 'C-f')
2061 edit
.run_after_textinput(Editor_state
, 'a')
2062 -- search for previous occurrence
2063 edit
.run_after_keychord(Editor_state
, 'up')
2064 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_search_upwards/2/cursor:line')
2065 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_search_upwards/2/cursor:pos')
2068 function test_search_wrap()
2069 io
.write('\ntest_search_wrap')
2070 App
.screen
.init
{width
=120, height
=60}
2071 Editor_state
= edit
.initialize_test_state()
2072 Editor_state
.lines
= load_array
{'abc'}
2073 Text
.redraw_all(Editor_state
)
2074 Editor_state
.cursor1
= {line
=1, pos
=3}
2075 Editor_state
.screen_top1
= {line
=1, pos
=1}
2076 Editor_state
.screen_bottom1
= {}
2077 edit
.draw(Editor_state
)
2078 -- search for a string
2079 edit
.run_after_keychord(Editor_state
, 'C-f')
2080 edit
.run_after_textinput(Editor_state
, 'a')
2081 edit
.run_after_keychord(Editor_state
, 'return')
2083 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_search_wrap/1/cursor:line')
2084 check_eq(Editor_state
.cursor1
.pos
, 1, 'F - test_search_wrap/1/cursor:pos')
2087 function test_search_wrap_upwards()
2088 io
.write('\ntest_search_wrap_upwards')
2089 App
.screen
.init
{width
=120, height
=60}
2090 Editor_state
= edit
.initialize_test_state()
2091 Editor_state
.lines
= load_array
{'abc abd'}
2092 Text
.redraw_all(Editor_state
)
2093 Editor_state
.cursor1
= {line
=1, pos
=1}
2094 Editor_state
.screen_top1
= {line
=1, pos
=1}
2095 Editor_state
.screen_bottom1
= {}
2096 edit
.draw(Editor_state
)
2097 -- search upwards for a string
2098 edit
.run_after_keychord(Editor_state
, 'C-f')
2099 edit
.run_after_textinput(Editor_state
, 'a')
2100 edit
.run_after_keychord(Editor_state
, 'up')
2102 check_eq(Editor_state
.cursor1
.line
, 1, 'F - test_search_wrap_upwards/1/cursor:line')
2103 check_eq(Editor_state
.cursor1
.pos
, 5, 'F - test_search_wrap_upwards/1/cursor:pos')