about summary refs log tree commit diff stats
path: root/drawing_tests.lua
diff options
context:
space:
mode:
Diffstat (limited to 'drawing_tests.lua')
-rw-r--r--drawing_tests.lua38
1 files changed, 36 insertions, 2 deletions
diff --git a/drawing_tests.lua b/drawing_tests.lua
index b73be2e..761824d 100644
--- a/drawing_tests.lua
+++ b/drawing_tests.lua
@@ -586,7 +586,7 @@ function test_undo_name_point()
   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
+  -- undo 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')
@@ -632,9 +632,43 @@ function test_undo_move_point()
   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
+  -- undo 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
+
+function test_undo_delete_point()
+  io.write('\ntest_undo_delete_point')
+  -- create a drawing with two lines connected at a point
+  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)
+  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
+  App.run_after_mouse_release(Margin_left+55, Margin_top+Drawing_padding_top+26, 1)
+  local drawing = 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(Margin_left+35, Margin_top+Drawing_padding_top+36)
+  App.run_after_keychord('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')
+  local drawing = Lines[1]
+  local p2 = drawing.points[drawing.shapes[1].p2]
+  check_eq(Next_history, 3, 'F - test_undo_move_point/next_history')
+  check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/shape:1')
+  check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/shape:2')
+  -- undo is saved
+  Lines = load_from_disk(Filename)
+  check_eq(#Lines[1].shapes, 2, 'F - test_undo_delete_point/save')
+end