call edit rather than App callbacks in tests

This commit is contained in:
Kartik K. Agaram 2022-07-12 15:39:11 -07:00
parent 81ecca89ff
commit 92ad99853e
3 changed files with 231 additions and 188 deletions

View File

@ -9,7 +9,7 @@ function test_creating_drawing_saves()
Editor_state.lines = load_array{}
edit.draw(Editor_state)
-- click on button to create drawing
App.run_after_mouse_click(8,Editor_state.margin_top+8, 1)
edit.run_after_mouse_click(Editor_state, 8,Editor_state.margin_top+8, 1)
-- file not immediately saved
App.update(0.01)
check_nil(App.filesystem['foo'], 'F - test_creating_drawing_saves/early')
@ -34,8 +34,8 @@ function test_draw_line()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_line/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes')
-- draw a line
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_line/#shapes')
check_eq(#drawing.points, 2, 'F - test_draw_line/#points')
@ -77,8 +77,8 @@ function test_draw_horizontal_line()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_horizontal_line/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_horizontal_line/baseline/#shapes')
-- draw a line that is more horizontal than vertical
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_horizontal_line/#shapes')
check_eq(#drawing.points, 2, 'F - test_draw_horizontal_line/#points')
@ -105,9 +105,9 @@ function test_draw_circle()
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_circle/baseline/#shapes')
-- draw a circle
App.mouse_move(Editor_state.margin_left+4, Editor_state.margin_top+Editor_state.drawing_padding_top+4) -- hover on drawing
App.run_after_keychord('C-o')
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_release(Editor_state.margin_left+35+30, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 'C-o')
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35+30, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_circle/#shapes')
check_eq(#drawing.points, 1, 'F - test_draw_circle/#points')
@ -132,10 +132,10 @@ function test_cancel_stroke()
check_eq(Editor_state.lines[1].h, 128, 'F - test_cancel_stroke/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_cancel_stroke/baseline/#shapes')
-- start drawing a line
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
-- cancel
App.run_after_keychord('escape')
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 'escape')
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 0, 'F - test_cancel_stroke/#shapes')
end
@ -149,7 +149,7 @@ function test_keys_do_not_affect_shape_when_mouse_up()
edit.draw(Editor_state)
-- hover over drawing and press 'o' without holding mouse
App.mouse_move(Editor_state.margin_left+4, Editor_state.margin_top+Editor_state.drawing_padding_top+4) -- hover on drawing
App.run_after_keychord('o')
edit.run_after_keychord(Editor_state, 'o')
-- no change to drawing mode
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode')
-- no change to text either because we didn't run the textinput event
@ -169,9 +169,9 @@ function test_draw_circle_mid_stroke()
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_circle_mid_stroke/baseline/#shapes')
-- draw a circle
App.mouse_move(Editor_state.margin_left+4, Editor_state.margin_top+Editor_state.drawing_padding_top+4) -- hover on drawing
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_keychord('o')
App.run_after_mouse_release(Editor_state.margin_left+35+30, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 'o')
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35+30, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_circle_mid_stroke/#shapes')
check_eq(#drawing.points, 1, 'F - test_draw_circle_mid_stroke/#points')
@ -195,10 +195,10 @@ function test_draw_arc()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_arc/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_arc/baseline/#shapes')
-- draw an arc
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.mouse_move(Editor_state.margin_left+35+30, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('a') -- arc mode
App.run_after_mouse_release(Editor_state.margin_left+35+50, Editor_state.margin_top+Editor_state.drawing_padding_top+36+50, 1) -- 45°
edit.run_after_keychord(Editor_state, 'a') -- arc mode
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35+50, Editor_state.margin_top+Editor_state.drawing_padding_top+36+50, 1) -- 45°
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_arc/#shapes')
check_eq(#drawing.points, 1, 'F - test_draw_arc/#points')
@ -225,13 +225,13 @@ function test_draw_polygon()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_polygon/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')
-- first point
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_keychord('g') -- polygon mode
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_keychord(Editor_state, 'g') -- polygon mode
-- second point
App.mouse_move(Editor_state.margin_left+65, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('p') -- add point
edit.run_after_keychord(Editor_state, 'p') -- add point
-- final point
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_polygon/#shapes')
check_eq(#drawing.points, 3, 'F - test_draw_polygon/vertices')
@ -262,16 +262,16 @@ function test_draw_rectangle()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_rectangle/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle/baseline/#shapes')
-- first point
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_keychord('r') -- rectangle mode
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 'r') -- rectangle mode
-- second point/first edge
App.mouse_move(Editor_state.margin_left+42, Editor_state.margin_top+Editor_state.drawing_padding_top+45)
App.run_after_keychord('p')
edit.run_after_keychord(Editor_state, 'p')
-- override second point/first edge
App.mouse_move(Editor_state.margin_left+75, Editor_state.margin_top+Editor_state.drawing_padding_top+76)
App.run_after_keychord('p')
edit.run_after_keychord(Editor_state, 'p')
-- release (decides 'thickness' of rectangle perpendicular to first edge)
App.run_after_mouse_release(Editor_state.margin_left+15, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+15, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_rectangle/#shapes')
check_eq(#drawing.points, 5, 'F - test_draw_rectangle/#points') -- currently includes every point added
@ -305,14 +305,14 @@ function test_draw_rectangle_intermediate()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_rectangle_intermediate/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_rectangle_intermediate/baseline/#shapes')
-- first point
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_keychord('r') -- rectangle mode
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 'r') -- rectangle mode
-- second point/first edge
App.mouse_move(Editor_state.margin_left+42, Editor_state.margin_top+Editor_state.drawing_padding_top+45)
App.run_after_keychord('p')
edit.run_after_keychord(Editor_state, 'p')
-- override second point/first edge
App.mouse_move(Editor_state.margin_left+75, Editor_state.margin_top+Editor_state.drawing_padding_top+76)
App.run_after_keychord('p')
edit.run_after_keychord(Editor_state, 'p')
local drawing = Editor_state.lines[1]
check_eq(#drawing.points, 3, 'F - test_draw_rectangle_intermediate/#points') -- currently includes every point added
local pending = drawing.pending
@ -340,16 +340,16 @@ function test_draw_square()
check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_square/baseline/y')
check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes')
-- first point
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_keychord('s') -- square mode
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_keychord(Editor_state, 's') -- square mode
-- second point/first edge
App.mouse_move(Editor_state.margin_left+42, Editor_state.margin_top+Editor_state.drawing_padding_top+45)
App.run_after_keychord('p')
edit.run_after_keychord(Editor_state, 'p')
-- override second point/first edge
App.mouse_move(Editor_state.margin_left+65, Editor_state.margin_top+Editor_state.drawing_padding_top+66)
App.run_after_keychord('p')
edit.run_after_keychord(Editor_state, 'p')
-- release (decides which side of first edge to draw square on)
App.run_after_mouse_release(Editor_state.margin_left+15, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+15, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_square/#shapes')
check_eq(#drawing.points, 5, 'F - test_draw_square/#points') -- currently includes every point added
@ -378,8 +378,8 @@ function test_name_point()
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
-- draw a line
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_name_point/baseline/#shapes')
check_eq(#drawing.points, 2, 'F - test_name_point/baseline/#points')
@ -392,14 +392,14 @@ function test_name_point()
check_eq(p2.y, 36, 'F - test_name_point/baseline/p2:y')
check_nil(p2.name, 'F - test_name_point/baseline/p2:name')
-- enter 'name' mode without moving the mouse
App.run_after_keychord('C-n')
edit.run_after_keychord(Editor_state, 'C-n')
check_eq(Editor_state.current_drawing_mode, 'name', 'F - test_name_point/mode:1')
App.run_after_textinput('A')
edit.run_after_textinput(Editor_state, 'A')
check_eq(p2.name, 'A', 'F - test_name_point')
-- still in 'name' mode
check_eq(Editor_state.current_drawing_mode, 'name', 'F - test_name_point/mode:2')
-- exit 'name' mode
App.run_after_keychord('return')
edit.run_after_keychord(Editor_state, 'return')
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_name_point/mode:3')
check_eq(p2.name, 'A', 'F - test_name_point')
-- wait until save
@ -419,8 +419,8 @@ function test_move_point()
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_move_point/baseline/#shapes')
check_eq(#drawing.points, 2, 'F - test_move_point/baseline/#points')
@ -442,7 +442,7 @@ function test_move_point()
check_eq(p2.y, 36, 'F - test_move_point/save/y')
edit.draw(Editor_state)
-- enter 'move' mode without moving the mouse
App.run_after_keychord('C-u')
edit.run_after_keychord(Editor_state, 'C-u')
check_eq(Editor_state.current_drawing_mode, 'move', 'F - test_move_point/mode:1')
-- point is lifted
check_eq(drawing.pending.mode, 'move', 'F - test_move_point/mode:2')
@ -454,7 +454,7 @@ function test_move_point()
check_eq(p2.x, 26, 'F - test_move_point/x')
check_eq(p2.y, 44, 'F - test_move_point/y')
-- exit 'move' mode
App.run_after_mouse_click(Editor_state.margin_left+26, Editor_state.margin_top+Editor_state.drawing_padding_top+44, 1)
edit.run_after_mouse_click(Editor_state, Editor_state.margin_left+26, Editor_state.margin_top+Editor_state.drawing_padding_top+44, 1)
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_move_point/mode:3')
check_eq(drawing.pending, {}, 'F - test_move_point/pending')
-- wait until save
@ -475,15 +475,15 @@ function test_move_point_on_manhattan_line()
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'manhattan'
edit.draw(Editor_state)
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+46, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+46, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_move_point_on_manhattan_line/baseline/#shapes')
check_eq(#drawing.points, 2, 'F - test_move_point_on_manhattan_line/baseline/#points')
check_eq(drawing.shapes[1].mode, 'manhattan', 'F - test_move_point_on_manhattan_line/baseline/shape:1')
edit.draw(Editor_state)
-- enter 'move' mode
App.run_after_keychord('C-u')
edit.run_after_keychord(Editor_state, 'C-u')
check_eq(Editor_state.current_drawing_mode, 'move', 'F - test_move_point_on_manhattan_line/mode:1')
-- move point
App.mouse_move(Editor_state.margin_left+26, Editor_state.margin_top+Editor_state.drawing_padding_top+44)
@ -500,17 +500,17 @@ function test_delete_lines_at_point()
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_release(Editor_state.margin_left+55, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+55, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 2, 'F - test_delete_lines_at_point/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'line', 'F - test_delete_lines_at_point/baseline/shape:1')
check_eq(drawing.shapes[2].mode, 'line', 'F - test_delete_lines_at_point/baseline/shape:2')
-- hover on the common point and delete
App.mouse_move(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('C-d')
edit.run_after_keychord(Editor_state, 'C-d')
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_lines_at_point/shape:1')
check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_delete_lines_at_point/shape:2')
-- wait for some time
@ -528,17 +528,17 @@ function test_delete_line_under_mouse_pointer()
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_release(Editor_state.margin_left+55, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+55, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 2, 'F - test_delete_line_under_mouse_pointer/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'line', 'F - test_delete_line_under_mouse_pointer/baseline/shape:1')
check_eq(drawing.shapes[2].mode, 'line', 'F - test_delete_line_under_mouse_pointer/baseline/shape:2')
-- hover on one of the lines and delete
App.mouse_move(Editor_state.margin_left+25, Editor_state.margin_top+Editor_state.drawing_padding_top+26)
App.run_after_keychord('C-d')
edit.run_after_keychord(Editor_state, 'C-d')
-- only that line is deleted
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_line_under_mouse_pointer/shape:1')
check_eq(drawing.shapes[2].mode, 'line', 'F - test_delete_line_under_mouse_pointer/shape:2')
@ -552,23 +552,23 @@ function test_delete_point_from_polygon()
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
-- first point
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_keychord('g') -- polygon mode
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_keychord(Editor_state, 'g') -- polygon mode
-- second point
App.mouse_move(Editor_state.margin_left+65, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('p') -- add point
edit.run_after_keychord(Editor_state, 'p') -- add point
-- third point
App.mouse_move(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+26)
App.run_after_keychord('p') -- add point
edit.run_after_keychord(Editor_state, 'p') -- add point
-- fourth point
App.run_after_mouse_release(Editor_state.margin_left+14, Editor_state.margin_top+Editor_state.drawing_padding_top+16, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+14, Editor_state.margin_top+Editor_state.drawing_padding_top+16, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_delete_point_from_polygon/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/baseline/mode')
check_eq(#drawing.shapes[1].vertices, 4, 'F - test_delete_point_from_polygon/baseline/vertices')
-- hover on a point and delete
App.mouse_move(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+26)
App.run_after_keychord('C-d')
edit.run_after_keychord(Editor_state, 'C-d')
-- just the one point is deleted
check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/shape')
check_eq(#drawing.shapes[1].vertices, 3, 'F - test_delete_point_from_polygon/vertices')
@ -582,20 +582,20 @@ function test_delete_point_from_polygon()
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
-- first point
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_keychord('g') -- polygon mode
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_keychord(Editor_state, 'g') -- polygon mode
-- second point
App.mouse_move(Editor_state.margin_left+65, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('p') -- add point
edit.run_after_keychord(Editor_state, 'p') -- add point
-- third point
App.run_after_mouse_release(Editor_state.margin_left+14, Editor_state.margin_top+Editor_state.drawing_padding_top+16, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+14, Editor_state.margin_top+Editor_state.drawing_padding_top+16, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_delete_point_from_polygon/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/baseline/mode')
check_eq(#drawing.shapes[1].vertices, 3, 'F - test_delete_point_from_polygon/baseline/vertices')
-- hover on a point and delete
App.mouse_move(Editor_state.margin_left+65, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('C-d')
edit.run_after_keychord(Editor_state, 'C-d')
-- there's < 3 points left, so the whole polygon is deleted
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_point_from_polygon')
end
@ -609,8 +609,8 @@ function test_undo_name_point()
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
-- draw a line
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_undo_name_point/baseline/#shapes')
check_eq(#drawing.points, 2, 'F - test_undo_name_point/baseline/#points')
@ -624,14 +624,14 @@ function test_undo_name_point()
check_nil(p2.name, 'F - test_undo_name_point/baseline/p2:name')
check_eq(#Editor_state.history, 1, 'F - test_undo_name_point/baseline/history:1')
-- enter 'name' mode without moving the mouse
App.run_after_keychord('C-n')
App.run_after_textinput('A')
App.run_after_keychord('return')
edit.run_after_keychord(Editor_state, 'C-n')
edit.run_after_textinput(Editor_state, 'A')
edit.run_after_keychord(Editor_state, 'return')
check_eq(p2.name, 'A', 'F - test_undo_name_point/baseline')
check_eq(#Editor_state.history, 3, 'F - test_undo_name_point/baseline/history:2')
check_eq(Editor_state.next_history, 4, 'F - test_undo_name_point/baseline/next_history')
-- undo
App.run_after_keychord('C-z')
edit.run_after_keychord(Editor_state, 'C-z')
local drawing = Editor_state.lines[1]
local p2 = drawing.points[drawing.shapes[1].p2]
check_eq(Editor_state.next_history, 3, 'F - test_undo_name_point/next_history')
@ -653,8 +653,8 @@ function test_undo_move_point()
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 1, 'F - test_undo_move_point/baseline/#shapes')
check_eq(#drawing.points, 2, 'F - test_undo_move_point/baseline/#points')
@ -667,18 +667,18 @@ function test_undo_move_point()
check_eq(p2.y, 36, 'F - test_undo_move_point/baseline/p2:y')
check_nil(p2.name, 'F - test_undo_move_point/baseline/p2:name')
-- move p2
App.run_after_keychord('C-u')
edit.run_after_keychord(Editor_state, 'C-u')
App.mouse_move(Editor_state.margin_left+26, Editor_state.margin_top+Editor_state.drawing_padding_top+44)
App.update(0.05)
local p2 = drawing.points[drawing.shapes[1].p2]
check_eq(p2.x, 26, 'F - test_undo_move_point/x')
check_eq(p2.y, 44, 'F - test_undo_move_point/y')
-- exit 'move' mode
App.run_after_mouse_click(Editor_state.margin_left+26, Editor_state.margin_top+Editor_state.drawing_padding_top+44, 1)
edit.run_after_mouse_click(Editor_state, Editor_state.margin_left+26, Editor_state.margin_top+Editor_state.drawing_padding_top+44, 1)
check_eq(Editor_state.next_history, 4, 'F - test_undo_move_point/next_history')
-- undo
App.run_after_keychord('C-z')
App.run_after_keychord('C-z') -- bug: need to undo twice
edit.run_after_keychord(Editor_state, 'C-z')
edit.run_after_keychord(Editor_state, 'C-z') -- bug: need to undo twice
local drawing = Editor_state.lines[1]
local p2 = drawing.points[drawing.shapes[1].p2]
check_eq(Editor_state.next_history, 2, 'F - test_undo_move_point/next_history')
@ -702,21 +702,21 @@ function test_undo_delete_point()
Editor_state.lines = load_array{'```lines', '```', ''}
Editor_state.current_drawing_mode = 'line'
edit.draw(Editor_state)
App.run_after_mouse_press(Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
App.run_after_mouse_release(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_press(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
App.run_after_mouse_release(Editor_state.margin_left+55, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+5, Editor_state.margin_top+Editor_state.drawing_padding_top+6, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+55, Editor_state.margin_top+Editor_state.drawing_padding_top+26, 1)
local drawing = Editor_state.lines[1]
check_eq(#drawing.shapes, 2, 'F - test_undo_delete_point/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/baseline/shape:1')
check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/baseline/shape:2')
-- hover on the common point and delete
App.mouse_move(Editor_state.margin_left+35, Editor_state.margin_top+Editor_state.drawing_padding_top+36)
App.run_after_keychord('C-d')
edit.run_after_keychord(Editor_state, 'C-d')
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_undo_delete_point/shape:1')
check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_undo_delete_point/shape:2')
-- undo
App.run_after_keychord('C-z')
edit.run_after_keychord(Editor_state, 'C-z')
local drawing = Editor_state.lines[1]
local p2 = drawing.points[drawing.shapes[1].p2]
check_eq(Editor_state.next_history, 3, 'F - test_undo_move_point/next_history')

View File

@ -440,3 +440,46 @@ end
function edit.key_released(State, key, scancode)
end
--== copy some App methods for tests
-- all textinput events are also keypresses
-- TODO: handle chords of multiple keys
function edit.run_after_textinput(State, t)
edit.keychord_pressed(State, t)
edit.textinput(State, t)
edit.key_released(State, t)
App.screen.contents = {}
edit.draw(State)
end
-- not all keys are textinput
function edit.run_after_keychord(State, chord)
edit.keychord_pressed(State, chord)
edit.key_released(State, chord)
App.screen.contents = {}
edit.draw(State)
end
function edit.run_after_mouse_click(State, x,y, button)
App.fake_mouse_press(x,y, button)
edit.mouse_pressed(State, x,y, button)
App.fake_mouse_release(x,y, button)
edit.mouse_released(State, x,y, button)
App.screen.contents = {}
edit.draw(State)
end
function edit.run_after_mouse_press(State, x,y, button)
App.fake_mouse_press(x,y, button)
edit.mouse_pressed(State, x,y, button)
App.screen.contents = {}
edit.draw(State)
end
function edit.run_after_mouse_release(State, x,y, button)
App.fake_mouse_release(x,y, button)
edit.mouse_released(State, x,y, button)
App.screen.contents = {}
edit.draw(State)
end

View File

@ -17,7 +17,7 @@ function test_click_to_create_drawing()
App.screen.init{width=120, height=60}
Editor_state.lines = load_array{}
edit.draw(Editor_state)
App.run_after_mouse_click(8,Editor_state.margin_top+8, 1)
edit.run_after_mouse_click(Editor_state, 8,Editor_state.margin_top+8, 1)
-- cursor skips drawing to always remain on text
check_eq(#Editor_state.lines, 2, 'F - test_click_to_create_drawing/#lines')
check_eq(Editor_state.cursor1.line, 2, 'F - test_click_to_create_drawing/cursor')
@ -31,7 +31,7 @@ function test_backspace_to_delete_drawing()
-- cursor is on text as always (outside tests this will get initialized correctly)
Editor_state.cursor1.line = 2
-- backspacing deletes the drawing
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(#Editor_state.lines, 1, 'F - test_backspace_to_delete_drawing/#lines')
check_eq(Editor_state.cursor1.line, 1, 'F - test_backspace_to_delete_drawing/cursor')
end
@ -41,7 +41,7 @@ function test_insert_first_character()
App.screen.init{width=120, height=60}
Editor_state.lines = load_array{}
edit.draw(Editor_state)
App.run_after_textinput('a')
edit.run_after_textinput(Editor_state, 'a')
local y = Editor_state.margin_top
App.screen.check(y, 'a', 'F - test_insert_first_character/screen:1')
end
@ -54,7 +54,7 @@ function test_press_ctrl()
Editor_state.cursor1 = {line=1, pos=1}
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.screen_bottom1 = {}
App.run_after_keychord('C-m')
edit.run_after_keychord(Editor_state, 'C-m')
end
function test_move_left()
@ -63,7 +63,7 @@ function test_move_left()
Editor_state.lines = load_array{'a'}
Editor_state.cursor1 = {line=1, pos=2}
edit.draw(Editor_state)
App.run_after_keychord('left')
edit.run_after_keychord(Editor_state, 'left')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_left')
end
@ -73,7 +73,7 @@ function test_move_right()
Editor_state.lines = load_array{'a'}
Editor_state.cursor1 = {line=1, pos=1}
edit.draw(Editor_state)
App.run_after_keychord('right')
edit.run_after_keychord(Editor_state, 'right')
check_eq(Editor_state.cursor1.pos, 2, 'F - test_move_right')
end
@ -83,7 +83,7 @@ function test_move_left_to_previous_line()
Editor_state.lines = load_array{'abc', 'def'}
Editor_state.cursor1 = {line=2, pos=1}
edit.draw(Editor_state)
App.run_after_keychord('left')
edit.run_after_keychord(Editor_state, 'left')
check_eq(Editor_state.cursor1.line, 1, 'F - test_move_left_to_previous_line/line')
check_eq(Editor_state.cursor1.pos, 4, 'F - test_move_left_to_previous_line/pos') -- past end of line
end
@ -94,7 +94,7 @@ function test_move_right_to_next_line()
Editor_state.lines = load_array{'abc', 'def'}
Editor_state.cursor1 = {line=1, pos=4} -- past end of line
edit.draw(Editor_state)
App.run_after_keychord('right')
edit.run_after_keychord(Editor_state, 'right')
check_eq(Editor_state.cursor1.line, 2, 'F - test_move_right_to_next_line/line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_right_to_next_line/pos')
end
@ -105,7 +105,7 @@ function test_move_to_start_of_word()
Editor_state.lines = load_array{'abc'}
Editor_state.cursor1 = {line=1, pos=3}
edit.draw(Editor_state)
App.run_after_keychord('M-left')
edit.run_after_keychord(Editor_state, 'M-left')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_to_start_of_word')
end
@ -115,7 +115,7 @@ function test_move_to_start_of_previous_word()
Editor_state.lines = load_array{'abc def'}
Editor_state.cursor1 = {line=1, pos=4} -- at the space between words
edit.draw(Editor_state)
App.run_after_keychord('M-left')
edit.run_after_keychord(Editor_state, 'M-left')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_to_start_of_previous_word')
end
@ -125,7 +125,7 @@ function test_skip_to_previous_word()
Editor_state.lines = load_array{'abc def'}
Editor_state.cursor1 = {line=1, pos=5} -- at the start of second word
edit.draw(Editor_state)
App.run_after_keychord('M-left')
edit.run_after_keychord(Editor_state, 'M-left')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_skip_to_previous_word')
end
@ -135,7 +135,7 @@ function test_skip_past_tab_to_previous_word()
Editor_state.lines = load_array{'abc def\tghi'}
Editor_state.cursor1 = {line=1, pos=10} -- within third word
edit.draw(Editor_state)
App.run_after_keychord('M-left')
edit.run_after_keychord(Editor_state, 'M-left')
check_eq(Editor_state.cursor1.pos, 9, 'F - test_skip_past_tab_to_previous_word')
end
@ -145,7 +145,7 @@ function test_skip_multiple_spaces_to_previous_word()
Editor_state.lines = load_array{'abc def'}
Editor_state.cursor1 = {line=1, pos=6} -- at the start of second word
edit.draw(Editor_state)
App.run_after_keychord('M-left')
edit.run_after_keychord(Editor_state, 'M-left')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_skip_multiple_spaces_to_previous_word')
end
@ -155,7 +155,7 @@ function test_move_to_start_of_word_on_previous_line()
Editor_state.lines = load_array{'abc def', 'ghi'}
Editor_state.cursor1 = {line=2, pos=1}
edit.draw(Editor_state)
App.run_after_keychord('M-left')
edit.run_after_keychord(Editor_state, 'M-left')
check_eq(Editor_state.cursor1.line, 1, 'F - test_move_to_start_of_word_on_previous_line/line')
check_eq(Editor_state.cursor1.pos, 5, 'F - test_move_to_start_of_word_on_previous_line/pos')
end
@ -166,7 +166,7 @@ function test_move_past_end_of_word()
Editor_state.lines = load_array{'abc def'}
Editor_state.cursor1 = {line=1, pos=1}
edit.draw(Editor_state)
App.run_after_keychord('M-right')
edit.run_after_keychord(Editor_state, 'M-right')
check_eq(Editor_state.cursor1.pos, 4, 'F - test_move_past_end_of_word')
end
@ -176,7 +176,7 @@ function test_skip_to_next_word()
Editor_state.lines = load_array{'abc def'}
Editor_state.cursor1 = {line=1, pos=4} -- at the space between words
edit.draw(Editor_state)
App.run_after_keychord('M-right')
edit.run_after_keychord(Editor_state, 'M-right')
check_eq(Editor_state.cursor1.pos, 8, 'F - test_skip_to_next_word')
end
@ -186,7 +186,7 @@ function test_skip_past_tab_to_next_word()
Editor_state.lines = load_array{'abc\tdef'}
Editor_state.cursor1 = {line=1, pos=1} -- at the space between words
edit.draw(Editor_state)
App.run_after_keychord('M-right')
edit.run_after_keychord(Editor_state, 'M-right')
check_eq(Editor_state.cursor1.pos, 4, 'F - test_skip_past_tab_to_next_word')
end
@ -196,7 +196,7 @@ function test_skip_multiple_spaces_to_next_word()
Editor_state.lines = load_array{'abc def'}
Editor_state.cursor1 = {line=1, pos=4} -- at the start of second word
edit.draw(Editor_state)
App.run_after_keychord('M-right')
edit.run_after_keychord(Editor_state, 'M-right')
check_eq(Editor_state.cursor1.pos, 9, 'F - test_skip_multiple_spaces_to_next_word')
end
@ -206,7 +206,7 @@ function test_move_past_end_of_word_on_next_line()
Editor_state.lines = load_array{'abc def', 'ghi'}
Editor_state.cursor1 = {line=1, pos=8}
edit.draw(Editor_state)
App.run_after_keychord('M-right')
edit.run_after_keychord(Editor_state, 'M-right')
check_eq(Editor_state.cursor1.line, 2, 'F - test_move_past_end_of_word_on_next_line/line')
check_eq(Editor_state.cursor1.pos, 4, 'F - test_move_past_end_of_word_on_next_line/pos')
end
@ -221,7 +221,7 @@ function test_click_with_mouse()
Editor_state.screen_bottom1 = {}
-- click on the other line
edit.draw(Editor_state)
App.run_after_mouse_click(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_click(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
-- cursor moves
check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse/cursor')
check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse/selection is empty to avoid perturbing future edits')
@ -237,7 +237,7 @@ function test_click_with_mouse_on_empty_line()
Editor_state.screen_bottom1 = {}
-- click on the empty line
edit.draw(Editor_state)
App.run_after_mouse_click(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_click(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
-- cursor moves
check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_empty_line/cursor')
end
@ -340,7 +340,7 @@ function test_click_on_wrapping_line()
App.screen.check(y, "I'm ada", 'F - test_click_on_wrapping_line/baseline/screen:2')
y = y + Editor_state.line_height
-- click past end of second screen line
App.run_after_mouse_click(App.screen.width-2,y-2, 1)
edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1)
-- cursor moves to end of screen line
check_eq(Editor_state.cursor1.line, 1, 'F - test_click_on_wrapping_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 13, 'F - test_click_on_wrapping_line/cursor:pos')
@ -360,7 +360,7 @@ function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen()
App.screen.check(y, "I'm ada", 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/baseline/screen:2')
y = y + Editor_state.line_height
-- click past end of second screen line
App.run_after_mouse_click(App.screen.width-2,y-2, 1)
edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1)
-- cursor moves to end of screen line
check_eq(Editor_state.cursor1.line, 1, 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/cursor:line')
check_eq(Editor_state.cursor1.pos, 13, 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/cursor:pos')
@ -384,7 +384,7 @@ function test_click_past_end_of_wrapping_line()
App.screen.check(y, 'm', 'F - test_click_past_end_of_wrapping_line/baseline/screen:3')
y = y + Editor_state.line_height
-- click past the end of it
App.run_after_mouse_click(App.screen.width-2,y-2, 1)
edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1)
-- cursor moves to end of line
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
end
@ -407,7 +407,7 @@ function test_click_on_wrapping_line_containing_non_ascii()
App.screen.check(y, 'm', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:3')
y = y + Editor_state.line_height
-- click past the end of it
App.run_after_mouse_click(App.screen.width-2,y-2, 1)
edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1)
-- cursor moves to end of line
check_eq(Editor_state.cursor1.pos, 15, 'F - test_click_on_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points
end
@ -427,7 +427,7 @@ function test_click_past_end_of_word_wrapping_line()
App.screen.check(y, 'the quick brown fox ', 'F - test_click_past_end_of_word_wrapping_line/baseline/screen:1')
y = y + Editor_state.line_height
-- click past the end of the screen line
App.run_after_mouse_click(App.screen.width-2,y-2, 1)
edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1)
-- cursor moves to end of screen line
check_eq(Editor_state.cursor1.pos, 20, 'F - test_click_past_end_of_word_wrapping_line/cursor')
end
@ -443,7 +443,7 @@ function test_select_text()
edit.draw(Editor_state)
-- select a letter
App.fake_key_press('lshift')
App.run_after_keychord('S-right')
edit.run_after_keychord(Editor_state, 'S-right')
App.fake_key_release('lshift')
App.keyreleased('lshift')
-- selection persists even after shift is released
@ -464,7 +464,7 @@ function test_cursor_movement_without_shift_resets_selection()
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
-- press an arrow key without shift
App.run_after_keychord('right')
edit.run_after_keychord(Editor_state, 'right')
-- no change to data, selection is reset
check_nil(Editor_state.selection1.line, 'F - test_cursor_movement_without_shift_resets_selection')
check_eq(Editor_state.lines[1].data, 'abc', 'F - test_cursor_movement_without_shift_resets_selection/data')
@ -481,7 +481,7 @@ function test_edit_deletes_selection()
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
-- press a key
App.run_after_textinput('x')
edit.run_after_textinput(Editor_state, 'x')
-- selected text is deleted and replaced with the key
check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_edit_deletes_selection')
end
@ -518,7 +518,7 @@ function test_copy_does_not_reset_selection()
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
-- copy selection
App.run_after_keychord('C-c')
edit.run_after_keychord(Editor_state, 'C-c')
check_eq(App.clipboard, 'a', 'F - test_copy_does_not_reset_selection/clipboard')
-- selection is reset since shift key is not pressed
check(Editor_state.selection1.line, 'F - test_copy_does_not_reset_selection')
@ -535,7 +535,7 @@ function test_cut()
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
-- press a key
App.run_after_keychord('C-x')
edit.run_after_keychord(Editor_state, 'C-x')
check_eq(App.clipboard, 'a', 'F - test_cut/clipboard')
-- selected text is deleted
check_eq(Editor_state.lines[1].data, 'bc', 'F - test_cut/data')
@ -554,7 +554,7 @@ function test_paste_replaces_selection()
-- set clipboard
App.clipboard = 'xyz'
-- paste selection
App.run_after_keychord('C-v')
edit.run_after_keychord(Editor_state, 'C-v')
-- selection is reset since shift key is not pressed
-- selection includes the newline, so it's also deleted
check_eq(Editor_state.lines[1].data, 'xyzdef', 'F - test_paste_replaces_selection')
@ -578,7 +578,7 @@ function test_deleting_selection_may_scroll()
-- set up a selection starting above the currently displayed page
Editor_state.selection1 = {line=1, pos=2}
-- delete selection
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
-- page scrolls up
check_eq(Editor_state.screen_top1.line, 1, 'F - test_deleting_selection_may_scroll')
check_eq(Editor_state.lines[1].data, 'ahi', 'F - test_deleting_selection_may_scroll/data')
@ -592,10 +592,10 @@ function test_edit_wrapping_text()
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
App.run_after_textinput('g')
App.run_after_textinput('h')
App.run_after_textinput('i')
App.run_after_textinput('j')
edit.run_after_textinput(Editor_state, 'g')
edit.run_after_textinput(Editor_state, 'h')
edit.run_after_textinput(Editor_state, 'i')
edit.run_after_textinput(Editor_state, 'j')
local y = Editor_state.margin_top
App.screen.check(y, 'abc', 'F - test_edit_wrapping_text/screen:1')
y = y + Editor_state.line_height
@ -620,7 +620,7 @@ function test_insert_newline()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_insert_newline/baseline/screen:3')
-- hitting the enter key splits the line
App.run_after_keychord('return')
edit.run_after_keychord(Editor_state, 'return')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_insert_newline/screen_top')
check_eq(Editor_state.cursor1.line, 2, 'F - test_insert_newline/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_insert_newline/cursor:pos')
@ -641,7 +641,7 @@ function test_insert_newline_at_start_of_line()
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.screen_bottom1 = {}
-- hitting the enter key splits the line
App.run_after_keychord('return')
edit.run_after_keychord(Editor_state, 'return')
check_eq(Editor_state.cursor1.line, 2, 'F - test_insert_newline_at_start_of_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_insert_newline_at_start_of_line/cursor:pos')
check_eq(Editor_state.lines[1].data, '', 'F - test_insert_newline_at_start_of_line/data:1')
@ -665,7 +665,7 @@ function test_insert_from_clipboard()
App.screen.check(y, 'ghi', 'F - test_insert_from_clipboard/baseline/screen:3')
-- paste some text including a newline, check that new line is created
App.clipboard = 'xy\nz'
App.run_after_keychord('C-v')
edit.run_after_keychord(Editor_state, 'C-v')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_insert_from_clipboard/screen_top')
check_eq(Editor_state.cursor1.line, 2, 'F - test_insert_from_clipboard/cursor:line')
check_eq(Editor_state.cursor1.pos, 2, 'F - test_insert_from_clipboard/cursor:pos')
@ -686,7 +686,7 @@ function test_move_cursor_using_mouse()
Editor_state.screen_bottom1 = {}
Editor_state.selection1 = {}
edit.draw(Editor_state) -- populate line.y for each line in Editor_state.lines
App.run_after_mouse_release(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
check_eq(Editor_state.cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line')
check_eq(Editor_state.cursor1.pos, 2, 'F - test_move_cursor_using_mouse/cursor:pos')
check_nil(Editor_state.selection1.line, 'F - test_move_cursor_using_mouse/selection:line')
@ -703,9 +703,9 @@ function test_select_text_using_mouse()
Editor_state.selection1 = {}
edit.draw(Editor_state) -- populate line.y for each line in Editor_state.lines
-- press and hold on first location
App.run_after_mouse_press(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
-- drag and release somewhere else
App.run_after_mouse_release(Editor_state.margin_left+20,Editor_state.margin_top+Editor_state.line_height+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+20,Editor_state.margin_top+Editor_state.line_height+5, 1)
check_eq(Editor_state.selection1.line, 1, 'F - test_select_text_using_mouse/selection:line')
check_eq(Editor_state.selection1.pos, 2, 'F - test_select_text_using_mouse/selection:pos')
check_eq(Editor_state.cursor1.line, 2, 'F - test_select_text_using_mouse/cursor:line')
@ -722,12 +722,12 @@ function test_select_text_using_mouse_and_shift()
Editor_state.selection1 = {}
edit.draw(Editor_state) -- populate line.y for each line in Editor_state.lines
-- click on first location
App.run_after_mouse_press(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
App.run_after_mouse_release(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
-- hold down shift and click somewhere else
App.fake_key_press('lshift')
App.run_after_mouse_press(Editor_state.margin_left+20,Editor_state.margin_top+5, 1)
App.run_after_mouse_release(Editor_state.margin_left+20,Editor_state.margin_top+Editor_state.line_height+5, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+20,Editor_state.margin_top+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+20,Editor_state.margin_top+Editor_state.line_height+5, 1)
App.fake_key_release('lshift')
check_eq(Editor_state.selection1.line, 1, 'F - test_select_text_using_mouse_and_shift/selection:line')
check_eq(Editor_state.selection1.pos, 2, 'F - test_select_text_using_mouse_and_shift/selection:pos')
@ -745,16 +745,16 @@ function test_select_text_repeatedly_using_mouse_and_shift()
Editor_state.selection1 = {}
edit.draw(Editor_state) -- populate line.y for each line in Editor_state.lines
-- click on first location
App.run_after_mouse_press(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
App.run_after_mouse_release(Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+5, 1)
-- hold down shift and click on a second location
App.fake_key_press('lshift')
App.run_after_mouse_press(Editor_state.margin_left+20,Editor_state.margin_top+5, 1)
App.run_after_mouse_release(Editor_state.margin_left+20,Editor_state.margin_top+Editor_state.line_height+5, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+20,Editor_state.margin_top+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+20,Editor_state.margin_top+Editor_state.line_height+5, 1)
-- hold down shift and click at a third location
App.fake_key_press('lshift')
App.run_after_mouse_press(Editor_state.margin_left+20,Editor_state.margin_top+5, 1)
App.run_after_mouse_release(Editor_state.margin_left+8,Editor_state.margin_top+Editor_state.line_height+5, 1)
edit.run_after_mouse_press(Editor_state, Editor_state.margin_left+20,Editor_state.margin_top+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+Editor_state.line_height+5, 1)
App.fake_key_release('lshift')
-- selection is between first and third location. forget the second location, not the first.
check_eq(Editor_state.selection1.line, 1, 'F - test_select_text_repeatedly_using_mouse_and_shift/selection:line')
@ -774,7 +774,7 @@ function test_cut_without_selection()
Editor_state.selection1 = {}
edit.draw(Editor_state)
-- try to cut without selecting text
App.run_after_keychord('C-x')
edit.run_after_keychord(Editor_state, 'C-x')
-- no crash
check_nil(Editor_state.selection1.line, 'F - test_cut_without_selection')
end
@ -793,7 +793,7 @@ function test_pagedown()
y = y + Editor_state.line_height
App.screen.check(y, 'def', 'F - test_pagedown/baseline/screen:2')
-- after pagedown the bottom line becomes the top
App.run_after_keychord('pagedown')
edit.run_after_keychord(Editor_state, 'pagedown')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_pagedown/screen_top')
check_eq(Editor_state.cursor1.line, 2, 'F - test_pagedown/cursor')
y = Editor_state.margin_top
@ -823,7 +823,7 @@ function test_pagedown_skips_drawings()
App.screen.check(y, 'abc', 'F - test_pagedown_skips_drawings/baseline/screen:1')
-- after pagedown the screen draws the drawing up top
-- 15px margin + 10px margin + 25px drawing + 10px margin + 15px line3 = 75px < screen height 80px
App.run_after_keychord('pagedown')
edit.run_after_keychord(Editor_state, 'pagedown')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_pagedown_skips_drawings/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_pagedown_skips_drawings/cursor')
y = Editor_state.margin_top + drawing_height
@ -846,7 +846,7 @@ function test_pagedown_often_shows_start_of_wrapping_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi ', 'F - test_pagedown_often_shows_start_of_wrapping_line/baseline/screen:3')
-- after pagedown we start drawing from the bottom _line_ (multiple screen lines)
App.run_after_keychord('pagedown')
edit.run_after_keychord(Editor_state, 'pagedown')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_pagedown_often_shows_start_of_wrapping_line/screen_top:line')
check_eq(Editor_state.screen_top1.pos, 1, 'F - test_pagedown_often_shows_start_of_wrapping_line/screen_top:pos')
check_eq(Editor_state.cursor1.line, 2, 'F - test_pagedown_often_shows_start_of_wrapping_line/cursor:line')
@ -875,7 +875,7 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/baseline/screen:3')
-- after pagedown we scroll down the very long wrapping line
App.run_after_keychord('pagedown')
edit.run_after_keychord(Editor_state, 'pagedown')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen_top:line')
check_eq(Editor_state.screen_top1.pos, 9, 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen_top:pos')
y = Editor_state.margin_top
@ -902,7 +902,7 @@ function test_down_arrow_moves_cursor()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_down_arrow_moves_cursor/baseline/screen:3')
-- after hitting the down arrow, the cursor moves down by 1 line
App.run_after_keychord('down')
edit.run_after_keychord(Editor_state, 'down')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_down_arrow_moves_cursor/screen_top')
check_eq(Editor_state.cursor1.line, 2, 'F - test_down_arrow_moves_cursor/cursor')
-- the screen is unchanged
@ -930,7 +930,7 @@ function test_down_arrow_scrolls_down_by_one_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_down_arrow_scrolls_down_by_one_line/baseline/screen:3')
-- after hitting the down arrow the screen scrolls down by one line
App.run_after_keychord('down')
edit.run_after_keychord(Editor_state, 'down')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_down_arrow_scrolls_down_by_one_line/screen_top')
check_eq(Editor_state.cursor1.line, 4, 'F - test_down_arrow_scrolls_down_by_one_line/cursor')
y = Editor_state.margin_top
@ -957,7 +957,7 @@ function test_down_arrow_scrolls_down_by_one_screen_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi ', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
-- after hitting the down arrow the screen scrolls down by one line
App.run_after_keychord('down')
edit.run_after_keychord(Editor_state, 'down')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_down_arrow_scrolls_down_by_one_screen_line/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_down_arrow_scrolls_down_by_one_screen_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 5, 'F - test_down_arrow_scrolls_down_by_one_screen_line/cursor:pos')
@ -985,7 +985,7 @@ function test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_
y = y + Editor_state.line_height
App.screen.check(y, 'ghijk', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:3')
-- after hitting the down arrow the screen scrolls down by one line
App.run_after_keychord('down')
edit.run_after_keychord(Editor_state, 'down')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:line')
check_eq(Editor_state.cursor1.pos, 6, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:pos')
@ -1012,12 +1012,12 @@ function test_page_down_followed_by_down_arrow_does_not_scroll_screen_up()
y = y + Editor_state.line_height
App.screen.check(y, 'ghijk', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:3')
-- after hitting pagedown the screen scrolls down to start of a long line
App.run_after_keychord('pagedown')
edit.run_after_keychord(Editor_state, 'pagedown')
check_eq(Editor_state.screen_top1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/cursor:pos')
-- after hitting down arrow the screen doesn't scroll down further, and certainly doesn't scroll up
App.run_after_keychord('down')
edit.run_after_keychord(Editor_state, 'down')
check_eq(Editor_state.screen_top1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:line')
check_eq(Editor_state.cursor1.pos, 6, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:pos')
@ -1045,7 +1045,7 @@ function test_up_arrow_moves_cursor()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_up_arrow_moves_cursor/baseline/screen:3')
-- after hitting the up arrow the cursor moves up by 1 line
App.run_after_keychord('up')
edit.run_after_keychord(Editor_state, 'up')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_up_arrow_moves_cursor/screen_top')
check_eq(Editor_state.cursor1.line, 2, 'F - test_up_arrow_moves_cursor/cursor')
-- the screen is unchanged
@ -1073,7 +1073,7 @@ function test_up_arrow_scrolls_up_by_one_line()
y = y + Editor_state.line_height
App.screen.check(y, 'jkl', 'F - test_up_arrow_scrolls_up_by_one_line/baseline/screen:3')
-- after hitting the up arrow the screen scrolls up by one line
App.run_after_keychord('up')
edit.run_after_keychord(Editor_state, 'up')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_up_arrow_scrolls_up_by_one_line/screen_top')
check_eq(Editor_state.cursor1.line, 1, 'F - test_up_arrow_scrolls_up_by_one_line/cursor')
y = Editor_state.margin_top
@ -1098,7 +1098,7 @@ function test_up_arrow_scrolls_up_by_one_screen_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:2')
-- after hitting the up arrow the screen scrolls up to first screen line
App.run_after_keychord('up')
edit.run_after_keychord(Editor_state, 'up')
y = Editor_state.margin_top
App.screen.check(y, 'ghi ', 'F - test_up_arrow_scrolls_up_by_one_screen_line/screen:1')
y = y + Editor_state.line_height
@ -1127,7 +1127,7 @@ function test_up_arrow_scrolls_up_to_final_screen_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:3')
-- after hitting the up arrow the screen scrolls up to final screen line of previous line
App.run_after_keychord('up')
edit.run_after_keychord(Editor_state, 'up')
y = Editor_state.margin_top
App.screen.check(y, 'def', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:1')
y = y + Editor_state.line_height
@ -1156,7 +1156,7 @@ function test_up_arrow_scrolls_up_to_empty_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_up_arrow_scrolls_up_to_empty_line/baseline/screen:3')
-- after hitting the up arrow the screen scrolls up by one line
App.run_after_keychord('up')
edit.run_after_keychord(Editor_state, 'up')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_up_arrow_scrolls_up_to_empty_line/screen_top')
check_eq(Editor_state.cursor1.line, 1, 'F - test_up_arrow_scrolls_up_to_empty_line/cursor')
y = Editor_state.margin_top
@ -1181,7 +1181,7 @@ function test_pageup()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_pageup/baseline/screen:2')
-- after pageup the cursor goes to first line
App.run_after_keychord('pageup')
edit.run_after_keychord(Editor_state, 'pageup')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_pageup/screen_top')
check_eq(Editor_state.cursor1.line, 1, 'F - test_pageup/cursor')
y = Editor_state.margin_top
@ -1206,7 +1206,7 @@ function test_pageup_scrolls_up_by_screen_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
-- after hitting the page-up key the screen scrolls up to top
App.run_after_keychord('pageup')
edit.run_after_keychord(Editor_state, 'pageup')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_pageup_scrolls_up_by_screen_line/screen_top')
check_eq(Editor_state.cursor1.line, 1, 'F - test_pageup_scrolls_up_by_screen_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_pageup_scrolls_up_by_screen_line/cursor:pos')
@ -1232,7 +1232,7 @@ function test_pageup_scrolls_up_from_middle_screen_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_pageup_scrolls_up_from_middle_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
-- after hitting the page-up key the screen scrolls up to top
App.run_after_keychord('pageup')
edit.run_after_keychord(Editor_state, 'pageup')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/screen_top')
check_eq(Editor_state.cursor1.line, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/cursor:pos')
@ -1260,7 +1260,7 @@ function test_enter_on_bottom_line_scrolls_down()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_enter_on_bottom_line_scrolls_down/baseline/screen:3')
-- after hitting the enter key the screen scrolls down
App.run_after_keychord('return')
edit.run_after_keychord(Editor_state, 'return')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_enter_on_bottom_line_scrolls_down/screen_top')
check_eq(Editor_state.cursor1.line, 4, 'F - test_enter_on_bottom_line_scrolls_down/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_enter_on_bottom_line_scrolls_down/cursor:pos')
@ -1284,7 +1284,7 @@ function test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom()
local y = Editor_state.margin_top
App.screen.check(y, 'jkl', 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/baseline/screen:1')
-- after hitting the enter key the screen does not scroll down
App.run_after_keychord('return')
edit.run_after_keychord(Editor_state, 'return')
check_eq(Editor_state.screen_top1.line, 4, 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top')
check_eq(Editor_state.cursor1.line, 5, 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line')
check_eq(Editor_state.cursor1.pos, 1, 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos')
@ -1304,7 +1304,7 @@ function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bot
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
-- after hitting the inserting_text key the screen does not scroll down
App.run_after_textinput('a')
edit.run_after_textinput(Editor_state, 'a')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top')
check_eq(Editor_state.cursor1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line')
check_eq(Editor_state.cursor1.pos, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos')
@ -1328,9 +1328,9 @@ function test_typing_on_bottom_line_scrolls_down()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:3')
-- after typing something the line wraps and the screen scrolls down
App.run_after_textinput('j')
App.run_after_textinput('k')
App.run_after_textinput('l')
edit.run_after_textinput(Editor_state, 'j')
edit.run_after_textinput(Editor_state, 'k')
edit.run_after_textinput(Editor_state, 'l')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_typing_on_bottom_line_scrolls_down/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_typing_on_bottom_line_scrolls_down/cursor:line')
check_eq(Editor_state.cursor1.pos, 7, 'F - test_typing_on_bottom_line_scrolls_down/cursor:pos')
@ -1357,7 +1357,7 @@ function test_left_arrow_scrolls_up_in_wrapped_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_left_arrow_scrolls_up_in_wrapped_line/baseline/screen:2')
-- after hitting the left arrow the screen scrolls up to first screen line
App.run_after_keychord('left')
edit.run_after_keychord(Editor_state, 'left')
y = Editor_state.margin_top
App.screen.check(y, 'ghi ', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:1')
y = y + Editor_state.line_height
@ -1387,7 +1387,7 @@ function test_right_arrow_scrolls_down_in_wrapped_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi ', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:3') -- line wrapping includes trailing whitespace
-- after hitting the right arrow the screen scrolls down by one line
App.run_after_keychord('right')
edit.run_after_keychord(Editor_state, 'right')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_right_arrow_scrolls_down_in_wrapped_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 6, 'F - test_right_arrow_scrolls_down_in_wrapped_line/cursor:pos')
@ -1414,7 +1414,7 @@ function test_home_scrolls_up_in_wrapped_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_home_scrolls_up_in_wrapped_line/baseline/screen:2')
-- after hitting home the screen scrolls up to first screen line
App.run_after_keychord('home')
edit.run_after_keychord(Editor_state, 'home')
y = Editor_state.margin_top
App.screen.check(y, 'ghi ', 'F - test_home_scrolls_up_in_wrapped_line/screen:1')
y = y + Editor_state.line_height
@ -1444,7 +1444,7 @@ function test_end_scrolls_down_in_wrapped_line()
y = y + Editor_state.line_height
App.screen.check(y, 'ghi ', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:3') -- line wrapping includes trailing whitespace
-- after hitting end the screen scrolls down by one line
App.run_after_keychord('end')
edit.run_after_keychord(Editor_state, 'end')
check_eq(Editor_state.screen_top1.line, 2, 'F - test_end_scrolls_down_in_wrapped_line/screen_top')
check_eq(Editor_state.cursor1.line, 3, 'F - test_end_scrolls_down_in_wrapped_line/cursor:line')
check_eq(Editor_state.cursor1.pos, 8, 'F - test_end_scrolls_down_in_wrapped_line/cursor:pos')
@ -1472,9 +1472,9 @@ function test_position_cursor_on_recently_edited_wrapping_line()
y = y + Editor_state.line_height
App.screen.check(y, 'xyz', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:3')
-- add to the line until it's wrapping over 3 screen lines
App.run_after_textinput('s')
App.run_after_textinput('t')
App.run_after_textinput('u')
edit.run_after_textinput(Editor_state, 's')
edit.run_after_textinput(Editor_state, 't')
edit.run_after_textinput(Editor_state, 'u')
check_eq(Editor_state.cursor1.pos, 28, 'F - test_move_cursor_using_mouse/cursor:pos')
y = Editor_state.margin_top
App.screen.check(y, 'abc def ghi ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:1')
@ -1483,7 +1483,7 @@ function test_position_cursor_on_recently_edited_wrapping_line()
y = y + Editor_state.line_height
App.screen.check(y, 'stu', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline2/screen:3')
-- try to move the cursor earlier in the third screen line by clicking the mouse
App.run_after_mouse_release(Editor_state.margin_left+8,Editor_state.margin_top+Editor_state.line_height*2+5, 1)
edit.run_after_mouse_release(Editor_state, Editor_state.margin_left+8,Editor_state.margin_top+Editor_state.line_height*2+5, 1)
-- cursor should move
check_eq(Editor_state.cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line')
check_eq(Editor_state.cursor1.pos, 26, 'F - test_move_cursor_using_mouse/cursor:pos')
@ -1505,7 +1505,7 @@ function test_backspace_can_scroll_up()
y = y + Editor_state.line_height
App.screen.check(y, 'jkl', 'F - test_backspace_can_scroll_up/baseline/screen:3')
-- after hitting backspace the screen scrolls up by one line
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.screen_top1.line, 1, 'F - test_backspace_can_scroll_up/screen_top')
check_eq(Editor_state.cursor1.line, 1, 'F - test_backspace_can_scroll_up/cursor')
y = Editor_state.margin_top
@ -1530,7 +1530,7 @@ function test_backspace_can_scroll_up_screen_line()
y = y + Editor_state.line_height
App.screen.check(y, 'mno', 'F - test_backspace_can_scroll_up_screen_line/baseline/screen:2')
-- after hitting backspace the screen scrolls up by one screen line
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
y = Editor_state.margin_top
App.screen.check(y, 'ghijk', 'F - test_backspace_can_scroll_up_screen_line/screen:1')
y = y + Editor_state.line_height
@ -1550,7 +1550,7 @@ function test_backspace_past_line_boundary()
Editor_state.lines = load_array{'abc', 'def'}
Editor_state.cursor1 = {line=2, pos=1}
-- backspace joins with previous line
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.lines[1].data, 'abcdef', "F - test_backspace_past_line_boundary")
end
@ -1565,7 +1565,7 @@ function test_backspace_over_selection()
Editor_state.cursor1 = {line=1, pos=1}
Editor_state.selection1 = {line=1, pos=2}
-- backspace deletes the selected character, even though it's after the cursor
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.lines[1].data, 'bc', "F - test_backspace_over_selection/data")
-- cursor (remains) at start of selection
check_eq(Editor_state.cursor1.line, 1, "F - test_backspace_over_selection/cursor:line")
@ -1582,7 +1582,7 @@ function test_backspace_over_selection_reverse()
Editor_state.cursor1 = {line=1, pos=2}
Editor_state.selection1 = {line=1, pos=1}
-- backspace deletes the selected character
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.lines[1].data, 'bc', "F - test_backspace_over_selection_reverse/data")
-- cursor moves to start of selection
check_eq(Editor_state.cursor1.line, 1, "F - test_backspace_over_selection_reverse/cursor:line")
@ -1599,7 +1599,7 @@ function test_backspace_over_multiple_lines()
Editor_state.cursor1 = {line=1, pos=2}
Editor_state.selection1 = {line=4, pos=2}
-- backspace deletes the region and joins the remaining portions of lines on either side
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.lines[1].data, 'akl', "F - test_backspace_over_multiple_lines/data:1")
check_eq(Editor_state.lines[2].data, 'mno', "F - test_backspace_over_multiple_lines/data:2")
-- cursor remains at start of selection
@ -1617,7 +1617,7 @@ function test_backspace_to_end_of_line()
Editor_state.cursor1 = {line=1, pos=2}
Editor_state.selection1 = {line=1, pos=4}
-- backspace deletes rest of line without joining to any other line
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.lines[1].data, 'a', "F - test_backspace_to_start_of_line/data:1")
check_eq(Editor_state.lines[2].data, 'def', "F - test_backspace_to_start_of_line/data:2")
-- cursor remains at start of selection
@ -1635,7 +1635,7 @@ function test_backspace_to_start_of_line()
Editor_state.cursor1 = {line=2, pos=1}
Editor_state.selection1 = {line=2, pos=3}
-- backspace deletes beginning of line without joining to any other line
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.lines[1].data, 'abc', "F - test_backspace_to_start_of_line/data:1")
check_eq(Editor_state.lines[2].data, 'f', "F - test_backspace_to_start_of_line/data:2")
-- cursor remains at start of selection
@ -1654,7 +1654,7 @@ function test_undo_insert_text()
Editor_state.screen_bottom1 = {}
-- insert a character
edit.draw(Editor_state)
App.run_after_textinput('g')
edit.run_after_textinput(Editor_state, 'g')
check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_insert_text/baseline/cursor:line')
check_eq(Editor_state.cursor1.pos, 5, 'F - test_undo_insert_text/baseline/cursor:pos')
check_nil(Editor_state.selection1.line, 'F - test_undo_insert_text/baseline/selection:line')
@ -1666,7 +1666,7 @@ function test_undo_insert_text()
y = y + Editor_state.line_height
App.screen.check(y, 'xyz', 'F - test_undo_insert_text/baseline/screen:3')
-- undo
App.run_after_keychord('C-z')
edit.run_after_keychord(Editor_state, 'C-z')
check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_insert_text/cursor:line')
check_eq(Editor_state.cursor1.pos, 4, 'F - test_undo_insert_text/cursor:pos')
check_nil(Editor_state.selection1.line, 'F - test_undo_insert_text/selection:line')
@ -1687,7 +1687,7 @@ function test_undo_delete_text()
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.screen_bottom1 = {}
-- delete a character
App.run_after_keychord('backspace')
edit.run_after_keychord(Editor_state, 'backspace')
check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_delete_text/baseline/cursor:line')
check_eq(Editor_state.cursor1.pos, 4, 'F - test_undo_delete_text/baseline/cursor:pos')
check_nil(Editor_state.selection1.line, 'F - test_undo_delete_text/baseline/selection:line')
@ -1700,7 +1700,7 @@ function test_undo_delete_text()
App.screen.check(y, 'xyz', 'F - test_undo_delete_text/baseline/screen:3')
-- undo
--? -- after undo, the backspaced key is selected
App.run_after_keychord('C-z')
edit.run_after_keychord(Editor_state, 'C-z')
check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_delete_text/cursor:line')
check_eq(Editor_state.cursor1.pos, 5, 'F - test_undo_delete_text/cursor:pos')
check_nil(Editor_state.selection1.line, 'F - test_undo_delete_text/selection:line')
@ -1726,12 +1726,12 @@ function test_undo_restores_selection()
Editor_state.screen_bottom1 = {}
edit.draw(Editor_state)
-- delete selected text
App.run_after_textinput('x')
edit.run_after_textinput(Editor_state, 'x')
check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_undo_restores_selection/baseline')
check_nil(Editor_state.selection1.line, 'F - test_undo_restores_selection/baseline:selection')
-- undo
App.run_after_keychord('C-z')
App.run_after_keychord('C-z')
edit.run_after_keychord(Editor_state, 'C-z')
edit.run_after_keychord(Editor_state, 'C-z')
-- selection is restored
check_eq(Editor_state.selection1.line, 1, 'F - test_undo_restores_selection/line')
check_eq(Editor_state.selection1.pos, 2, 'F - test_undo_restores_selection/pos')