run_tests.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  18. function test_drop_file()
  19. App.screen.init{width=Editor_state.left+300, height=300}
  20. Editor_state = edit.initialize_test_state()
  21. App.filesystem['foo'] = 'abc\ndef\nghi\n'
  22. local fake_dropped_file = {
  23. opened = false,
  24. getFilename = function(self)
  25. return 'foo'
  26. end,
  27. open = function(self)
  28. self.opened = true
  29. end,
  30. lines = function(self)
  31. assert(self.opened)
  32. return App.filesystem['foo']:gmatch('[^\n]+')
  33. end,
  34. close = function(self)
  35. self.opened = false
  36. end,
  37. }
  38. App.filedropped(fake_dropped_file)
  39. check_eq(#Editor_state.lines, 3, '#lines')
  40. check_eq(Editor_state.lines[1].data, 'abc', 'lines:1')
  41. check_eq(Editor_state.lines[2].data, 'def', 'lines:2')
  42. check_eq(Editor_state.lines[3].data, 'ghi', 'lines:3')
  43. edit.draw(Editor_state)
  44. end
  45. function test_drop_file_saves_previous()
  46. App.screen.init{width=Editor_state.left+300, height=300}
  47. -- initially editing a file called foo that hasn't been saved to filesystem yet
  48. Editor_state.lines = load_array{'abc', 'def'}
  49. Editor_state.filename = 'foo'
  50. schedule_save(Editor_state)
  51. -- now drag a new file bar from the filesystem
  52. App.filesystem['bar'] = 'abc\ndef\nghi\n'
  53. local fake_dropped_file = {
  54. opened = false,
  55. getFilename = function(self)
  56. return 'bar'
  57. end,
  58. open = function(self)
  59. self.opened = true
  60. end,
  61. lines = function(self)
  62. assert(self.opened)
  63. return App.filesystem['bar']:gmatch('[^\n]+')
  64. end,
  65. close = function(self)
  66. self.opened = false
  67. end,
  68. }
  69. App.filedropped(fake_dropped_file)
  70. -- filesystem now contains a file called foo
  71. check_eq(App.filesystem['foo'], 'abc\ndef\n', 'check')
  72. end