2022-06-14 18:28:09 +01:00
|
|
|
-- 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.
|
|
|
|
|
2022-06-15 06:06:08 +01:00
|
|
|
function test_creating_drawing_saves()
|
fix a crash involving mouse and drawings
Thanks Alex Schroeder for reporting this crash. The scenario:
* Edit a file like say this repo's Readme.
* The second line is empty and there's a '+' to insert a drawing.
Click on that.
* Resize the window so just the first line of text and the drawing are
visible.
* Close the window.
* Reopen lines.love, it will reopen the same file.
* Click on the left margin to the left of the drawing.
Before this commit these steps yielded the following crash:
Error: bad argument #1 to 'len' (string expected, got nil)
text.lua:626: in function 'pos_at_end_of_screen_line'
edit.lua:298: in function 'mouse_press'
There were two distinct problems here:
1. State.screen_bottom1 is not required to point to a text line, it
could just as well be a drawing. I have been sloppy in handling that.
2. The bug was partially masked (the need to close and reopen the
window) by a second bug: inserting a drawing was not invalidating the
cache I save of starty coordinates for each line. (I've inserted and
deleted starty invalidations a few times in the past, but it looks
like I'd never had one in this particular location edit.draw before.)
How did these issues get missed for years?
- Even though I use lines.love on a daily basis, it turns out I don't
actually create line drawings all that often.
- When I do, I'm still living in files that are mostly text with only
an occasional drawing.
- I keep my windows fairly large.
Between these 3 patterns, the odds of running into a drawing as the
first or bottom-most line on the screen were fairly small. And then I
had to interact with it. I suspect I tend to interact with drawings
after centering them vertically.
---
Bug #1 in particular has some interesting past history.
* Near the start of the project, when I implemented line-wrapping I
started saving screen_bottom, the bottom-most line displayed on
screen. I did this so I could scroll down easily just by assigning
`screen_top = screen_bottom`. (On the other hand, scrolling up still
required some work. I should perhaps get rid of it and just compute
scrolls from scratch each time.)
* Also near the start of the project, I supported selecting text by a
complex state machine spanning keypress, mouse press and mouse
release:
mouse click (press and immediate release) moves cursor
mouse drag (press and much later release) creates selection
shift-click selects from current cursor to click location
shift-movement creates/grows a selection
* On 2023-06-01, inscript reported a bug. Opening a window with just a
little bit of text (lots of unused space in the window), selecting all
the text and then clicking below all the text would crash the editor.
To fix this I added code at the bottom of edit.mouse_press which
computed the final visible line+pos location and used that in the
cursor-move/text-selection state machine. It did this computation
based on.. screen_bottom. But I didn't notice that screen_bottom could
be a drawing (which has no pos). This commit's bug/regression was
created.
* On 2023-09-20, Matt Wynne encountered a crash which got me to realize
I need code at the bottom of edit.mouse_release symmetric to the code
at the bottom of edit.mouse_press. I still didn't notice that
screen_bottom could be a drawing.
So in fixing inscript's bug report, I introduced (at least) 2
regressions, because I either had no idea or quickly forgot that
screen_bottom could point at a drawing.
While I created regressions, the underlying mental bug feels new. I just
never focused on the fact that screen_bottom could point at a drawing.
This past history makes me suspicious of my mouse_press/mouse_release
code. I think I'm going to get rid of screen_bottom entirely as a
concept. I'll still have to be careful though about the remaining
locations and which of them are allowed to point at drawings:
- cursor and selection are not allowed to point at drawings
- screen_top and screen_bottom are allowed to point at drawings
I sometimes copy between these 4 location variables. Auditing shows no
gaps where cursor could ever end up pointing at a drawing. It's just
when I started using screen_bottom for a whole new purpose (in
the mouse_press/release state machine) that I went wrong.
I should also try getting rid of starty entirely. Is it _really_ needed
for a responsive editor? I think I introduced it back when I didn't know
what I was doing with LÖVE and was profligately creating text objects
willy-nilly just to compute widths.
Getting rid of these two fairly global bits of mutable state will
hopefully make lines much more robust when the next person tries it out
in 6 months :-/ X-(
Thanks everyone for the conversation around this bug:
https://merveilles.town/@akkartik/112567862542495637
---
Bug #2 has some complexity as well, and might lead to some follow-on
cleanup.
When I click on the button to insert a new drawing, the mouse_release
hook triggers and moves the cursor below the new drawing. This is
desirable, but I'd never noticed this happy accident. It stops working
when I invalidate starty for all lines (which gets recomputed and cached
for all visible lines on every frame).
Fixing this caused a couple of unit tests start crashing for 2 reasons
that required their own minor fixes:
- My emulated mouse press and release didn't have an intervening
frame and so mouse_release no longer receives starty. Now I've added
a call to edit.draw() between press and release.
This might actually bite someone for real someday, if they're
running on a slow computer or something like that. I've tried to
click really fast but I can't seem to put mouse_press and release in
the same frame (assuming 30 frames per second)
- My tests' window dimensions often violate my constraint that the
screen always have one line of text for showing the cursor. They're
unrealistically small or have a really wide aspect ratio (width 2x
of height). I suspect lines.love will itself crash in those
situations, but hopefully they're unrealistic. Hmm, I wonder what
would happen if someone maximized in a 16:9 screen, that's almost
2x.. Anyways, I've cleaned a couple of tests up, but might need to
fix up others at some point. I'd have to rejigger all my brittle
line-wrapping tests if I modify the screen width :-/ X-(
2024-06-09 21:17:55 +01:00
|
|
|
App.screen.init{width=800, height=600}
|
2022-07-16 06:12:25 +01:00
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.filename = 'foo'
|
|
|
|
Editor_state.lines = load_array{}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-15 06:06:08 +01:00
|
|
|
-- click on button to create drawing
|
2022-07-13 02:29:00 +01:00
|
|
|
edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)
|
2022-06-17 23:42:53 +01:00
|
|
|
-- file not immediately saved
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0.01)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_nil(App.filesystem['foo'], 'early')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:06:08 +01:00
|
|
|
-- filesystem contains drawing and an empty line of text
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'check')
|
2022-06-15 06:06:08 +01:00
|
|
|
end
|
|
|
|
|
2022-06-14 18:28:09 +01:00
|
|
|
function test_draw_line()
|
|
|
|
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines, 2, 'baseline/#lines')
|
|
|
|
check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
|
|
|
|
check_eq(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 18:28:09 +01:00
|
|
|
-- draw a line
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, '#shapes')
|
|
|
|
check_eq(#drawing.points, 2, '#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'shape:1')
|
2022-06-14 18:28:09 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:06:08 +01:00
|
|
|
-- The format on disk isn't perfectly stable. Table fields can be reordered.
|
|
|
|
-- So just reload from disk to verify.
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, 'save/#shapes')
|
|
|
|
check_eq(#drawing.points, 2, 'save/#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'save/shape:1')
|
2022-06-15 06:06:08 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-14 18:28:09 +01:00
|
|
|
end
|
2022-06-14 19:19:19 +01:00
|
|
|
|
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'manhattan'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines, 2, 'baseline/#lines')
|
|
|
|
check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
|
|
|
|
check_eq(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 19:19:19 +01:00
|
|
|
-- draw a line that is more horizontal than vertical
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, '#shapes')
|
|
|
|
check_eq(#drawing.points, 2, '#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'manhattan', 'shape_mode')
|
2022-06-14 19:19:19 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-14 19:19:19 +01:00
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines, 2, 'baseline/#lines')
|
|
|
|
check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
|
|
|
|
check_eq(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 19:19:19 +01:00
|
|
|
-- draw a circle
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawing
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-o', 'o')
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-14 19:19:19 +01:00
|
|
|
local center = drawing.points[drawing.shapes[1].center]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(center.x, 35, 'center:x')
|
|
|
|
check_eq(center.y, 36, 'center:y')
|
2022-06-14 19:19:19 +01:00
|
|
|
end
|
|
|
|
|
2022-07-05 19:04:39 +01:00
|
|
|
function test_cancel_stroke()
|
|
|
|
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines, 2, 'baseline/#lines')
|
|
|
|
check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
|
|
|
|
check_eq(Editor_state.line_cache[1].starty, 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')
|
2022-07-05 19:04:39 +01:00
|
|
|
-- start drawing a line
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
|
2022-07-05 19:04:39 +01:00
|
|
|
-- cancel
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'escape', 'escape')
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 0, '#shapes')
|
2022-07-05 19:04:39 +01:00
|
|
|
end
|
|
|
|
|
2022-06-14 19:19:19 +01:00
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-14 19:19:19 +01:00
|
|
|
-- hover over drawing and press 'o' without holding mouse
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+4, Editor_state.top+Drawing_padding_top+4) -- hover on drawing
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'o', 'o')
|
2022-06-14 19:19:19 +01:00
|
|
|
-- no change to drawing mode
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'line', 'drawing_mode')
|
2022-12-24 01:16:19 +00:00
|
|
|
-- no change to text either because we didn't run the text_input event
|
2022-06-14 19:19:19 +01:00
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines, 2, 'baseline/#lines')
|
|
|
|
check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
|
|
|
|
check_eq(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 19:19:19 +01:00
|
|
|
-- draw a circle
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'o')
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+35+30, Editor_state.top+Drawing_padding_top+36, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-14 19:19:19 +01:00
|
|
|
local center = drawing.points[drawing.shapes[1].center]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(center.x, 35, 'center:x')
|
|
|
|
check_eq(center.y, 36, 'center:y')
|
2022-06-14 19:19:19 +01:00
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'circle'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines, 2, 'baseline/#lines')
|
|
|
|
check_eq(Editor_state.lines[1].mode, 'drawing', 'baseline/mode')
|
|
|
|
check_eq(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 19:19:19 +01:00
|
|
|
-- draw an arc
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'a') -- arc mode
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+35+50, Editor_state.top+Drawing_padding_top+36+50, 1) -- 45°
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, '#shapes')
|
|
|
|
check_eq(#drawing.points, 1, '#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'arc', 'shape_mode')
|
2022-06-14 19:19:19 +01:00
|
|
|
local arc = drawing.shapes[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(arc.radius, 30, 'radius')
|
2022-06-14 19:19:19 +01:00
|
|
|
local center = drawing.points[arc.center]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-14 19:19:19 +01:00
|
|
|
end
|
2022-06-14 22:59:09 +01:00
|
|
|
|
|
|
|
function test_draw_polygon()
|
|
|
|
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
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(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- first point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'g') -- polygon mode
|
2022-06-14 22:59:09 +01:00
|
|
|
-- second point
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p') -- add point
|
2022-06-14 22:59:09 +01:00
|
|
|
-- final point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+26, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, '#shapes')
|
|
|
|
check_eq(#drawing.points, 3, 'vertices')
|
2022-06-14 22:59:09 +01:00
|
|
|
local shape = drawing.shapes[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(shape.mode, 'polygon', 'shape_mode')
|
|
|
|
check_eq(#shape.vertices, 3, 'vertices')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[1]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 5, 'p1:x')
|
|
|
|
check_eq(p.y, 6, 'p1:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[2]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 65, 'p2:x')
|
|
|
|
check_eq(p.y, 36, 'p2:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[3]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 35, 'p3:x')
|
|
|
|
check_eq(p.y, 26, 'p3:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
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(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- first point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'r') -- rectangle mode
|
2022-06-14 22:59:09 +01:00
|
|
|
-- second point/first edge
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- override second point/first edge
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- release (decides 'thickness' of rectangle perpendicular to first edge)
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, '#shapes')
|
|
|
|
check_eq(#drawing.points, 5, '#points') -- currently includes every point added
|
2022-06-14 22:59:09 +01:00
|
|
|
local shape = drawing.shapes[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(shape.mode, 'rectangle', 'shape_mode')
|
|
|
|
check_eq(#shape.vertices, 4, 'vertices')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[1]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 35, 'p1:x')
|
|
|
|
check_eq(p.y, 36, 'p1:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[2]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 75, 'p2:x')
|
|
|
|
check_eq(p.y, 76, 'p2:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[3]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 70, 'p3:x')
|
|
|
|
check_eq(p.y, 81, 'p3:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[shape.vertices[4]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 30, 'p4:x')
|
|
|
|
check_eq(p.y, 41, 'p4:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
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(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- first point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'r') -- rectangle mode
|
2022-06-14 22:59:09 +01:00
|
|
|
-- second point/first edge
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- override second point/first edge
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+75, Editor_state.top+Drawing_padding_top+76)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p')
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.points, 3, '#points') -- currently includes every point added
|
2022-06-14 22:59:09 +01:00
|
|
|
local pending = drawing.pending
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(pending.mode, 'rectangle', 'shape_mode')
|
|
|
|
check_eq(#pending.vertices, 2, 'vertices')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[pending.vertices[1]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 35, 'p1:x')
|
|
|
|
check_eq(p.y, 36, 'p1:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[pending.vertices[2]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 75, 'p2:x')
|
|
|
|
check_eq(p.y, 76, 'p2:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- 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)
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
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(Editor_state.line_cache[1].starty, 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')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- first point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 's') -- square mode
|
2022-06-14 22:59:09 +01:00
|
|
|
-- second point/first edge
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+42, Editor_state.top+Drawing_padding_top+45)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- override second point/first edge
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+66)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p')
|
2022-06-14 22:59:09 +01:00
|
|
|
-- release (decides which side of first edge to draw square on)
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+15, Editor_state.top+Drawing_padding_top+26, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[drawing.shapes[1].vertices[1]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 35, 'p1:x')
|
|
|
|
check_eq(p.y, 36, 'p1:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[drawing.shapes[1].vertices[2]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 65, 'p2:x')
|
|
|
|
check_eq(p.y, 66, 'p2:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[drawing.shapes[1].vertices[3]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 35, 'p3:x')
|
|
|
|
check_eq(p.y, 96, 'p3:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
local p = drawing.points[drawing.shapes[1].vertices[4]]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p.x, 5, 'p4:x')
|
|
|
|
check_eq(p.y, 66, 'p4:y')
|
2022-06-14 22:59:09 +01:00
|
|
|
end
|
2022-06-15 05:07:04 +01:00
|
|
|
|
|
|
|
function test_name_point()
|
|
|
|
-- create a drawing with a line
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-15 05:07:04 +01:00
|
|
|
-- draw a line
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, 'baseline/#shapes')
|
|
|
|
check_eq(#drawing.points, 2, 'baseline/#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
|
2022-06-15 05:07:04 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 05:07:04 +01:00
|
|
|
-- enter 'name' mode without moving the mouse
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-n', 'n')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'A')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.name, 'A', 'check1')
|
2022-06-15 05:07:04 +01:00
|
|
|
-- still in 'name' mode
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'name', 'mode:2')
|
2022-06-15 05:07:04 +01:00
|
|
|
-- exit 'name' mode
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'return', 'return')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'line', 'mode:3')
|
|
|
|
check_eq(p2.name, 'A', 'check2')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:17:42 +01:00
|
|
|
-- change is saved
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.name, 'A', 'save')
|
2022-06-15 05:07:04 +01:00
|
|
|
end
|
2022-06-15 05:08:03 +01:00
|
|
|
|
2023-03-26 16:17:31 +01:00
|
|
|
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
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-n', 'n')
|
2023-03-26 16:17:31 +01:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'name', 'mode:1')
|
|
|
|
-- hit backspace
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'backspace', 'backspace')
|
2023-03-26 16:17:31 +01:00
|
|
|
-- no crash
|
|
|
|
end
|
|
|
|
|
2023-03-26 17:36:41 +01:00
|
|
|
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
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-n', 'n')
|
2023-03-26 17:36:41 +01:00
|
|
|
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
|
|
|
|
|
2022-06-15 05:08:03 +01:00
|
|
|
function test_move_point()
|
|
|
|
-- create a drawing with a line
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, 'baseline/#shapes')
|
|
|
|
check_eq(#drawing.points, 2, 'baseline/#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
|
2022-06-15 05:08:03 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:17:42 +01:00
|
|
|
-- line is saved to disk
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
|
|
|
local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.x, 35, 'save/x')
|
|
|
|
check_eq(p2.y, 36, 'save/y')
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-15 05:08:03 +01:00
|
|
|
-- enter 'move' mode without moving the mouse
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-u', 'u')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'move', 'mode:1')
|
2022-06-15 05:08:03 +01:00
|
|
|
-- point is lifted
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.pending.mode, 'move', 'mode:2')
|
|
|
|
check_eq(drawing.pending.target_point, p2, 'target')
|
2022-06-15 05:08:03 +01:00
|
|
|
-- move point
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0.05)
|
2022-06-15 05:08:03 +01:00
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.x, 26, 'x')
|
|
|
|
check_eq(p2.y, 44, 'y')
|
2022-06-15 05:08:03 +01:00
|
|
|
-- exit 'move' mode
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_click(Editor_state, Editor_state.left+26, Editor_state.top+Drawing_padding_top+44, 1)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'line', 'mode:3')
|
|
|
|
check_eq(drawing.pending, {}, 'pending')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:17:42 +01:00
|
|
|
-- change is saved
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.x, 26, 'save/x')
|
|
|
|
check_eq(p2.y, 44, 'save/y')
|
2022-06-15 05:08:03 +01:00
|
|
|
end
|
2022-06-15 05:23:39 +01:00
|
|
|
|
2022-06-18 06:52:34 +01:00
|
|
|
function test_move_point_on_manhattan_line()
|
|
|
|
-- create a drawing with a manhattan line
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'manhattan'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, 'baseline/#shapes')
|
|
|
|
check_eq(#drawing.points, 2, 'baseline/#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'manhattan', 'baseline/shape:1')
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-18 06:52:34 +01:00
|
|
|
-- enter 'move' mode
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-u', 'u')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.current_drawing_mode, 'move', 'mode:1')
|
2022-06-18 06:52:34 +01:00
|
|
|
-- move point
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0.05)
|
2022-06-18 06:52:34 +01:00
|
|
|
-- line is no longer manhattan
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
|
2022-06-18 06:52:34 +01:00
|
|
|
end
|
|
|
|
|
2022-06-15 05:23:39 +01:00
|
|
|
function test_delete_lines_at_point()
|
|
|
|
-- create a drawing with two lines connected at a point
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- hover on the common point and delete
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+36)
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-d', 'd')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
|
|
|
|
check_eq(drawing.shapes[2].mode, 'deleted', 'shape:2')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait for some time
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:17:42 +01:00
|
|
|
-- deleted points disappear after file is reloaded
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines[1].shapes, 0, 'save')
|
2022-06-15 05:23:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_delete_line_under_mouse_pointer()
|
|
|
|
-- create a drawing with two lines connected at a point
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- hover on one of the lines and delete
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+25, Editor_state.top+Drawing_padding_top+26)
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-d', 'd')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- only that line is deleted
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
|
|
|
|
check_eq(drawing.shapes[2].mode, 'line', 'shape:2')
|
2022-06-15 05:23:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_delete_point_from_polygon()
|
|
|
|
-- create a drawing with two lines connected at a point
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-15 05:23:39 +01:00
|
|
|
-- first point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'g') -- polygon mode
|
2022-06-15 05:23:39 +01:00
|
|
|
-- second point
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p') -- add point
|
2022-06-15 05:23:39 +01:00
|
|
|
-- third point
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p') -- add point
|
2022-06-15 05:23:39 +01:00
|
|
|
-- fourth point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- hover on a point and delete
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+26)
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-d', 'd')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- just the one point is deleted
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.shapes[1].mode, 'polygon', 'shape')
|
|
|
|
check_eq(#drawing.shapes[1].vertices, 3, 'vertices')
|
2022-06-15 05:23:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function test_delete_point_from_polygon()
|
|
|
|
-- create a drawing with two lines connected at a point
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-15 05:23:39 +01:00
|
|
|
-- first point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'g') -- polygon mode
|
2022-06-15 05:23:39 +01:00
|
|
|
-- second point
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'p') -- add point
|
2022-06-15 05:23:39 +01:00
|
|
|
-- third point
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_release(Editor_state, Editor_state.left+14, Editor_state.top+Drawing_padding_top+16, 1)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- hover on a point and delete
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+65, Editor_state.top+Drawing_padding_top+36)
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-d', 'd')
|
2022-06-15 05:23:39 +01:00
|
|
|
-- there's < 3 points left, so the whole polygon is deleted
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.shapes[1].mode, 'deleted', 'check')
|
2022-06-15 05:23:39 +01:00
|
|
|
end
|
2022-06-15 06:38:36 +01:00
|
|
|
|
|
|
|
function test_undo_name_point()
|
|
|
|
-- create a drawing with a line
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-06-15 06:38:36 +01:00
|
|
|
-- draw a line
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, 'baseline/#shapes')
|
|
|
|
check_eq(#drawing.points, 2, 'baseline/#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
|
2022-06-15 06:38:36 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-07-13 16:38:07 +01:00
|
|
|
--? print('a', Editor_state.lines.current_drawing)
|
2022-06-15 06:38:36 +01:00
|
|
|
-- enter 'name' mode without moving the mouse
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-n', 'n')
|
2022-12-24 01:16:19 +00:00
|
|
|
edit.run_after_text_input(Editor_state, 'A')
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'return', 'return')
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-07-13 16:38:07 +01:00
|
|
|
--? print('b', Editor_state.lines.current_drawing)
|
2022-06-15 06:38:36 +01:00
|
|
|
-- undo
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-z', 'z')
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2022-06-15 06:38:36 +01:00
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.next_history, 3, 'next_history')
|
|
|
|
check_eq(p2.name, '', 'undo') -- not quite what it was before, but close enough
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:47:49 +01:00
|
|
|
-- undo is saved
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.name, '', 'save')
|
2022-06-15 06:38:36 +01:00
|
|
|
end
|
2022-06-15 06:43:59 +01:00
|
|
|
|
|
|
|
function test_undo_move_point()
|
|
|
|
-- create a drawing with a line
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#drawing.shapes, 1, 'baseline/#shapes')
|
|
|
|
check_eq(#drawing.points, 2, 'baseline/#points')
|
|
|
|
check_eq(drawing.shapes[1].mode, 'line', 'baseline/shape:1')
|
2022-06-15 06:43:59 +01:00
|
|
|
local p1 = drawing.points[drawing.shapes[1].p1]
|
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 06:43:59 +01:00
|
|
|
-- move p2
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-u', 'u')
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+26, Editor_state.top+Drawing_padding_top+44)
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0.05)
|
2022-06-15 06:43:59 +01:00
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.x, 26, 'x')
|
|
|
|
check_eq(p2.y, 44, 'y')
|
2022-06-15 06:43:59 +01:00
|
|
|
-- exit 'move' mode
|
2022-07-16 16:48:02 +01:00
|
|
|
edit.run_after_mouse_click(Editor_state, Editor_state.left+26, Editor_state.top+Drawing_padding_top+44, 1)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.next_history, 4, 'next_history')
|
2022-06-15 06:43:59 +01:00
|
|
|
-- undo
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-z', 'z')
|
|
|
|
edit.run_after_keychord(Editor_state, 'C-z', 'z') -- bug: need to undo twice
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2022-06-15 06:43:59 +01:00
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(Editor_state.next_history, 2, 'next_history')
|
|
|
|
check_eq(p2.x, 35, 'x')
|
|
|
|
check_eq(p2.y, 36, 'y')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:47:49 +01:00
|
|
|
-- undo is saved
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
local p2 = Editor_state.lines[1].points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(p2.x, 35, 'save/x')
|
|
|
|
check_eq(p2.y, 36, 'save/y')
|
2022-06-15 06:43:59 +01:00
|
|
|
end
|
2022-06-15 06:47:49 +01:00
|
|
|
|
|
|
|
function test_undo_delete_point()
|
|
|
|
-- create a drawing with two lines connected at a point
|
2022-07-16 06:12:25 +01:00
|
|
|
App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels
|
|
|
|
Editor_state = edit.initialize_test_state()
|
2022-07-19 15:50:53 +01:00
|
|
|
Editor_state.filename = 'foo'
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.lines = load_array{'```lines', '```', ''}
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2022-07-12 22:18:50 +01:00
|
|
|
Editor_state.current_drawing_mode = 'line'
|
2022-07-12 23:18:45 +01:00
|
|
|
edit.draw(Editor_state)
|
2022-07-16 16:48:02 +01:00
|
|
|
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)
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-15 06:47:49 +01:00
|
|
|
-- hover on the common point and delete
|
2022-07-16 16:48:02 +01:00
|
|
|
App.mouse_move(Editor_state.left+35, Editor_state.top+Drawing_padding_top+36)
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-d', 'd')
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(drawing.shapes[1].mode, 'deleted', 'shape:1')
|
|
|
|
check_eq(drawing.shapes[2].mode, 'deleted', 'shape:2')
|
2022-06-15 06:47:49 +01:00
|
|
|
-- undo
|
2024-02-04 17:30:48 +00:00
|
|
|
edit.run_after_keychord(Editor_state, 'C-z', 'z')
|
2022-07-12 22:18:50 +01:00
|
|
|
local drawing = Editor_state.lines[1]
|
2022-06-15 06:47:49 +01:00
|
|
|
local p2 = drawing.points[drawing.shapes[1].p2]
|
2023-01-21 05:42:52 +00:00
|
|
|
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')
|
2022-06-17 23:42:53 +01:00
|
|
|
-- wait until save
|
2022-11-04 04:02:31 +00:00
|
|
|
Current_time = Current_time + 3.1
|
2022-07-16 16:20:47 +01:00
|
|
|
edit.update(Editor_state, 0)
|
2022-06-15 06:47:49 +01:00
|
|
|
-- undo is saved
|
2022-07-26 03:56:39 +01:00
|
|
|
load_from_disk(Editor_state)
|
2022-07-18 05:05:01 +01:00
|
|
|
Text.redraw_all(Editor_state)
|
2023-01-21 05:42:52 +00:00
|
|
|
check_eq(#Editor_state.lines[1].shapes, 2, 'save')
|
2022-06-15 06:47:49 +01:00
|
|
|
end
|