summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
0 files changed, 0 insertions, 0 deletions
c6b602342beba3dc9ebef8748470018be6652a8'>^
8bbc1ff ^

29dac6a ^
81ecca8 ^
15acc38 ^
3b36093 ^
856c512 ^
51b4efa ^
2a0a770 ^
856c512 ^
0e0f36f ^
51b4efa ^
15acc38 ^
2a0a770 ^
15acc38 ^

dc3b18e ^
dc3b18e ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
2a0a770 ^

69c88da ^
2a0a770 ^

dc3b18e ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


dc3b18e ^

2a0a770 ^



856c512 ^
0e0f36f ^
51b4efa ^
15acc38 ^

48162b9 ^
29dac6a ^
8bbc1ff ^
2a0a770 ^


15acc38 ^

2a0a770 ^



dc3b18e ^
6894acc ^

6894acc ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
2a0a770 ^

69c88da ^
2a0a770 ^

6894acc ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


6894acc ^

2a0a770 ^



6894acc ^


6894acc ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
2a0a770 ^

69c88da ^
2a0a770 ^

6894acc ^
f61d426 ^
1d1a829 ^
f61d426 ^

8bbc1ff ^
2a0a770 ^



6894acc ^
2a0a770 ^

6894acc ^

3422d92 ^
3422d92 ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
2a0a770 ^

69c88da ^
2a0a770 ^

3422d92 ^
f61d426 ^
3422d92 ^
1d1a829 ^
f61d426 ^
8bbc1ff ^
2a0a770 ^
3422d92 ^

6894acc ^
6894acc ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
6894acc ^
f61d426 ^
1d1a829 ^
6894acc ^
2a0a770 ^
2b3e09c ^
6894acc ^


6894acc ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
2a0a770 ^

69c88da ^
2a0a770 ^

6894acc ^
f61d426 ^

2b3e09c ^
f61d426 ^
8bbc1ff ^
2a0a770 ^



6894acc ^
2a0a770 ^

6894acc ^


6894acc ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
2a0a770 ^

69c88da ^
2a0a770 ^

6894acc ^
f61d426 ^

2b3e09c ^
f61d426 ^
8bbc1ff ^
2a0a770 ^


6894acc ^
2a0a770 ^
6894acc ^
2a0a770 ^



6894acc ^
2b4e141 ^

2b4e141 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
81ecca8 ^
2a0a770 ^


69c88da ^
2a0a770 ^

2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
8bbc1ff ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^


2b4e141 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
81ecca8 ^
2a0a770 ^


69c88da ^
2a0a770 ^

2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
8bbc1ff ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^


2b4e141 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
81ecca8 ^
2a0a770 ^


69c88da ^
2a0a770 ^

2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
8bbc1ff ^
2a0a770 ^
2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^



2b4e141 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
81ecca8 ^
2a0a770 ^


69c88da ^
2a0a770 ^

2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
2b3e09c ^
2b4e141 ^
f61d426 ^
8bbc1ff ^
2a0a770 ^



2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
2a0a770 ^

2b4e141 ^
4f9789d ^

4f9789d ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
4f9789d ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


4f9789d ^

2a0a770 ^




4f9789d ^
1d1a829 ^
2a0a770 ^
2b3e09c ^
2a0a770 ^
4f9789d ^
2a0a770 ^
4f9789d ^
1d1a829 ^
2a0a770 ^

856c512 ^
0e0f36f ^
51b4efa ^
ab6eff4 ^
48162b9 ^
29dac6a ^
8bbc1ff ^
2a0a770 ^
4f9789d ^
93a9dfd ^
0ae94b0 ^























1d1a829 ^
0ae94b0 ^

1d1a829 ^
0ae94b0 ^


eae5c95 ^
























1d1a829 ^
eae5c95 ^








93a9dfd ^
93a9dfd ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


93a9dfd ^

2a0a770 ^



856c512 ^
0e0f36f ^
51b4efa ^
ab6eff4 ^
48162b9 ^
29dac6a ^
8bbc1ff ^

2a0a770 ^

81ecca8 ^
93a9dfd ^
1d1a829 ^
2a0a770 ^
93a9dfd ^
2a0a770 ^

93a9dfd ^
f61d426 ^
51b4efa ^
93a9dfd ^
2a0a770 ^

93a9dfd ^
f61d426 ^
2a0a770 ^

