test: autosave after any shape

[?]
Jun 15, 2022, 5:06 AM
7CLGG7J277QZGMNOVFEXBX6DRETCVK7GH66HJ7BYOBMPHTJCDFMAC

Dependencies

  • [2] AD34IX2Z couple more tests
  • [3] CRYGI3LR more drawing tests
  • [4] BYG5CEMV support for naming points
  • [5] 2XLZCWZC bugfix: rectangles and squares are now saved
  • [6] AVTNUQYR basic test-enabled framework
  • [7] VHQCNMAR several more modules
  • [8] CPZGQT72 go through and fix similar issues
  • [*] K2X6G75Z start writing some tests for drawings
  • [*] 3QNOKBFM beginnings of a test harness
  • [*] BJ5X5O4A let's prevent the text cursor from ever getting on a drawing

Change contents

  • replacement in file.lua at line 5
    [4.15202][4.15202:15237]()
    local infile = io.open(filename)
    [4.15202]
    [4.15237]
    local infile = App.open_for_reading(filename)
  • edit in drawing_tests.lua at line 5
    [10.193]
    [10.193]
    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
  • edit in drawing_tests.lua at line 20
    [10.353]
    [10.353]
    Filename = 'foo'
  • edit in drawing_tests.lua at line 44
    [10.1529]
    [3.126]
    -- 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')
  • replacement in app.lua at line 279
    [2.2493][2.2493:2592]()
    write = function(self, s)
    App.filesystem[filename] = App.filesystem[filename]..s
    [2.2493]
    [2.2592]
    write = function(self, ...)
    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]+')
  • edit in app.lua at line 347
    [4.8162]
    [2.2713]
    App.open_for_reading = function(filename) return io.open(filename, 'r') end
  • edit in Manual_tests.md at line 16
    [4.16][4.16:131]()
    draw a line, circle, rectangle, square, polygon, quit, restart. All the shapes you drew should still be visible.