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')
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?
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
= {
25 getFilename
= function(self
)
31 lines
= function(self
)
33 return App
.filesystem
['foo']:gmatch('[^\n]+')
35 close
= function(self
)
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
)
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
= {
57 getFilename
= function(self
)
63 lines
= function(self
)
65 return App
.filesystem
['bar']:gmatch('[^\n]+')
67 close
= function(self
)
71 App
.filedropped(fake_dropped_file
)
72 -- filesystem now contains a file called foo
73 check_eq(App
.filesystem
['foo'], 'abc\ndef\n', 'check')