856c512 ^
0e0f36f ^
51b4efa ^
ab6eff4 ^
48162b9 ^
29dac6a ^
8bbc1ff ^
2a0a770 ^

93a9dfd ^
d077ce7 ^
26995dd ^
26995dd ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


81ecca8 ^
26995dd ^
1d1a829 ^
2a0a770 ^
26995dd ^
f61d426 ^
51b4efa ^
26995dd ^
2a0a770 ^
26995dd ^

d077ce7 ^
d077ce7 ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
f61d426 ^



8bbc1ff ^
2a0a770 ^


d077ce7 ^
f61d426 ^
1d1a829 ^
2a0a770 ^

856c512 ^
0e0f36f ^
51b4efa ^
ab6eff4 ^
48162b9 ^
29dac6a ^
2a0a770 ^
d077ce7 ^


d077ce7 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
f61d426 ^



8bbc1ff ^
2a0a770 ^


d077ce7 ^
f61d426 ^
1d1a829 ^
d077ce7 ^
2a0a770 ^

d077ce7 ^


d077ce7 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
d077ce7 ^
f61d426 ^
2b3e09c ^
d077ce7 ^
f61d426 ^
2b3e09c ^
d077ce7 ^
f61d426 ^
2b3e09c ^
d077ce7 ^
f61d426 ^
8bbc1ff ^
2a0a770 ^


d077ce7 ^
f61d426 ^
1d1a829 ^
d077ce7 ^
2a0a770 ^

d077ce7 ^


d077ce7 ^
2884f87 ^

8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
d077ce7 ^
f61d426 ^
2b3e09c ^
d077ce7 ^
f61d426 ^
2b3e09c ^
d077ce7 ^
f61d426 ^
8bbc1ff ^
2a0a770 ^


d077ce7 ^
f61d426 ^
1d1a829 ^
d077ce7 ^
2a0a770 ^
d077ce7 ^
1aa2590 ^

1aa2590 ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
1aa2590 ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


1aa2590 ^

2a0a770 ^





22ad537 ^
1aa2590 ^
1d1a829 ^
2b3e09c ^
1d1a829 ^
2a0a770 ^


22ad537 ^
1aa2590 ^
1d1a829 ^
8bbc1ff ^
1aa2590 ^
2a0a770 ^

856c512 ^
0e0f36f ^
51b4efa ^
21bd828 ^
48162b9 ^
29dac6a ^
8bbc1ff ^
2a0a770 ^
1aa2590 ^
b8d7774 ^

b8d7774 ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
f61d426 ^

8bbc1ff ^
2a0a770 ^


b8d7774 ^

2a0a770 ^




b8d7774 ^
1d1a829 ^
f61d426 ^
51b4efa ^
b8d7774 ^
2a0a770 ^

b8d7774 ^
f61d426 ^
2a0a770 ^
b8d7774 ^
1d1a829 ^

8bbc1ff ^
b8d7774 ^
2a0a770 ^


856c512 ^
0e0f36f ^
51b4efa ^
21bd828 ^
48162b9 ^
29dac6a ^
8bbc1ff ^
2a0a770 ^

b8d7774 ^
21bd828 ^

21bd828 ^
2884f87 ^

8abd986 ^
8bbc1ff ^
29dac6a ^
8bbc1ff ^
81ecca8 ^
f61d426 ^



8bbc1ff ^
2a0a770 ^


21bd828 ^
f61d426 ^
1d1a829 ^
2a0a770 ^

21bd828 ^
1d1a829 ^
8bbc1ff ^
21bd828 ^
2a0a770 ^


