123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830 |
- -- 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
|