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