856c512 ^
0e0f36f ^
51b4efa ^
21bd828 ^
48162b9 ^
29dac6a ^
2a0a770 ^
21bd828 ^
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829



                                                                              
                                      
                                        
                                             

                                   
                               
                         
                                      
                                                                   
                               
                                 
                                           
                    
                                   
                              
                                                          
                                                               

   
                         
                                                                                                      

                                                                                                 
                               
                                                        
                               
                                            
                         

                                                                  
                                                                                            

                                                                
                

                                                                                                              
                                       


                                                     

                                                 



                            
                    
                                   
                              

                                                                              
                              
                               
                                       


                                                          

                                                 



                                 
   

                                    
                                                                                                      

                                                                                                 
                                                        
                               
                                                 
                         

                                                                  
                                                                                            

                                                                
                                                      

                                                                                                              
                                       


                                                             

                                                 



                              


                           
                                                                                                      

                                                                                                 
                                                        
                               
                                            
                         

                                                                  
                                                                                            

                                                                
                  
                                                                                                  
                                                   

                                                                                                                 
                                       



                                                          
                                                         

                                    

   
                             
                                                                                                      

                                                                                                 
                               
                                                        
                               
                                            
                         

                                                                  
                                                                                            

                                                                
                         
                                                                                                          
           
                                                           
                                                                                                              
                                       
                                         

   
                                                      
                                                                                                      

                                                                                                 
                                                        
                               
                                            
                         
                                                           
                                                                                                  
                                                 
                              
                                                                     
                                                                        


                                      
                                                                                                      

                                                                                                 
                                                        
                               
                                            
                         

                                                                  
                                                                                            

                                                                
                  

                                                                                                            
                                              
                                                                                                                 
                                       



                                                          
                                                         

                                    


                        
                                                                                                      

                                                                                                 
                                                        
                               
                                              
                         

                                                                  
                                                                                            

                                                                
                

                                                                                                            
                                                           
                                                                                                                             
                                       


                                                       
                               
                                    
                                           



                                                 
   

                            
                                                                                                      

                                                                                                 
                                                        
                               
                         


                                                                              
                                                                                            

                                                                
                
                                                                                                          
                                                               
                 
                                                                               
                                                            
                
                                                                                                              
                                       

                                          
                                 

                                               
                                             

                          
                                             

                           
                                             

                           


                              
                                                                                                      

                                                                                                 
                                                        
                               
                         


                                                                              
                                                                                            

                                                                
                
                                                                                                            
                                                                 
                            
                                                                               
                                              
                                     
                                                                               
                                              
                                                                           
                                                                                                              
                                       

                                                                                  
                                 

                                                 
                                             

                           
                                             

                           
                                             

                           
                                             

                           


                                           
                                                                                                      

                                                                                                 
                                                        
                               
                         


                                                                              
                                                                                            

                                                                
                
                                                                                                            
                                                                 
                            
                                                                               
                                              
                                     
                                                                               
                                              
                                       
                                                                                  
                                 

                                                   
                                               

                           
                                               

                           



                                                                                              
                                                                                                      

                                                                                                 
                                                        
                               
                         


                                                                              
                                                                                            

                                                                
                
                                                                                                            
                                                              
                            
                                                                               
                                              
                                     
                                                                               
                                              
                                                                 
                                                                                                              
                                       



                                                                                  
                                                         

                           
                                                         

                           
                                                         

                           
                                                         

                           
   

                          
                                 

                                                                                                 
                               
                                                        
                               
                                            
                         
                

                                                                                                              
                                       


                                                              

                                                 




                                        
                                               
                                                   
                                                               
                                              
                                  
                         
                                                               
                     
                                                           

                                                               
                    
                                   
                              
                    
                              
                               
                                                               
                                
   
 























                                                                                                              
                                                   

                                                               
                                                                 


             
























                                                                                                              
                                                   








                                                                                      
                          
                                 

                                                                                                 
                               
                                                        
                               
                                            
                         

                                                                                                              
                                       


                                                              

                                                 



                                     
                    
                                   
                              
                          
                              
                               

                                                               

                              
                         
                                               
                                                   
                                                               
                    

                                                      
               
                                                                               
                                 
                                                 

                         
                     
                                                                                                            

                                                               
                    
                                   
                              
                    
                              
                               
                                                               

                              
   
 
                                            
                                           

                                                                                                 
                               
                                                        
                               
                                                 
                         

                                                                                                              
                                       


                                                                   
                         
                      
                                                   
                                                               
               
                                                                               
                                 
                                
                                                              

   
                                     
                                                         

                                                                                                 
                               
                                                        
                               
                                            
                         



                                                                                                              
                                       


                                                              
                                         
                                                                               
                                                   

                                                        
                       
                                   
                              
                                                    
                              
                               
                                                    


                                               
                                                         

                                                                                                 
                                                        
                               
                                            
                         



                                                                                                              
                                       


                                                              
                                         
                                                                               
                                                   
                              

                                                        


                                         
                                                         

                                                                                                 
                                                        
                               
                                            
                         
                
                                                                                                          
                                                               
                 
                                                                               
                                                            
                
                                                                               
                                                            
                 
                                                                                                              
                                       


                                                               
                                
                                                                               
                                                   
                                  

                                                      


                                         
                                                         

                                                                                                 
                                                        
                               
                                            
                         
                
                                                                                                          
                                                               
                 
                                                                               
                                                            
                
                                                                                                              
                                       


                                                               
                                
                                                                               
                                                   
                                                             
                                                      
   

                               
                                 

                                                                                                 
                               
                                                        
                               
                                            
                         
                

                                                                                                              
                                       


                                                              

                                                 





                                                          
                                                    
                                               
                                                   
                                              
                                                           


                                                                 
                                                    
         
                                                   
                                       
                                                 

                                                                                  
                    
                                   
                              
                  
                              
                               
                                                               
                               
   

                               
                                 

                                                                                                 
                               
                                                        
                               
                                            
                         

                                                                                                              
                                       


                                                              

                                                 




                                        
            
                                                   
                                                                               
                                 
                                                 

                         
                     
                                                                                                            
                                                        
         

                                                                               
                                       
                                                 


                                                        
                    
                                   
                              
                  
                              
                               
                                                               

                              
   

                                 
                                                         

                                                                                                 
                               
                                                        
                               
                                            
                         



                                                                                                              
                                       


                                                              
                                         
                                                                               
                                                   

                                                        
         
                                                   
                                       
                                                 


                                                        
                    
                                   
                              
                  
                              
                               
                                                    
   
-- 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_creating_drawing_saves()
  App.screen.init{width=800, height=600}
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{}
  Text.redraw_all(Editor_state)
  edit.draw(Editor_state)
  -- click on button to create drawing
  edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)
  -- file not immediately saved
  edit.update(Editor_state, 0.01)
  check_nil(App.filesystem['foo'], 'early')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- filesystem contains drawing and an empty line of text
  check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'check')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- draw a line
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 2, '#points')
  check_eq(drawing.shapes[1].mode, 'line', 'shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'p1:x')
  check_eq(p1.y, 6, 'p1:y')
  check_eq(p2.x, 35, 'p2:x')
  check_eq(p2.y, 36, 'p2:y')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- The format on disk isn't perfectly stable. Table fields can be reordered.
  -- So just reload from disk to verify.
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'save/#shapes')
  check_eq(#drawing.points, 2, 'save/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'save/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'save/p1:x')
  check_eq(p1.y, 6, 'save/p1:y')
  check_eq(p2.x, 35, 'save/p2:x')
  check_eq(p2.y, 36, 'save/p2:y')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'manhattan'
  edit.draw(Editor_state)
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- draw a line that is more horizontal than vertical
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 2, '#points')
  check_eq(drawing.shapes[1].mode, 'manhattan', 'shape_mode')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'p1:x')
  check_eq(p1.y, 6, 'p1:y')
  check_eq(p2.x, 35, 'p2:x')
  check_eq(p2.y, p1.y, 'p2:y')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- draw a circle
  App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4)  -- hover on drawing
  edit.run_after_keychord(Editor_state, 'C-o', 'o')
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 1, '#points')
  check_eq(drawing.shapes[1].mode, 'circle', 'shape_mode')
  check_eq(drawing.shapes[1].radius, 30, 'radius')
  local center = drawing.points[drawing.shapes[1].center]
  check_eq(center.x, 35, 'center:x')
  check_eq(center.y, 36, 'center:y')
