about summary refs log tree commit diff stats
path: root/drawing_tests.lua
blob: 4505002fee952ccb4e00fc8a6300af4bb3810a57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
-- major tests for drawings
-- We minimize assumptions about specific pixels, and try to test at the level
-- of specific shapes. In particular, no tests of freehand drawings.

function test_draw_line()
  io.write('\ntest_draw_line')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  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()
  check_eq(#Lines, 2, 'F - test_draw_line/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_line/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_line/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_line/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes')
  -- 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_draw_line/#shapes')
  check_eq(#drawing.points, 2, 'F - test_draw_line/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'F - test_draw_line/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_draw_line/p1:x')
  check_eq(p1.y, 6, 'F - test_draw_line/p1:y')
  check_eq(p2.x, 35, 'F - test_draw_line/p2:x')
  check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
end

function test_draw_horizontal_line()
  io.write('\ntest_draw_horizontal_line')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  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 = 'manhattan'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_horizontal_line/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_horizontal_line/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_horizontal_line/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_horizontal_line/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_horizontal_line/baseline/#shapes')
  -- draw a line that is more horizontal than vertical
  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+26, 1)
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_horizontal_line/#shapes')
  check_eq(#drawing.points, 2, 'F - test_draw_horizontal_line/#points')
  check_eq(drawing.shapes[1].mode, 'manhattan', 'F - test_draw_horizontal_line/shape_mode')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'F - test_draw_horizontal_line/p1:x')
  check_eq(p1.y, 6, 'F - test_draw_horizontal_line/p1:y')
  check_eq(p2.x, 35, 'F - test_draw_horizontal_line/p2:x')
  check_eq(p2.y, p1.y, 'F - test_draw_horizontal_line/p2:y')
end

function test_draw_circle()
  io.write('\ntest_draw_circle')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  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()
  check_eq(#Lines, 2, 'F - test_draw_circle/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_circle/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_circle/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_circle/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_circle/baseline/#shapes')
  -- draw a circle
  App.mouse_move(Margin_left+4, Margin_top+Drawing_padding_top+4)  -- hover on drawing
  App.run_after_keychord('C-o')
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_mouse_release(Margin_left+35+30, Margin_top+Drawing_padding_top+36, 1)
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_circle/#shapes')
  check_eq(#drawing.points, 1, 'F - test_draw_circle/#points')
  check_eq(drawing.shapes[1].mode, 'circle', 'F - test_draw_horizontal_line/shape_mode')
  check_eq(drawing.shapes[1].radius, 30, 'F - test_draw_circle/radius')
  local center = drawing.points[drawing.shapes[1].center]
  check_eq(center.x, 35, 'F - test_draw_circle/center:x')
  check_eq(center.y, 36, 'F - test_draw_circle/center:y')
end

function test_keys_do_not_affect_shape_when_mouse_up()
  io.write('\ntest_keys_do_not_affect_shape_when_mouse_up')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  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()
  -- hover over drawing and press 'o' without holding mouse
  App.mouse_move(Margin_left+4, Margin_top+Drawing_padding_top+4)  -- hover on drawing
  App.run_after_keychord('o')
  -- no change to drawing mode
  check_eq(Current_drawing_mode, 'line', 'F - test_keys_do_not_affect_shape_when_mouse_up/drawing_mode')
  -- no change to text either because we didn't run the textinput event
end

function test_draw_circle_mid_stroke()
  io.write('\ntest_draw_circle_mid_stroke')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  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()
  check_eq(#Lines, 2, 'F - test_draw_circle_mid_stroke/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_circle_mid_stroke/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_circle_mid_stroke/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_circle_mid_stroke/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_circle_mid_stroke/baseline/#shapes')
  -- draw a circle
  App.mouse_move(Margin_left+4, Margin_top+Drawing_padding_top+4)  -- hover on drawing
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_keychord('o')
  App.run_after_mouse_release(Margin_left+35+30, Margin_top+Drawing_padding_top+36, 1)
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_circle_mid_stroke/#shapes')
  check_eq(#drawing.points, 1, 'F - test_draw_circle_mid_stroke/#points')
  check_eq(drawing.shapes[1].mode, 'circle', 'F - test_draw_horizontal_line/shape_mode')
  check_eq(drawing.shapes[1].radius, 30, 'F - test_draw_circle_mid_stroke/radius')
  local center = drawing.points[drawing.shapes[1].center]
  check_eq(center.x, 35, 'F - test_draw_circle_mid_stroke/center:x')
  check_eq(center.y, 36, 'F - test_draw_circle_mid_stroke/center:y')
end

function test_draw_arc()
  io.write('\ntest_draw_arc')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  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 = 'circle'
  App.draw()
  check_eq(#Lines, 2, 'F - test_draw_arc/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_arc/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_arc/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_arc/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_arc/baseline/#shapes')
  -- draw an arc
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.mouse_move(Margin_left+35+30, Margin_top+Drawing_padding_top+36)
  App.run_after_keychord('a')  -- arc mode
  App.run_after_mouse_release(Margin_left+35+50, Margin_top+Drawing_padding_top+36+50, 1)  -- 45°
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_arc/#shapes')
  check_eq(#drawing.points, 2, 'F - test_draw_arc/#points')
  check_eq(drawing.shapes[1].mode, 'arc', 'F - test_draw_horizontal_line/shape_mode')
  local arc = drawing.shapes[1]
  check_eq(arc.radius, 30, 'F - test_draw_arc/radius')
  local center = drawing.points[arc.center]
  check_eq(center.x, 35, 'F - test_draw_arc/center:x')
  check_eq(center.y, 36, 'F - test_draw_arc/center:y')
  check_eq(arc.start_angle, 0, 'F - test_draw_arc/start:angle')
  check_eq(arc.end_angle, math.pi/4, 'F - test_draw_arc/end:angle')
end

function test_draw_polygon()
  io.write('\ntest_draw_polygon')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  App.draw()
  check_eq(Current_drawing_mode, 'line', 'F - test_draw_polygon/baseline/drawing_mode')
  check_eq(#Lines, 2, 'F - test_draw_polygon/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_polygon/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_polygon/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_polygon/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')
  -- first point
  App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
  App.run_after_keychord('g')  -- polygon mode
  -- second point
  App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+36)
  App.run_after_keychord('p')  -- add point
  -- final point
  App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+26, 1)
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_polygon/#shapes')
  check_eq(#drawing.points, 3, 'F - test_draw_polygon/vertices')
  local shape = drawing.shapes[1]
  check_eq(shape.mode, 'polygon', 'F - test_draw_polygon/shape_mode')
  check_eq(#shape.vertices, 3, 'F - test_draw_polygon/vertices')
  local p = drawing.points[shape.vertices[1]]
  check_eq(p.x, 5, 'F - test_draw_polygon/p1:x')
  check_eq(p.y, 6, 'F - test_draw_polygon/p1:y')
  local p = drawing.points[shape.vertices[2]]
  check_eq(p.x, 65, 'F - test_draw_polygon/p2:x')
  check_eq(p.y, 36, 'F - test_draw_polygon/p2:y')
  local p = drawing.points[shape.vertices[3]]
  check_eq(p.x, 35, 'F - test_draw_polygon/p3:x')
  check_eq(p.y, 26, 'F - test_draw_polygon/p3:y')
end

function test_draw_rectangle()
  io.write('\ntest_draw_rectangle')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  App.draw()
  check_eq(Current_drawing_mode, 'line', 'F - test_draw_rectangle/baseline/drawing_mode')
  check_eq(#Lines, 2, 'F - test_draw_rectangle/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_rectangle/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_rectangle/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_rectangle/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_rectangle/baseline/#shapes')
  -- first point
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_keychord('r')  -- rectangle mode
  -- second point/first edge
  App.mouse_move(Margin_left+42, Margin_top+Drawing_padding_top+45)
  App.run_after_keychord('p')
  -- override second point/first edge
  App.mouse_move(Margin_left+75, Margin_top+Drawing_padding_top+76)
  App.run_after_keychord('p')
  -- release (decides 'thickness' of rectangle perpendicular to first edge)
  App.run_after_mouse_release(Margin_left+15, Margin_top+Drawing_padding_top+26, 1)
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_rectangle/#shapes')
  check_eq(#drawing.points, 5, 'F - test_draw_rectangle/#points')  -- currently includes every point added
  local shape = drawing.shapes[1]
  check_eq(shape.mode, 'rectangle', 'F - test_draw_rectangle/shape_mode')
  check_eq(#shape.vertices, 4, 'F - test_draw_rectangle/vertices')
  local p = drawing.points[shape.vertices[1]]
  check_eq(p.x, 35, 'F - test_draw_rectangle/p1:x')
  check_eq(p.y, 36, 'F - test_draw_rectangle/p1:y')
  local p = drawing.points[shape.vertices[2]]
  check_eq(p.x, 75, 'F - test_draw_rectangle/p2:x')
  check_eq(p.y, 76, 'F - test_draw_rectangle/p2:y')
  local p = drawing.points[shape.vertices[3]]
  check_eq(p.x, 70, 'F - test_draw_rectangle/p3:x')
  check_eq(p.y, 81, 'F - test_draw_rectangle/p3:y')
  local p = drawing.points[shape.vertices[4]]
  check_eq(p.x, 30, 'F - test_draw_rectangle/p4:x')
  check_eq(p.y, 41, 'F - test_draw_rectangle/p4:y')
end

function test_draw_rectangle_intermediate()
  io.write('\ntest_draw_rectangle_intermediate')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  App.draw()
  check_eq(Current_drawing_mode, 'line', 'F - test_draw_rectangle_intermediate/baseline/drawing_mode')
  check_eq(#Lines, 2, 'F - test_draw_rectangle_intermediate/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_rectangle_intermediate/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_rectangle_intermediate/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_rectangle_intermediate/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_rectangle_intermediate/baseline/#shapes')
  -- first point
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_keychord('r')  -- rectangle mode
  -- second point/first edge
  App.mouse_move(Margin_left+42, Margin_top+Drawing_padding_top+45)
  App.run_after_keychord('p')
  -- override second point/first edge
  App.mouse_move(Margin_left+75, Margin_top+Drawing_padding_top+76)
  App.run_after_keychord('p')
  local drawing = Lines[1]
  check_eq(#drawing.points, 3, 'F - test_draw_rectangle_intermediate/#points')  -- currently includes every point added
  local pending = drawing.pending
  check_eq(pending.mode, 'rectangle', 'F - test_draw_rectangle_intermediate/shape_mode')
  check_eq(#pending.vertices, 2, 'F - test_draw_rectangle_intermediate/vertices')
  local p = drawing.points[pending.vertices[1]]
  check_eq(p.x, 35, 'F - test_draw_rectangle_intermediate/p1:x')
  check_eq(p.y, 36, 'F - test_draw_rectangle_intermediate/p1:y')
  local p = drawing.points[pending.vertices[2]]
  check_eq(p.x, 75, 'F - test_draw_rectangle_intermediate/p2:x')
  check_eq(p.y, 76, 'F - test_draw_rectangle_intermediate/p2:y')
  -- outline of rectangle is drawn based on where the mouse is, but we can't check that so far
end

function test_draw_square()
  io.write('\ntest_draw_square')
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Margin_left+300, height=300}
  Lines = load_array{'```lines', '```', ''}
  Line_width = 256  -- drawing coordinates 1:1 with pixels
  App.draw()
  check_eq(Current_drawing_mode, 'line', 'F - test_draw_square/baseline/drawing_mode')
  check_eq(#Lines, 2, 'F - test_draw_square/baseline/#lines')
  check_eq(Lines[1].mode, 'drawing', 'F - test_draw_square/baseline/mode')
  check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_square/baseline/y')
  check_eq(Lines[1].h, 128, 'F - test_draw_square/baseline/y')
  check_eq(#Lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes')
  -- first point
  App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
  App.run_after_keychord('s')  -- square mode
  -- second point/first edge
  App.mouse_move(Margin_left+42, Margin_top+Drawing_padding_top+45)
  App.run_after_keychord('p')
  -- override second point/first edge
  App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+66)
  App.run_after_keychord('p')
  -- release (decides which side of first edge to draw square on)
  App.run_after_mouse_release(Margin_left+15, Margin_top+Drawing_padding_top+26, 1)
  local drawing = Lines[1]
  check_eq(#drawing.shapes, 1, 'F - test_draw_square/#shapes')
  check_eq(#drawing.points, 5, 'F - test_draw_square/#points')  -- currently includes every point added
  check_eq(drawing.shapes[1].mode, 'square', 'F - test_draw_square/shape_mode')
  check_eq(#drawing.shapes[1].vertices, 4, 'F - test_draw_square/vertices')
  local p = drawing.points[drawing.shapes[1].vertices[1]]
  check_eq(p.x, 35, 'F - test_draw_square/p1:x')
  check_eq(p.y, 36, 'F - test_draw_square/p1:y')
  local p = drawing.points[drawing.shapes[1].vertices[2]]
  check_eq(p.x, 65, 'F - test_draw_square/p2:x')
  check_eq(p.y, 66, 'F - test_draw_square/p2:y')
  local p = drawing.points[drawing.shapes[1].vertices[3]]
  check_eq(p.x, 35, 'F - test_draw_square/p3:x')
  check_eq(p.y, 96, 'F - test_draw_square/p3:y')
  local p = drawing.points[drawing.shapes[1].vertices[4]]
  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

function test_move_point()
  io.write('\ntest_move_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_move_point/baseline/#shapes')
  check_eq(#drawing.points, 2, 'F - test_move_point/baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'F - test_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_move_point/baseline/p1:x')
  check_eq(p1.y, 6, 'F - test_move_point/baseline/p1:y')
  check_eq(p2.x, 35, 'F - test_move_point/baseline/p2:x')
  check_eq(p2.y, 36, 'F - test_move_point/baseline/p2:y')
  check_nil(p2.name, 'F - test_move_point/baseline/p2:name')
  -- enter 'move' mode without moving the mouse
  App.run_after_keychord('C-u')
  check_eq(Current_drawing_mode, 'move', 'F - test_move_point/mode:1')
  -- point is lifted
  check_eq(drawing.pending.mode, 'move', 'F - test_move_point/mode:2')
  check_eq(drawing.pending.target_point, p2, 'F - test_move_point/target')
  -- move point
  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_move_point/x')
  check_eq(p2.y, 44, 'F - test_move_point/y')
  -- exit 'move' mode
  App.run_after_mouse_click(Margin_left+26, Margin_top+Drawing_padding_top+44, 1)
  check_eq(Current_drawing_mode, 'line', 'F - test_move_point/mode:3')
  check_eq(drawing.pending, {}, 'F - test_move_point/pending')
end