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)
edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)
edit.update(Editor_state, 0.01)
check_nil(App.filesystem['foo'], 'early')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'check')
end
function test_draw_line()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) 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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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)
App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) edit.run_after_keychord(Editor_state, 'o', 'o')
check_eq(Editor_state.current_drawing_mode, 'line', 'drawing_mode')
end
function test_draw_circle_mid_stroke()
App.screen.init{width=Test_margin_left+256, height=300} 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')
App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) 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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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') edit.run_after_mouse_release(Editor_state, Editor_state.left+35+50, Editor_state.top+Drawing_padding_top+36+50, 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, '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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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, '5')
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, 1, '#shapes')
check_eq(#drawing.points, 2, 'vertices')
local shape = drawing.shapes[1]
check_eq(shape.mode, 'polygon', 'shape_mode')
check_eq(shape.num_vertices, 5, 'vertices')
end
function test_draw_rectangle()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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') App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
edit.run_after_text_input(Editor_state, 'p')
App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)
edit.run_after_text_input(Editor_state, 'p')
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') 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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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') App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
edit.run_after_text_input(Editor_state, 'p')
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') 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')
end
function test_name_point()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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')
check_eq(Editor_state.current_drawing_mode, 'name', 'mode:2')
edit.run_after_keychord(Editor_state, 'return', 'return')
check_eq(Editor_state.current_drawing_mode, 'line', 'mode:3')
check_eq(p2.name, 'A', 'check2')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
edit.run_after_keychord(Editor_state, 'C-n', 'n')
check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
edit.run_after_keychord(Editor_state, 'backspace', 'backspace')
end
function test_name_point_then_exit_drawing()
App.screen.init{width=Test_margin_left+256, height=300} 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)
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')
edit.run_after_keychord(Editor_state, 'C-n', 'n')
check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
edit.run_after_mouse_click(Editor_state, App.screen.width-5, App.screen.height-5, 1)
edit.run_after_text_input(Editor_state, 'a')
check_eq(Editor_state.lines[2].data, 'a')
end
function test_move_point()
App.screen.init{width=Test_margin_left+256, height=300} 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')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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)
edit.run_after_keychord(Editor_state, 'C-u', 'u')
check_eq(Editor_state.current_drawing_mode, 'move', 'mode:1')
check_eq(drawing.pending.mode, 'move', 'mode:2')
check_eq(drawing.pending.target_point, p2, 'target')
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')
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')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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)
edit.run_after_keychord(Editor_state, 'C-u', 'u')
check_eq(Editor_state.current_drawing_mode, 'move', 'mode:1')
App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
edit.update(Editor_state, 0.05)
check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
end
function test_delete_lines_at_point()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
App.mouse_move(Editor_state.left+25, Editor_state.top+Drawing_padding_top+26)
edit.run_after_keychord(Editor_state, 'C-d', 'd')
check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
check_eq(drawing.shapes[2].mode, 'line', 'shape:2')
end
function test_undo_name_point()
App.screen.init{width=Test_margin_left+256, height=300} 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')
check_eq(#Editor_state.history, 1, 'baseline/history:1')
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')
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') Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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')
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')
edit.run_after_keychord(Editor_state, 'C-z', 'z')
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, 2, 'next_history')
check_eq(p2.x, 35, 'x')
check_eq(p2.y, 36, 'y')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
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()
App.screen.init{width=Test_margin_left+256, height=300} 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')
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')
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')
Current_time = Current_time + 3.1
edit.update(Editor_state, 0)
load_from_disk(Editor_state)
Text.redraw_all(Editor_state)
check_eq(#Editor_state.lines[1].shapes, 2, 'save')
end