end

function test_cancel_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- start drawing a line
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  -- cancel
  edit.run_after_keychord(Editor_state, 'escape', 'escape')
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 0, '#shapes')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- hover over drawing and press 'o' without holding mouse
  App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4)  -- hover on drawing
  edit.run_after_keychord(Editor_state, 'o', 'o')
  -- no change to drawing mode
  check_eq(Editor_state.current_drawing_mode, 'line', 'drawing_mode')
  -- no change to text either because we didn't run the text_input event
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- draw a circle
  App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4)  -- hover on drawing
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_text_input(Editor_state, 'o')
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 1, '#points')
  check_eq(drawing.shapes[1].mode, 'circle', 'shape_mode')
  check_eq(drawing.shapes[1].radius, 30, 'radius')
  local center = drawing.points[drawing.shapes[1].center]
  check_eq(center.x, 35, 'center:x')
  check_eq(center.y, 36, 'center:y')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'circle'
  edit.draw(Editor_state)
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- draw an arc
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  App.mouse_move(Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_text_input(Editor_state, 'a')  -- arc mode
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35+50, Editor_state.top+Drawing_padding_top+36+50, 1)  -- 45°
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 1, '#points')
  check_eq(drawing.shapes[1].mode, 'arc', 'shape_mode')
  local arc = drawing.shapes[1]
  check_eq(arc.radius, 30, 'radius')
  local center = drawing.points[arc.center]
  check_eq(center.x, 35, 'center:x')
  check_eq(center.y, 36, 'center:y')
  check_eq(arc.start_angle, 0, 'start:angle')
  check_eq(arc.end_angle, math.pi/4, 'end:angle')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  edit.draw(Editor_state)
  check_eq(Editor_state.current_drawing_mode, 'line', 'baseline/drawing_mode')
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- first point
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_text_input(Editor_state, 'g')  -- polygon mode
  -- second point
  App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_text_input(Editor_state, 'p')  -- add point
  -- final point
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 3, 'vertices')
  local shape = drawing.shapes[1]
  check_eq(shape.mode, 'polygon', 'shape_mode')
  check_eq(#shape.vertices, 3, 'vertices')
  local p = drawing.points[shape.vertices[1]]
  check_eq(p.x, 5, 'p1:x')
  check_eq(p.y, 6, 'p1:y')
  local p = drawing.points[shape.vertices[2]]
  check_eq(p.x, 65, 'p2:x')
  check_eq(p.y, 36, 'p2:y')
  local p = drawing.points[shape.vertices[3]]
  check_eq(p.x, 35, 'p3:x')
  check_eq(p.y, 26, 'p3:y')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  edit.draw(Editor_state)
  check_eq(Editor_state.current_drawing_mode, 'line', 'baseline/drawing_mode')
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- first point
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_text_input(Editor_state, 'r')  -- rectangle mode
  -- second point/first edge
  App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
  edit.run_after_text_input(Editor_state, 'p')
  -- override second point/first edge
  App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)
  edit.run_after_text_input(Editor_state, 'p')
  -- release (decides 'thickness' of rectangle perpendicular to first edge)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 5, '#points')  -- currently includes every point added
  local shape = drawing.shapes[1]
  check_eq(shape.mode, 'rectangle', 'shape_mode')
  check_eq(#shape.vertices, 4, 'vertices')
  local p = drawing.points[shape.vertices[1]]
  check_eq(p.x, 35, 'p1:x')
  check_eq(p.y, 36, 'p1:y')
  local p = drawing.points[shape.vertices[2]]
  check_eq(p.x, 75, 'p2:x')
  check_eq(p.y, 76, 'p2:y')
  local p = drawing.points[shape.vertices[3]]
  check_eq(p.x, 70, 'p3:x')
  check_eq(p.y, 81, 'p3:y')
  local p = drawing.points[shape.vertices[4]]
  check_eq(p.x, 30, 'p4:x')
  check_eq(p.y, 41, 'p4:y')
end

function test_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=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  edit.draw(Editor_state)
  check_eq(Editor_state.current_drawing_mode, 'line', 'baseline/drawing_mode')
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- first point
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_text_input(Editor_state, 'r')  -- rectangle mode
  -- second point/first edge
  App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
  edit.run_after_text_input(Editor_state, 'p')
  -- override second point/first edge
  App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)
  edit.run_after_text_input(Editor_state, 'p')
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.points, 3, '#points')  -- currently includes every point added
  local pending = drawing.pending
  check_eq(pending.mode, 'rectangle', 'shape_mode')
  check_eq(#pending.vertices, 2, 'vertices')
  local p = drawing.points[pending.vertices[1]]
  check_eq(p.x, 35, 'p1:x')
  check_eq(p.y, 36, 'p1:y')
  local p = drawing.points[pending.vertices[2]]
  check_eq(p.x, 75, 'p2:x')
  check_eq(p.y, 76, '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()
  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  edit.draw(Editor_state)
  check_eq(Editor_state.current_drawing_mode, 'line', 'baseline/drawing_mode')
  check_eq(#Editor_state.lines, 2, 'baseline/#lines')
  check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
  check_eq(Text.starty(Editor_state, 1), Editor_state.top+Drawing_padding_top, 'baseline/y')
  check_eq(Editor_state.lines[1].h, 128, 'baseline/y')
  check_eq(#Editor_state.lines[1].shapes, 0, 'baseline/#shapes')
  -- first point
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_text_input(Editor_state, 's')  -- square mode
  -- second point/first edge
  App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
  edit.run_after_text_input(Editor_state, 'p')
  -- override second point/first edge
  App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+66)
  edit.run_after_text_input(Editor_state, 'p')
  -- release (decides which side of first edge to draw square on)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, '#shapes')
  check_eq(#drawing.points, 5, '#points')  -- currently includes every point added
  check_eq(drawing.shapes[1].mode, 'square', 'shape_mode')
  check_eq(#drawing.shapes[1].vertices, 4, 'vertices')
  local p = drawing.points[drawing.shapes[1].vertices[1]]
  check_eq(p.x, 35, 'p1:x')
  check_eq(p.y, 36, 'p1:y')
  local p = drawing.points[drawing.shapes[1].vertices[2]]
  check_eq(p.x, 65, 'p2:x')
  check_eq(p.y, 66, 'p2:y')
  local p = drawing.points[drawing.shapes[1].vertices[3]]
  check_eq(p.x, 35, 'p3:x')
  check_eq(p.y, 96, 'p3:y')
  local p = drawing.points[drawing.shapes[1].vertices[4]]
  check_eq(p.x, 5, 'p4:x')
  check_eq(p.y, 66, 'p4:y')
end

function test_name_point()
  -- create a drawing with a line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- draw a line
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'baseline/p1:x')
  check_eq(p1.y, 6, 'baseline/p1:y')
  check_eq(p2.x, 35, 'baseline/p2:x')
  check_eq(p2.y, 36, 'baseline/p2:y')
  check_nil(p2.name, 'baseline/p2:name')
  -- enter 'name' mode without moving the mouse
  edit.run_after_keychord(Editor_state, 'C-n', 'n')
  check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
  edit.run_after_text_input(Editor_state, 'A')
  check_eq(p2.name, 'A', 'check1')
  -- still in 'name' mode
  check_eq(Editor_state.current_drawing_mode, 'name', 'mode:2')
  -- exit 'name' mode
  edit.run_after_keychord(Editor_state, 'return', 'return')
  check_eq(Editor_state.current_drawing_mode, 'line', 'mode:3')
  check_eq(p2.name, 'A', 'check2')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- change is saved
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
  check_eq(p2.name, 'A', 'save')
end

function test_name_point_then_hit_backspace()
  -- create a drawing with a line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- draw a line
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'baseline/p1:x')
  check_eq(p1.y, 6, 'baseline/p1:y')
  check_eq(p2.x, 35, 'baseline/p2:x')
  check_eq(p2.y, 36, 'baseline/p2:y')
  check_nil(p2.name, 'baseline/p2:name')
  -- enter 'name' mode without moving the mouse
  edit.run_after_keychord(Editor_state, 'C-n', 'n')
  check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
  -- hit backspace
  edit.run_after_keychord(Editor_state, 'backspace', 'backspace')
  -- no crash
end

function test_name_point_then_exit_drawing()
  -- create a drawing with a line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  edit.check_locs(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- draw a line
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'baseline/p1:x')
  check_eq(p1.y, 6, 'baseline/p1:y')
  check_eq(p2.x, 35, 'baseline/p2:x')
  check_eq(p2.y, 36, 'baseline/p2:y')
  check_nil(p2.name, 'baseline/p2:name')
  -- enter 'name' mode without moving the mouse
  edit.run_after_keychord(Editor_state, 'C-n', 'n')
  check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
  -- click outside the drawing
  edit.run_after_mouse_click(Editor_state, App.screen.width-5, App.screen.height-5, 1)
  -- press a key
  edit.run_after_text_input(Editor_state, 'a')
  -- key goes to text
  check_eq(Editor_state.lines[2].data, 'a')
end

function test_move_point()
  -- create a drawing with a line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'baseline/p1:x')
  check_eq(p1.y, 6, 'baseline/p1:y')
  check_eq(p2.x, 35, 'baseline/p2:x')
  check_eq(p2.y, 36, 'baseline/p2:y')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- line is saved to disk
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  local drawing = Editor_state.lines[1]
  local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
  check_eq(p2.x, 35, 'save/x')
  check_eq(p2.y, 36, 'save/y')
  edit.draw(Editor_state)
  -- enter 'move' mode without moving the mouse
  edit.run_after_keychord(Editor_state, 'C-u', 'u')
  check_eq(Editor_state.current_drawing_mode, 'move', 'mode:1')
  -- point is lifted
  check_eq(drawing.pending.mode, 'move', 'mode:2')
  check_eq(drawing.pending.target_point, p2, 'target')
  -- move point
  App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
  edit.update(Editor_state, 0.05)
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p2.x, 26, 'x')
  check_eq(p2.y, 44, 'y')
  -- exit 'move' mode
  edit.run_after_mouse_click(Editor_state, Editor_state.left+26, Editor_state.top+Drawing_padding_top+44, 1)
  check_eq(Editor_state.current_drawing_mode, 'line', 'mode:3')
  check_eq(drawing.pending, {}, 'pending')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- change is saved
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
  check_eq(p2.x, 26, 'save/x')
  check_eq(p2.y, 44, 'save/y')
