test: autosave after any shape
This commit is contained in:
parent
d077ce7f42
commit
15acc38da9
|
@ -13,7 +13,6 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking.
|
||||||
### Todo list
|
### Todo list
|
||||||
|
|
||||||
persistence:
|
persistence:
|
||||||
draw a line, circle, rectangle, square, polygon, quit, restart. All the shapes you drew should still be visible.
|
|
||||||
select a point and name it, quit, restart. Name is still visible.
|
select a point and name it, quit, restart. Name is still visible.
|
||||||
|
|
||||||
undo:
|
undo:
|
||||||
|
|
18
app.lua
18
app.lua
|
@ -276,8 +276,21 @@ end
|
||||||
function App.open_for_writing(filename)
|
function App.open_for_writing(filename)
|
||||||
App.filesystem[filename] = ''
|
App.filesystem[filename] = ''
|
||||||
return {
|
return {
|
||||||
write = function(self, s)
|
write = function(self, ...)
|
||||||
App.filesystem[filename] = App.filesystem[filename]..s
|
local args = {...}
|
||||||
|
for i,s in ipairs(args) do
|
||||||
|
App.filesystem[filename] = App.filesystem[filename]..s
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
close = function(self)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function App.open_for_reading(filename)
|
||||||
|
return {
|
||||||
|
lines = function(self)
|
||||||
|
return App.filesystem[filename]:gmatch('[^\n]+')
|
||||||
end,
|
end,
|
||||||
close = function(self)
|
close = function(self)
|
||||||
end
|
end
|
||||||
|
@ -331,6 +344,7 @@ function App.disable_tests()
|
||||||
App.newText = love.graphics.newText
|
App.newText = love.graphics.newText
|
||||||
App.screen.draw = love.graphics.draw
|
App.screen.draw = love.graphics.draw
|
||||||
App.width = function(text) return text:getWidth() end
|
App.width = function(text) return text:getWidth() end
|
||||||
|
App.open_for_reading = function(filename) return io.open(filename, 'r') end
|
||||||
App.open_for_writing = function(filename) return io.open(filename, 'w') end
|
App.open_for_writing = function(filename) return io.open(filename, 'w') end
|
||||||
App.getClipboardText = love.system.getClipboardText
|
App.getClipboardText = love.system.getClipboardText
|
||||||
App.setClipboardText = love.system.setClipboardText
|
App.setClipboardText = love.system.setClipboardText
|
||||||
|
|
|
@ -2,9 +2,22 @@
|
||||||
-- We minimize assumptions about specific pixels, and try to test at the level
|
-- We minimize assumptions about specific pixels, and try to test at the level
|
||||||
-- of specific shapes. In particular, no tests of freehand drawings.
|
-- 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}
|
||||||
|
Filename = 'foo'
|
||||||
|
Lines = load_array{}
|
||||||
|
App.draw()
|
||||||
|
-- click on button to create drawing
|
||||||
|
App.run_after_mouse_click(8,Margin_top+8, 1)
|
||||||
|
-- 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()
|
function test_draw_line()
|
||||||
io.write('\ntest_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)
|
-- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
|
||||||
|
Filename = 'foo'
|
||||||
App.screen.init{width=Margin_left+300, height=300}
|
App.screen.init{width=Margin_left+300, height=300}
|
||||||
Lines = load_array{'```lines', '```', ''}
|
Lines = load_array{'```lines', '```', ''}
|
||||||
Line_width = 256 -- drawing coordinates 1:1 with pixels
|
Line_width = 256 -- drawing coordinates 1:1 with pixels
|
||||||
|
@ -28,6 +41,19 @@ function test_draw_line()
|
||||||
check_eq(p1.y, 6, 'F - test_draw_line/p1:y')
|
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.x, 35, 'F - test_draw_line/p2:x')
|
||||||
check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
|
check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
|
||||||
|
-- The format on disk isn't perfectly stable. Table fields can be reordered.
|
||||||
|
-- So just reload from disk to verify.
|
||||||
|
Lines = load_from_disk(Filename)
|
||||||
|
local drawing = 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_draw_line/save/p2:x')
|
||||||
|
check_eq(p2.y, 36, 'F - test_draw_line/save/p2:y')
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_draw_horizontal_line()
|
function test_draw_horizontal_line()
|
||||||
|
|
2
file.lua
2
file.lua
|
@ -2,7 +2,7 @@
|
||||||
Drawing = require 'drawing'
|
Drawing = require 'drawing'
|
||||||
|
|
||||||
function load_from_disk(filename)
|
function load_from_disk(filename)
|
||||||
local infile = io.open(filename)
|
local infile = App.open_for_reading(filename)
|
||||||
local result = load_from_file(infile)
|
local result = load_from_file(infile)
|
||||||
if infile then infile:close() end
|
if infile then infile:close() end
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue