about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Manual_tests.md8
-rw-r--r--drawing_tests.lua38
2 files changed, 39 insertions, 7 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index ebdb79c..efdd8b1 100644
--- a/Manual_tests.md
+++ b/Manual_tests.md
@@ -1,5 +1,7 @@
 I care a lot about being able to automatically check _any_ property about my
-program before it ever runs. However, some things don't have tests yet.
+program before it ever runs. However, some things don't have tests yet, either
+because I don't know how to test them or because I've been lazy. I'll at least
+record those here.
 
 ### Compromises
 
@@ -9,12 +11,8 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking.
   byte offsets as _offset, and character positions as _pos. For example,
   string.sub should never use a _pos to substring, only an _offset.
 
-
 ### Todo list
 
-undo:
-  deleting points
-
 resize:
   create a file containing a long line of characters without spaces. try
   resizing the window vertically and horizontally, as far as possible.
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