Merge lines.love
[view.love.git] / source_tests.lua
blobe3264bb0a9c539a03b11f57ac937431d0affe9f1
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 Log_browser_state = edit.initialize_test_state()
6 check_eq(App.screen.width, 300, 'baseline/width')
7 check_eq(App.screen.height, 300, 'baseline/height')
8 check_eq(Editor_state.left, Test_margin_left, 'baseline/left_margin')
9 check_eq(Editor_state.right, 300 - Test_margin_right, 'baseline/right_margin')
10 App.resize(200, 400)
11 -- ugly; resize switches to real, non-test margins
12 check_eq(App.screen.width, 200, 'width')
13 check_eq(App.screen.height, 400, 'height')
14 check_eq(Editor_state.left, Margin_left, 'left_margin')
15 check_eq(Editor_state.right, 200-Margin_right, 'right_margin')
16 check_eq(Editor_state.width, 200-Margin_left-Margin_right, 'drawing_width')
17 -- TODO: how to make assertions about when App.update got past the early exit?
18 end
20 function test_show_log_browser_side()
21 App.screen.init{width=300, height=300}
22 Current_app = 'source'
23 Editor_state = edit.initialize_test_state()
24 Editor_state.filename = 'foo'
25 Text.redraw_all(Editor_state)
26 Log_browser_state = edit.initialize_test_state()
27 Text.redraw_all(Log_browser_state)
28 log_browser.parse(Log_browser_state)
29 check(not Show_log_browser_side, 'baseline')
30 -- pressing ctrl+l shows log-browser side
31 Current_time = Current_time + 0.1
32 App.run_after_keychord('C-l')
33 check(Show_log_browser_side, 'check')
34 end
36 function test_show_log_browser_side_splits_window_width()
37 -- initialize screen dimensions and indicate that it is maximized
38 App.screen.init{width=300, height=300}
39 -- initialize source app with left side occupying more than half the display
40 Current_app = 'source'
41 Editor_state = edit.initialize_test_state()
42 Editor_state.filename = 'foo'
43 Editor_state.left = Margin_left
44 Editor_state.right = 200
45 Text.redraw_all(Editor_state)
46 Log_browser_state = edit.initialize_test_state()
47 -- log browser has some arbitrary margins
48 Log_browser_state.left = 200 + Margin_left
49 Log_browser_state.right = 400
50 Text.redraw_all(Log_browser_state)
51 log_browser.parse(Log_browser_state)
52 -- display log browser
53 Current_time = Current_time + 0.1
54 App.run_after_keychord('C-l')
55 -- margins are now adjusted
56 check_eq(Editor_state.left, Margin_left, 'edit:left')
57 check_eq(Editor_state.right, App.screen.width/2 - Margin_right, 'edit:right')
58 check_eq(Log_browser_state.left, App.screen.width/2 + Margin_left, 'log:left')
59 check_eq(Log_browser_state.right, App.screen.width - Margin_right, 'log:right')
60 end
62 function test_drop_file()
63 App.screen.init{width=Editor_state.left+300, height=300}
64 Editor_state = edit.initialize_test_state()
65 App.filesystem['foo'] = 'abc\ndef\nghi\n'
66 local fake_dropped_file = {
67 opened = false,
68 getFilename = function(self)
69 return 'foo'
70 end,
71 open = function(self)
72 self.opened = true
73 end,
74 lines = function(self)
75 assert(self.opened)
76 return App.filesystem['foo']:gmatch('[^\n]+')
77 end,
78 close = function(self)
79 self.opened = false
80 end,
82 App.filedropped(fake_dropped_file)
83 check_eq(#Editor_state.lines, 3, '#lines')
84 check_eq(Editor_state.lines[1].data, 'abc', 'lines:1')
85 check_eq(Editor_state.lines[2].data, 'def', 'lines:2')
86 check_eq(Editor_state.lines[3].data, 'ghi', 'lines:3')
87 edit.draw(Editor_state)
88 end
90 function test_drop_file_saves_previous()
91 App.screen.init{width=Editor_state.left+300, height=300}
92 -- initially editing a file called foo that hasn't been saved to filesystem yet
93 Editor_state.lines = load_array{'abc', 'def'}
94 Editor_state.filename = 'foo'
95 schedule_save(Editor_state)
96 -- now drag a new file bar from the filesystem
97 App.filesystem['bar'] = 'abc\ndef\nghi\n'
98 local fake_dropped_file = {
99 opened = false,
100 getFilename = function(self)
101 return 'bar'
102 end,
103 open = function(self)
104 self.opened = true
105 end,
106 lines = function(self)
107 assert(self.opened)
108 return App.filesystem['bar']:gmatch('[^\n]+')
109 end,
110 close = function(self)
111 self.opened = false
112 end,
114 App.filedropped(fake_dropped_file)
115 -- filesystem now contains a file called foo
116 check_eq(App.filesystem['foo'], 'abc\ndef\n', 'check')