end

function test_move_point_on_manhattan_line()
  -- create a drawing with a manhattan line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'manhattan'
  edit.draw(Editor_state)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+46, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'manhattan', 'baseline/shape:1')
  edit.draw(Editor_state)
  -- enter 'move' mode
  edit.run_after_keychord(Editor_state, 'C-u', 'u')
  check_eq(Editor_state.current_drawing_mode, 'move', 'mode:1')
  -- move point
  App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
  edit.update(Editor_state, 0.05)
  -- line is no longer manhattan
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
end

function test_delete_lines_at_point()
  -- create a drawing with two lines connected at a point
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 2, 'baseline/#shapes')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  check_eq(drawing.shapes[2].mode, 'line', 'baseline/shape:2')
  -- hover on the common point and delete
  App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_keychord(Editor_state, 'C-d', 'd')
  check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
  check_eq(drawing.shapes[2].mode, 'deleted', 'shape:2')
  -- wait for some time
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- deleted points disappear after file is reloaded
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  check_eq(#Editor_state.lines[1].shapes, 0, 'save')
end

function test_delete_line_under_mouse_pointer()
  -- create a drawing with two lines connected at a point
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 2, 'baseline/#shapes')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  check_eq(drawing.shapes[2].mode, 'line', 'baseline/shape:2')
  -- hover on one of the lines and delete
  App.mouse_move(Editor_state.left+25, Editor_state.top+Drawing_padding_top+26)
  edit.run_after_keychord(Editor_state, 'C-d', 'd')
  -- only that line is deleted
  check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
  check_eq(drawing.shapes[2].mode, 'line', 'shape:2')
