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')
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?
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
= {
27 getFilename
= function(self
)
33 lines
= function(self
)
35 return App
.filesystem
['foo']:gmatch('[^\n]+')
37 close
= function(self
)
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
)
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
= {
60 getFilename
= function(self
)
66 lines
= function(self
)
68 return App
.filesystem
['bar']:gmatch('[^\n]+')
70 close
= function(self
)
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')