From 1aa2590236bb1171ca223b68ccfdb1fc8cc4d869 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 14 Jun 2022 22:38:36 -0700 Subject: test: undo naming a point Also ensure we autosave. --- Manual_tests.md | 1 - drawing_tests.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ main.lua | 2 ++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Manual_tests.md b/Manual_tests.md index c4773eb..38d1a66 100644 --- a/Manual_tests.md +++ b/Manual_tests.md @@ -13,7 +13,6 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking. ### Todo list undo: - naming points deleting points moving points diff --git a/drawing_tests.lua b/drawing_tests.lua index 758556e..aaaa467 100644 --- a/drawing_tests.lua +++ b/drawing_tests.lua @@ -548,3 +548,46 @@ function test_delete_point_from_polygon() -- 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 + +function test_undo_name_point() + io.write('\ntest_undo_name_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() + -- draw a line + 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_name_point/baseline/#shapes') + check_eq(#drawing.points, 2, 'F - test_undo_name_point/baseline/#points') + check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_name_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_name_point/baseline/p1:x') + check_eq(p1.y, 6, 'F - test_undo_name_point/baseline/p1:y') + check_eq(p2.x, 35, 'F - test_undo_name_point/baseline/p2:x') + check_eq(p2.y, 36, 'F - test_undo_name_point/baseline/p2:y') + check_nil(p2.name, 'F - test_undo_name_point/baseline/p2:name') + check_eq(#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') + check_eq(p2.name, 'A', 'F - test_undo_name_point/baseline') + check_eq(#History, 3, 'F - test_undo_name_point/baseline/history:2') + check_eq(Next_history, 4, 'F - test_undo_name_point/baseline/next_history') + -- undo + App.run_after_keychord('C-z') + local drawing = Lines[1] + local p2 = drawing.points[drawing.shapes[1].p2] + check_eq(Next_history, 3, 'F - test_undo_name_point/next_history') + check_eq(p2.name, '', 'F - test_undo_name_point') -- not quite what it was before, but close enough + -- change is saved + Lines = load_from_disk(Filename) + local p2 = Lines[1].points[drawing.shapes[1].p2] + check_eq(p2.name, '', 'F - test_undo_name_point/save') +end diff --git a/main.lua b/main.lua index 165538a..def3ec2 100644 --- a/main.lua +++ b/main.lua @@ -409,6 +409,7 @@ function App.keychord_pressed(chord) Selection1 = deepcopy(src.selection) patch(Lines, event.after, event.before) Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks + save_to_disk(Lines, Filename) end elseif chord == 'C-y' then for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll @@ -420,6 +421,7 @@ function App.keychord_pressed(chord) Selection1 = deepcopy(src.selection) patch(Lines, event.before, event.after) Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks + save_to_disk(Lines, Filename) end -- clipboard elseif chord == 'C-c' then -- cgit 1.4.1-2-gfad0