couple more tests
Along with the App helpers needed for them.
This commit is contained in:
parent
2999605530
commit
fa103ca2e8
18
app.lua
18
app.lua
|
@ -15,6 +15,7 @@ function love.run()
|
|||
App.run_tests()
|
||||
|
||||
App.disable_tests()
|
||||
if App.initialize_globals then App.initialize_globals() end
|
||||
if App.initialize then App.initialize(love.arg.parseGameArguments(arg), arg) end
|
||||
if love.timer then love.timer.step() end
|
||||
|
||||
|
@ -129,6 +130,8 @@ App = {screen={}}
|
|||
function App.initialize_for_test()
|
||||
App.screen.init({width=100, height=50})
|
||||
App.screen.contents = {} -- clear screen
|
||||
App.filesystem = {}
|
||||
if App.initialize_globals then App.initialize_globals() end
|
||||
end
|
||||
|
||||
function App.screen.init(dims)
|
||||
|
@ -199,6 +202,18 @@ function App.screen.check(y, expected_contents, msg)
|
|||
check_eq(contents, expected_contents, msg)
|
||||
end
|
||||
|
||||
-- fake files
|
||||
function App.open_for_writing(filename)
|
||||
App.filesystem[filename] = ''
|
||||
return {
|
||||
write = function(self, s)
|
||||
App.filesystem[filename] = App.filesystem[filename]..s
|
||||
end,
|
||||
close = function(self)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
function App.run_tests()
|
||||
local sorted_names = {}
|
||||
for name,binding in pairs(_G) do
|
||||
|
@ -228,10 +243,13 @@ function App.disable_tests()
|
|||
|
||||
-- test methods are disallowed outside tests
|
||||
App.screen.init = nil
|
||||
App.filesystem = nil
|
||||
App.run_after_textinput = nil
|
||||
App.run_after_keychord = nil
|
||||
-- other methods dispatch to real hardware
|
||||
App.screen.print = love.graphics.print
|
||||
App.newText = love.graphics.newText
|
||||
App.screen.draw = love.graphics.draw
|
||||
App.width = function(text) return text:getWidth() end
|
||||
App.open_for_writing = function(filename) return io.open(filename, 'w') end
|
||||
end
|
||||
|
|
2
file.lua
2
file.lua
|
@ -29,7 +29,7 @@ function load_from_file(infile)
|
|||
end
|
||||
|
||||
function save_to_disk(lines, filename)
|
||||
local outfile = io.open(filename, 'w')
|
||||
local outfile = App.open_for_writing(filename)
|
||||
for _,line in ipairs(lines) do
|
||||
if line.mode == 'drawing' then
|
||||
store_drawing(outfile, line)
|
||||
|
|
36
main.lua
36
main.lua
|
@ -12,12 +12,8 @@ local geom = require 'geom'
|
|||
require 'help'
|
||||
require 'icons'
|
||||
|
||||
function App.initialize(arg)
|
||||
love.keyboard.setTextInput(true) -- bring up keyboard on touch screen
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
|
||||
-- globals
|
||||
|
||||
-- run in both tests and a real run
|
||||
function App.initialize_globals()
|
||||
-- a line is either text or a drawing
|
||||
-- a text is a table with:
|
||||
-- mode = 'text'
|
||||
|
@ -61,17 +57,6 @@ Cursor1 = {line=1, pos=1} -- position of cursor
|
|||
Screen_top1 = {line=1, pos=1} -- position of start of screen line at top of screen
|
||||
Screen_bottom1 = {line=1, pos=1} -- position of start of screen line at bottom of screen
|
||||
|
||||
-- maximize window
|
||||
love.window.setMode(0, 0) -- maximize
|
||||
App.screen.width, App.screen.height = love.window.getMode()
|
||||
-- shrink slightly to account for window decoration
|
||||
App.screen.width = App.screen.width-100
|
||||
App.screen.height = App.screen.height-100
|
||||
love.window.setMode(App.screen.width, App.screen.height)
|
||||
--? App.screen.width = 120
|
||||
--? App.screen.height = 200
|
||||
--? love.window.setMode(App.screen.width, App.screen.height)
|
||||
|
||||
Cursor_x, Cursor_y = 0, 0 -- in pixels
|
||||
|
||||
Current_drawing_mode = 'line'
|
||||
|
@ -85,6 +70,23 @@ Zoom = 1.5
|
|||
|
||||
Filename = love.filesystem.getUserDirectory()..'/lines.txt'
|
||||
|
||||
end -- App.initialize_globals
|
||||
|
||||
function App.initialize(arg)
|
||||
love.keyboard.setTextInput(true) -- bring up keyboard on touch screen
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
|
||||
-- maximize window
|
||||
love.window.setMode(0, 0) -- maximize
|
||||
App.screen.width, App.screen.height = love.window.getMode()
|
||||
-- shrink slightly to account for window decoration
|
||||
App.screen.width = App.screen.width-100
|
||||
App.screen.height = App.screen.height-100
|
||||
love.window.setMode(App.screen.width, App.screen.height)
|
||||
--? App.screen.width = 120
|
||||
--? App.screen.height = 200
|
||||
--? love.window.setMode(App.screen.width, App.screen.height)
|
||||
|
||||
-- still in App.initialize
|
||||
if #arg > 0 then
|
||||
Filename = arg[1]
|
||||
|
|
45
text.lua
45
text.lua
|
@ -95,6 +95,51 @@ function test_draw_text()
|
|||
App.screen.check(y, 'ghi', 'F - test_draw_text/screen:3')
|
||||
end
|
||||
|
||||
function test_draw_wrapping_text()
|
||||
io.write('\ntest_draw_wrapping_text')
|
||||
App.screen.init{width=50, height=60}
|
||||
Lines = load_array{'abc', 'defgh', 'xyz'}
|
||||
Line_width = App.screen.width
|
||||
Cursor1 = {line=1, pos=1}
|
||||
Screen_top1 = {line=1, pos=1}
|
||||
Screen_bottom1 = {}
|
||||
Zoom = 1
|
||||
App.draw()
|
||||
local screen_top_margin = 15 -- pixels
|
||||
local line_height = 15 -- pixels
|
||||
local y = screen_top_margin
|
||||
App.screen.check(y, 'abc', 'F - test_draw_wrapping_text/screen:1')
|
||||
y = y + line_height
|
||||
App.screen.check(y, 'def', 'F - test_draw_wrapping_text/screen:2')
|
||||
y = y + line_height
|
||||
App.screen.check(y, 'gh', 'F - test_draw_wrapping_text/screen:3')
|
||||
end
|
||||
|
||||
function test_edit_wrapping_text()
|
||||
io.write('\ntest_edit_wrapping_text')
|
||||
App.screen.init{width=50, height=60}
|
||||
Lines = load_array{'abc', 'def', 'xyz'}
|
||||
Line_width = App.screen.width
|
||||
Cursor1 = {line=2, pos=4}
|
||||
Screen_top1 = {line=1, pos=1}
|
||||
Screen_bottom1 = {}
|
||||
Zoom = 1
|
||||
App.run_after_textinput('g')
|
||||
App.run_after_textinput('h')
|
||||
App.run_after_textinput('i')
|
||||
App.run_after_textinput('j')
|
||||
App.run_after_textinput('k')
|
||||
App.run_after_textinput('l')
|
||||
local screen_top_margin = 15 -- pixels
|
||||
local line_height = 15 -- pixels
|
||||
local y = screen_top_margin
|
||||
App.screen.check(y, 'abc', 'F - test_edit_wrapping_text/screen:1')
|
||||
y = y + line_height
|
||||
App.screen.check(y, 'def', 'F - test_edit_wrapping_text/screen:2')
|
||||
y = y + line_height
|
||||
App.screen.check(y, 'ghij', 'F - test_edit_wrapping_text/screen:3')
|
||||
end
|
||||
|
||||
function test_pagedown()
|
||||
io.write('\ntest_pagedown')
|
||||
App.screen.init{width=120, height=45}
|
||||
|
|
Loading…
Reference in New Issue