diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-03-26 09:49:03 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-03-26 09:49:03 -0700 |
commit | 46e568c4c566b6377b90daad211d16a59c540e4b (patch) | |
tree | b20b073e02418e18c108cc0c2e62b5ff8e42eda4 /drawing_tests.lua | |
parent | 9fff5b713214263a1565cf933f5db165483a5081 (diff) | |
parent | eae5c9505c665b343af7690d9665431ae17ed5e9 (diff) | |
download | text.love-46e568c4c566b6377b90daad211d16a59c540e4b.tar.gz |
Merge lines.love
Diffstat (limited to 'drawing_tests.lua')
-rw-r--r-- | drawing_tests.lua | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/drawing_tests.lua b/drawing_tests.lua index 91c4825..491ff3a 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -426,6 +426,72 @@ function test_name_point() check_eq(p2.name, 'A', 'save') end +function test_name_point_then_hit_backspace() + -- create a drawing with a line + App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels + Editor_state = edit.initialize_test_state() + Editor_state.filename = 'foo' + Editor_state.lines = load_array{'```lines', '```', ''} + Text.redraw_all(Editor_state) + Editor_state.current_drawing_mode = 'line' + edit.draw(Editor_state) + -- draw a line + edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) + edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) + local drawing = Editor_state.lines[1] + check_eq(#drawing.shapes, 1, 'baseline/#shapes') + check_eq(#drawing.points, 2, 'baseline/#points') + check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1') + local p1 = drawing.points[drawing.shapes[1].p1] + local p2 = drawing.points[drawing.shapes[1].p2] + check_eq(p1.x, 5, 'baseline/p1:x') + check_eq(p1.y, 6, 'baseline/p1:y') + check_eq(p2.x, 35, 'baseline/p2:x') + check_eq(p2.y, 36, 'baseline/p2:y') + check_nil(p2.name, 'baseline/p2:name') + -- enter 'name' mode without moving the mouse + edit.run_after_keychord(Editor_state, 'C-n') + check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1') + -- hit backspace + edit.run_after_keychord(Editor_state, 'backspace') + -- no crash +end + +function test_name_point_then_exit_drawing() + -- create a drawing with a line + App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels + Editor_state = edit.initialize_test_state() + Editor_state.filename = 'foo' + Editor_state.lines = load_array{'```lines', '```', ''} + Text.redraw_all(Editor_state) + edit.check_locs(Editor_state) + Editor_state.current_drawing_mode = 'line' + edit.draw(Editor_state) + -- draw a line + edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) + edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) + local drawing = Editor_state.lines[1] + check_eq(#drawing.shapes, 1, 'baseline/#shapes') + check_eq(#drawing.points, 2, 'baseline/#points') + check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1') + local p1 = drawing.points[drawing.shapes[1].p1] + local p2 = drawing.points[drawing.shapes[1].p2] + check_eq(p1.x, 5, 'baseline/p1:x') + check_eq(p1.y, 6, 'baseline/p1:y') + check_eq(p2.x, 35, 'baseline/p2:x') + check_eq(p2.y, 36, 'baseline/p2:y') + check_nil(p2.name, 'baseline/p2:name') + -- enter 'name' mode without moving the mouse + edit.run_after_keychord(Editor_state, 'C-n') + check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1') + -- click outside the drawing + edit.run_after_mouse_click(Editor_state, App.screen.width-5, App.screen.height-5, 1) + -- press a key + edit.run_after_text_input(Editor_state, 'a') + -- key goes to text + check_eq(Editor_state.lines[2].data, 'a') +end + function test_move_point() -- create a drawing with a line App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels |