From b8d777413863e83f61204fd1d98b80fe9e549a69 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 14 Jun 2022 22:43:59 -0700 Subject: test: undo moving point --- Manual_tests.md | 1 - drawing_tests.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Manual_tests.md b/Manual_tests.md index 38d1a66..ebdb79c 100644 --- a/Manual_tests.md +++ b/Manual_tests.md @@ -14,7 +14,6 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking. undo: deleting points - moving points resize: create a file containing a long line of characters without spaces. try diff --git a/drawing_tests.lua b/drawing_tests.lua index aaaa467..b73be2e 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -591,3 +591,50 @@ function test_undo_name_point() local p2 = Lines[1].points[drawing.shapes[1].p2] check_eq(p2.name, '', 'F - test_undo_name_point/save') end + +function test_undo_move_point() + io.write('\ntest_undo_move_point') + -- create a drawing with a line + Filename = 'foo' + App.screen.init{width=Margin_left+300, height=300} + Lines = load_array{'```lines', '```', ''} + Line_width = 256 -- drawing coordinates 1:1 with pixels + Current_drawing_mode = 'line' + App.draw() + App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1) + App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+36, 1) + local drawing = 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') + check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_move_point/baseline/shape:1') + local p1 = drawing.points[drawing.shapes[1].p1] + local p2 = drawing.points[drawing.shapes[1].p2] + check_eq(p1.x, 5, 'F - test_undo_move_point/baseline/p1:x') + check_eq(p1.y, 6, 'F - test_undo_move_point/baseline/p1:y') + check_eq(p2.x, 35, 'F - test_undo_move_point/baseline/p2:x') + 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') + App.mouse_move(Margin_left+26, Margin_top+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(Margin_left+26, Margin_top+Drawing_padding_top+44, 1) + check_eq(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 + local drawing = Lines[1] + local p2 = drawing.points[drawing.shapes[1].p2] + check_eq(Next_history, 2, 'F - test_undo_move_point/next_history') + check_eq(p2.x, 35, 'F - test_undo_move_point/x') + check_eq(p2.y, 36, 'F - test_undo_move_point/y') + -- change is saved + Lines = load_from_disk(Filename) + local p2 = Lines[1].points[drawing.shapes[1].p2] + check_eq(p2.x, 35, 'F - test_undo_move_point/save/x') + check_eq(p2.y, 36, 'F - test_undo_move_point/save/y') +end -- cgit 1.4.1-2-gfad0