end

function test_delete_point_from_polygon()
  -- create a drawing with two lines connected at a point
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- first point
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_text_input(Editor_state, 'g')  -- polygon mode
  -- second point
  App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_text_input(Editor_state, 'p')  -- add point
  -- third point
  App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26)
  edit.run_after_text_input(Editor_state, 'p')  -- add point
  -- fourth point
  edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(drawing.shapes[1].mode, 'polygon', 'baseline/mode')
  check_eq(#drawing.shapes[1].vertices, 4, 'baseline/vertices')
  -- hover on a point and delete
  App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26)
  edit.run_after_keychord(Editor_state, 'C-d', 'd')
  -- just the one point is deleted
  check_eq(drawing.shapes[1].mode, 'polygon', 'shape')
  check_eq(#drawing.shapes[1].vertices, 3, 'vertices')
end

function test_delete_point_from_polygon()
  -- create a drawing with two lines connected at a point
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- first point
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_text_input(Editor_state, 'g')  -- polygon mode
  -- second point
  App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_text_input(Editor_state, 'p')  -- add point
  -- third point
  edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(drawing.shapes[1].mode, 'polygon', 'baseline/mode')
  check_eq(#drawing.shapes[1].vertices, 3, 'baseline/vertices')
  -- hover on a point and delete
  App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_keychord(Editor_state, 'C-d', 'd')
  -- there's < 3 points left, so the whole polygon is deleted
  check_eq(drawing.shapes[1].mode, 'deleted', 'check')
end

function test_undo_name_point()
  -- create a drawing with a line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  -- draw a line
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'baseline/p1:x')
  check_eq(p1.y, 6, 'baseline/p1:y')
  check_eq(p2.x, 35, 'baseline/p2:x')
  check_eq(p2.y, 36, 'baseline/p2:y')
  check_nil(p2.name, 'baseline/p2:name')
  check_eq(#Editor_state.history, 1, 'baseline/history:1')
--?   print('a', Editor_state.lines.current_drawing)
  -- enter 'name' mode without moving the mouse
  edit.run_after_keychord(Editor_state, 'C-n', 'n')
  edit.run_after_text_input(Editor_state, 'A')
  edit.run_after_keychord(Editor_state, 'return', 'return')
  check_eq(p2.name, 'A', 'baseline')
  check_eq(#Editor_state.history, 3, 'baseline/history:2')
  check_eq(Editor_state.next_history, 4, 'baseline/next_history')
--?   print('b', Editor_state.lines.current_drawing)
  -- undo
  edit.run_after_keychord(Editor_state, 'C-z', 'z')
  local drawing = Editor_state.lines[1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(Editor_state.next_history, 3, 'next_history')
  check_eq(p2.name, '', 'undo')  -- not quite what it was before, but close enough
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- undo is saved
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
  check_eq(p2.name, '', 'save')
end

function test_undo_move_point()
  -- create a drawing with a line
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 1, 'baseline/#shapes')
  check_eq(#drawing.points, 2, 'baseline/#points')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  local p1 = drawing.points[drawing.shapes[1].p1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p1.x, 5, 'baseline/p1:x')
  check_eq(p1.y, 6, 'baseline/p1:y')
  check_eq(p2.x, 35, 'baseline/p2:x')
  check_eq(p2.y, 36, 'baseline/p2:y')
  check_nil(p2.name, 'baseline/p2:name')
  -- move p2
  edit.run_after_keychord(Editor_state, 'C-u', 'u')
  App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
  edit.update(Editor_state, 0.05)
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(p2.x, 26, 'x')
  check_eq(p2.y, 44, 'y')
  -- exit 'move' mode
  edit.run_after_mouse_click(Editor_state, Editor_state.left+26, Editor_state.top+Drawing_padding_top+44, 1)
  check_eq(Editor_state.next_history, 4, 'next_history')
  -- undo
  edit.run_after_keychord(Editor_state, 'C-z', 'z')
  edit.run_after_keychord(Editor_state, 'C-z', 'z')  -- bug: need to undo twice
  local drawing = Editor_state.lines[1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(Editor_state.next_history, 2, 'next_history')
  check_eq(p2.x, 35, 'x')
  check_eq(p2.y, 36, 'y')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- undo is saved
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
  check_eq(p2.x, 35, 'save/x')
  check_eq(p2.y, 36, 'save/y')
end

function test_undo_delete_point()
  -- create a drawing with two lines connected at a point
  App.screen.init{width=Test_margin_left+256, height=300}  -- drawing coordinates 1:1 with pixels
  Editor_state = edit.initialize_test_state()
  Editor_state.filename = 'foo'
  Editor_state.lines = load_array{'```lines', '```', ''}
  Text.redraw_all(Editor_state)
  Editor_state.current_drawing_mode = 'line'
  edit.draw(Editor_state)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
  edit.run_after_mouse_release(Editor_state, Editor_state.left+55, Editor_state.top+Drawing_padding_top+26, 1)
  local drawing = Editor_state.lines[1]
  check_eq(#drawing.shapes, 2, 'baseline/#shapes')
  check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
  check_eq(drawing.shapes[2].mode, 'line', 'baseline/shape:2')
  -- hover on the common point and delete
  App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+36)
  edit.run_after_keychord(Editor_state, 'C-d', 'd')
  check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
  check_eq(drawing.shapes[2].mode, 'deleted', 'shape:2')
  -- undo
  edit.run_after_keychord(Editor_state, 'C-z', 'z')
  local drawing = Editor_state.lines[1]
  local p2 = drawing.points[drawing.shapes[1].p2]
  check_eq(Editor_state.next_history, 3, 'next_history')
  check_eq(drawing.shapes[1].mode, 'line', 'shape:1')
  check_eq(drawing.shapes[2].mode, 'line', 'shape:2')
  -- wait until save
  Current_time = Current_time + 3.1
  edit.update(Editor_state, 0)
  -- undo is saved
  load_from_disk(Editor_state)
  Text.redraw_all(Editor_state)
  check_eq(#Editor_state.lines[1].shapes, 2, 'save')
end