about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app.lua18
-rw-r--r--file.lua2
-rw-r--r--main.lua36
-rw-r--r--text.lua45
4 files changed, 83 insertions, 18 deletions
diff --git a/app.lua b/app.lua
index 0a43319..ffcb30e 100644
--- a/app.lua
+++ b/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
diff --git a/file.lua b/file.lua
index a60fe69..ced2a04 100644
--- a/file.lua
+++ b/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)
diff --git a/main.lua b/main.lua
index e2a0e95..ce411d6 100644
--- a/main.lua
+++ b/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]
diff --git a/text.lua b/text.lua
index 4bdadfb..200ed64 100644
--- a/text.lua
+++ b/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}