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')
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?
20 function test_show_log_browser_side()
21 App
.screen
.init
{width
=300, height
=300}
22 Display_width
= App
.screen
.width
23 Current_app
= 'source'
24 Editor_state
= edit
.initialize_test_state()
25 Editor_state
.filename
= 'foo'
26 Text
.redraw_all(Editor_state
)
27 Log_browser_state
= edit
.initialize_test_state()
28 Text
.redraw_all(Log_browser_state
)
29 log_browser
.parse(Log_browser_state
)
30 check(not Show_log_browser_side
, 'baseline')
31 -- pressing ctrl+l shows log-browser side
32 Current_time
= Current_time
+ 0.1
33 App
.run_after_keychord('C-l')
34 check(Show_log_browser_side
, 'check')
37 function test_show_log_browser_side_doubles_window_width_if_possible()
38 -- initialize screen dimensions to half width
39 App
.screen
.init
{width
=300, height
=300}
40 Display_width
= App
.screen
.width
*2
41 -- initialize source app with left side occupying entire window (half the display)
42 Current_app
= 'source'
43 Editor_state
= edit
.initialize_test_state()
44 Editor_state
.filename
= 'foo'
45 Editor_state
.left
= Margin_left
46 Editor_state
.right
= App
.screen
.width
- Margin_right
47 local old_editor_right
= Editor_state
.right
48 Text
.redraw_all(Editor_state
)
49 Log_browser_state
= edit
.initialize_test_state()
50 -- log browser has some arbitrary margins
51 Log_browser_state
.left
= 200 + Margin_left
52 Log_browser_state
.right
= 400
53 Text
.redraw_all(Log_browser_state
)
54 log_browser
.parse(Log_browser_state
)
55 -- display log browser
56 Current_time
= Current_time
+ 0.1
57 App
.run_after_keychord('C-l')
58 -- window width is doubled
59 check_eq(App
.screen
.width
, 600, 'display:width')
60 -- left side margins are unchanged
61 check_eq(Editor_state
.left
, Margin_left
, 'edit:left')
62 check_eq(Editor_state
.right
, old_editor_right
, 'edit:right')
63 -- log browser margins are adjusted
64 check_eq(Log_browser_state
.left
, App
.screen
.width
/2 + Margin_left
, 'log:left')
65 check_eq(Log_browser_state
.right
, App
.screen
.width
- Margin_right
, 'log:right')
68 function test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width()
69 -- initialize screen dimensions and indicate that it is maximized
70 App
.screen
.init
{width
=300, height
=300}
72 -- initialize source app with left side occupying more than half the display
73 Current_app
= 'source'
74 Editor_state
= edit
.initialize_test_state()
75 Editor_state
.filename
= 'foo'
76 Editor_state
.left
= Margin_left
77 Editor_state
.right
= 200
78 Text
.redraw_all(Editor_state
)
79 Log_browser_state
= edit
.initialize_test_state()
80 -- log browser has some arbitrary margins
81 Log_browser_state
.left
= 200 + Margin_left
82 Log_browser_state
.right
= 400
83 Text
.redraw_all(Log_browser_state
)
84 log_browser
.parse(Log_browser_state
)
85 -- display log browser
86 Current_time
= Current_time
+ 0.1
87 App
.run_after_keychord('C-l')
88 -- margins are now adjusted
89 check_eq(Editor_state
.left
, Margin_left
, 'edit:left')
90 check_eq(Editor_state
.right
, App
.screen
.width
/2 - Margin_right
, 'edit:right')
91 check_eq(Log_browser_state
.left
, App
.screen
.width
/2 + Margin_left
, 'log:left')
92 check_eq(Log_browser_state
.right
, App
.screen
.width
- Margin_right
, 'log:right')
95 function test_drop_file()
96 App
.screen
.init
{width
=Editor_state
.left
+300, height
=300}
97 Editor_state
= edit
.initialize_test_state()
98 App
.filesystem
['foo'] = 'abc\ndef\nghi\n'
99 local fake_dropped_file
= {
101 getFilename
= function(self
)
104 open
= function(self
)
107 lines
= function(self
)
109 return App
.filesystem
['foo']:gmatch('[^\n]+')
111 close
= function(self
)
115 App
.filedropped(fake_dropped_file
)
116 check_eq(#Editor_state
.lines
, 3, '#lines')
117 check_eq(Editor_state
.lines
[1].data
, 'abc', 'lines:1')
118 check_eq(Editor_state
.lines
[2].data
, 'def', 'lines:2')
119 check_eq(Editor_state
.lines
[3].data
, 'ghi', 'lines:3')
120 edit
.draw(Editor_state
)
123 function test_drop_file_saves_previous()
124 App
.screen
.init
{width
=Editor_state
.left
+300, height
=300}
125 -- initially editing a file called foo that hasn't been saved to filesystem yet
126 Editor_state
.lines
= load_array
{'abc', 'def'}
127 Editor_state
.filename
= 'foo'
128 schedule_save(Editor_state
)
129 -- now drag a new file bar from the filesystem
130 App
.filesystem
['bar'] = 'abc\ndef\nghi\n'
131 local fake_dropped_file
= {
133 getFilename
= function(self
)
136 open
= function(self
)
139 lines
= function(self
)
141 return App
.filesystem
['bar']:gmatch('[^\n]+')
143 close
= function(self
)
147 App
.filedropped(fake_dropped_file
)
148 -- filesystem now contains a file called foo
149 check_eq(App
.filesystem
['foo'], 'abc\ndef\n', 'check')