bugfix: naming points in drawings
[view.love.git] / run_tests.lua
blobeab71ae511c301c5e105366936e7aceeb660bf0f
1 function test_resize_window()
2 io.write('\ntest_resize_window')
3 App.screen.init{width=300, height=300}
4 Editor_state = edit.initialize_test_state()
5 Editor_state.filename = 'foo'
6 check_eq(App.screen.width, 300, 'F - test_resize_window/baseline/width')
7 check_eq(App.screen.height, 300, 'F - test_resize_window/baseline/height')
8 check_eq(Editor_state.left, Test_margin_left, 'F - test_resize_window/baseline/left_margin')
9 check_eq(Editor_state.right, 300 - Test_margin_right, 'F - test_resize_window/baseline/left_margin')
10 App.resize(200, 400)
11 -- ugly; resize switches to real, non-test margins
12 check_eq(App.screen.width, 200, 'F - test_resize_window/width')
13 check_eq(App.screen.height, 400, 'F - test_resize_window/height')
14 check_eq(Editor_state.left, Margin_left, 'F - test_resize_window/left_margin')
15 check_eq(Editor_state.right, 200-Margin_right, 'F - test_resize_window/right_margin')
16 check_eq(Editor_state.width, 200-Margin_left-Margin_right, 'F - test_resize_window/drawing_width')
17 -- TODO: how to make assertions about when App.update got past the early exit?
18 end
20 function test_drop_file()
21 io.write('\ntest_drop_file')
22 App.screen.init{width=Editor_state.left+300, height=300}
23 Editor_state = edit.initialize_test_state()
24 App.filesystem['foo'] = 'abc\ndef\nghi\n'
25 local fake_dropped_file = {
26 opened = false,
27 getFilename = function(self)
28 return 'foo'
29 end,
30 open = function(self)
31 self.opened = true
32 end,
33 lines = function(self)
34 assert(self.opened)
35 return App.filesystem['foo']:gmatch('[^\n]+')
36 end,
37 close = function(self)
38 self.opened = false
39 end,
41 App.filedropped(fake_dropped_file)
42 check_eq(#Editor_state.lines, 3, 'F - test_drop_file/#lines')
43 check_eq(Editor_state.lines[1].data, 'abc', 'F - test_drop_file/lines:1')
44 check_eq(Editor_state.lines[2].data, 'def', 'F - test_drop_file/lines:2')
45 check_eq(Editor_state.lines[3].data, 'ghi', 'F - test_drop_file/lines:3')
46 edit.draw(Editor_state)
47 end
49 function test_drop_file_saves_previous()
50 io.write('\ntest_drop_file_saves_previous')
51 App.screen.init{width=Editor_state.left+300, height=300}
52 -- initially editing a file called foo that hasn't been saved to filesystem yet
53 Editor_state.lines = load_array{'abc', 'def'}
54 Editor_state.filename = 'foo'
55 schedule_save(Editor_state)
56 -- now drag a new file bar from the filesystem
57 App.filesystem['bar'] = 'abc\ndef\nghi\n'
58 local fake_dropped_file = {
59 opened = false,
60 getFilename = function(self)
61 return 'bar'
62 end,
63 open = function(self)
64 self.opened = true
65 end,
66 lines = function(self)
67 assert(self.opened)
68 return App.filesystem['bar']:gmatch('[^\n]+')
69 end,
70 close = function(self)
71 self.opened = false
72 end,
74 App.filedropped(fake_dropped_file)
75 -- filesystem now contains a file called foo
76 check_eq(App.filesystem['foo'], 'abc\ndef\n', 'F - test_drop_file_saves_previous')
77 end