about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Manual_tests.md1
-rw-r--r--drawing_tests.lua35
-rw-r--r--main.lua5
3 files changed, 39 insertions, 2 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index 1ee4aaf..b701718 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.
 
 drawing
   select a point and move it
-  select a point and name it
 
 persistence:
   draw a line, circle, rectangle, square, polygon, quit, restart. All the shapes you drew should still be visible.
diff --git a/drawing_tests.lua b/drawing_tests.lua
index 6b87c0b..545f182 100644
--- a/drawing_tests.lua
+++ b/drawing_tests.lua
@@ -321,3 +321,38 @@ function test_draw_square()
   check_eq(p.x, 5, 'F - test_draw_square/p4:x')
   check_eq(p.y, 66, 'F - test_draw_square/p4:y')
 end
+
+function test_name_point()
+  io.write('\ntest_name_point')
+  -- create a drawing with a line
+  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_name_point/baseline/#shapes')
+  check_eq(#drawing.points, 2, 'F - test_name_point/baseline/#points')
+  check_eq(drawing.shapes[1].mode, 'line', 'F - test_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_name_point/baseline/p1:x')
+  check_eq(p1.y, 6, 'F - test_name_point/baseline/p1:y')
+  check_eq(p2.x, 35, 'F - test_name_point/baseline/p2:x')
+  check_eq(p2.y, 36, 'F - test_name_point/baseline/p2:y')
+  check_nil(p2.name, 'F - test_name_point/baseline/p2:name')
+  -- enter 'name' mode without moving the mouse
+  App.run_after_keychord('C-n')
+  check_eq(Current_drawing_mode, 'name', 'F - test_name_point/mode:1')
+  App.run_after_textinput('A')
+  check_eq(p2.name, 'A', 'F - test_name_point')
+  -- still in 'name' mode
+  check_eq(Current_drawing_mode, 'name', 'F - test_name_point/mode:2')
+  -- exit 'name' mode
+  App.run_after_keychord('return')
+  check_eq(Current_drawing_mode, 'line', 'F - test_name_point/mode:3')
+  check_eq(p2.name, 'A', 'F - test_name_point')
+end
diff --git a/main.lua b/main.lua
index f717397..165538a 100644
--- a/main.lua
+++ b/main.lua
@@ -65,6 +65,8 @@ Previous_drawing_mode = nil
 -- values for tests
 Font_height = 14
 Line_height = 15
+-- widest possible character width
+Em = App.newText(love.graphics.getFont(), 'm')
 
 Margin_top = 15
 Margin_left = 25
@@ -174,8 +176,9 @@ function initialize_font_settings(font_height)
   love.graphics.setFont(love.graphics.newFont(Font_height))
   Line_height = math.floor(font_height*1.3)
 
-  -- maximum width available to either text or drawings, in pixels
   Em = App.newText(love.graphics.getFont(), 'm')
+
+  -- maximum width available to either text or drawings, in pixels
   -- readable text width is 50-75 chars
   Line_width = math.min(40*App.width(Em), App.screen.width-50)
 end