-- major tests for drawings -- We minimize assumptions about specific pixels, and try to test at the level -- of specific shapes. In particular, no tests of freehand drawings. function test_creating_drawing_saves() io.write('\ntest_creating_drawing_saves') App.screen.init{width=120, height=60} Editor_state = edit.initialize_test_state() Editor_state.filename = 'foo' Editor_state.lines = load_array{} Text.redraw_all(Editor_state) edit.draw(Editor_state) -- click on button to create drawing edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1) -- file not immediately saved edit.update(Editor_state, 0.01) check_nil(App.filesystem['foo'], 'F - test_creating_drawing_saves/early') -- wait until save Current_time = Current_time + 3.1 edit.update(Editor_state, 0) -- filesystem contains drawing and an empty line of text check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'F - test_creating_drawing_saves') end function test_draw_line() io.write('\ntest_draw_line') -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end) App.screen.init{width=Test_margin_left+256, height=300} -- drawing coordinates 1:1 with pixels Editor_state = edit.initialize_test_state() Editor_state.filename = 'foo' Editor_state.lines = load_array{'```lines', '```', ''} Text.redraw_all(Editor_state) Editor_state.current_drawing_mode = 'line' edit.draw(Editor_state) check_eq(#Editor_state.lines, 2, 'F - test_draw_line/baseline/#lines') check_eq(Editor_state.lines[1].mode, 'drawing', 'F - test_draw_line/baseline/mode') check_eq(Editor_state.line_cache[1].starty, Editor_state.top+Drawing_padding_top, 'F - test_draw_line/baseline/y') check_eq(Editor_state.lines[1].h, 128, 'F - test_draw_line/baseline/y') check_eq(#Editor_state.lines[1].shapes, 0, 'F - test_draw_line/baseline/#shapes') -- draw a line edit.run_after_mouse_press(Editor_state, Editor_state.left+5, Editor_state.top+Drawing_padding_top+6, 1) edit.run_after_mouse_release(Editor_state, Editor_state.left+35, Editor_state.top+Drawing_padding_top+36, 1) local drawing = Editor_state.lines[1] check_eq(#drawing.shapes, 1, 'F - test_draw_line/#shapes') check_eq(#drawing.points, 2, 'F - test_draw_line/#points') check_eq(drawing.shapes[1].mode, 'line', 'F - test_draw_line/shape:1') local p1 = drawing.points[drawing.shapes[1].p1] local p2 = drawing.points[drawing.shapes[1].p2] check_eq(p1.x, 5, 'F - test_draw_line/p1:x') check_eq(p1.y, 6, 'F - test_draw_line/p1:y') check_eq(p2.x, 35, 'F - test_draw_line/p2:x') check_eq(p2.y, 36, 'F - test_draw_line/p2:y') -- wait until save Current_time = Current_time + 3.1 edit.update(Editor_state, 0) -- The format on disk isn't perfectly stable. Table fields can be reordered. -- So just reload from disk to verify. load_from_disk(Editor_state) Text.redraw_all(Editor_state) local drawing = Editor_state.lines[1] check_eq(#drawing.shapes, 1, 'F - test_draw_line/save/#shapes') check_eq(#drawing.points, 2, 'F - test_draw_line/save/#points') check_eq(drawing.shapes[1].mode, 'line', 'F - test_draw_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, 'F - test_draw_line/save/p1:x') check_eq(p1.y, 6, 'F - test_draw_line/save/p1:y') check_eq(p2.x, 35, 'F - test_d
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Free Software</title>
<link rel="stylesheet" href="/plain.css" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta charset="utf-8" />
</head>
<body class="indent">
<h1>Free Software</h1>
<p>Article ID: 10</p>
<div id="footer">
<hr />
<p><a href="/">Andrew Yu's Website</a></p>
</div>
</body>
</html>