about summary refs log blame commit diff stats
path: root/051scenario_test.mu
blob: 0d6f04a66466911d17bc285e6fbec260c5c47406 (plain) (tree)
1
2
3
4
5
6
7
8
                                        
 

                               
                      
   
                         
           





                                      
                      

                         
           






                                                
                      

                         
           

   
 
                               
       
                    


                             
   
                         
                               

   


                      
                      

                        
                                 




                               
                      

                            
                                 




                                  
                         




                        
# tests for 'scenario' in previous layer

scenario first_scenario_in_mu [
  run [
    10:num <- add 2, 2
  ]
  memory-should-contain [
    10 <- 4
  ]
]

scenario scenario_with_comment_in_mu [
  run [
    # comment
    10:num <- add 2, 2
  ]
  memory-should-contain [
    10 <- 4
  ]
]

scenario scenario_with_multiple_comments_in_mu [
  run [
    # comment1
    # comment2
    10:num <- add 2, 2
  ]
  memory-should-contain [
    10 <- 4
  ]
]

scenario check_text_in_memory [
  run [
    10:num <- copy 3
    11:char <- copy 97  # 'a'
    12:char <- copy 98  # 'b'
    13:char <- copy 99  # 'c'
  ]
  memory-should-contain [
    10:array:character <- [abc]
  ]
]

scenario check_trace [
  run [
    10:num <- add 2, 2
  ]
  trace-should-contain [
    mem: storing 4 in location 10
  ]
]

scenario check_trace_negative [
  run [
    10:num <- add 2, 2
  ]
  trace-should-not-contain [
    mem: storing 3 in location 10
  ]
]

scenario check_trace_instruction [
  run [
    trace 1, [foo], [aaa]
  ]
  trace-should-contain [
    foo: aaa
  ]
]
class="o">= s end App.fake_key_pressed = {} function App.fake_key_press(key) App.fake_key_pressed[key] = true end function App.fake_key_release(key) App.fake_key_pressed[key] = nil end function App.modifier_down(key) return App.fake_key_pressed[key] end App.fake_mouse_state = {x=-1, y=-1} -- x,y always set function App.fake_mouse_press(x,y, button) App.fake_mouse_state.x = x App.fake_mouse_state.y = y App.fake_mouse_state[button] = true end function App.fake_mouse_release(x,y, button) App.fake_mouse_state.x = x App.fake_mouse_state.y = y App.fake_mouse_state[button] = nil end function App.mouse_move(x,y) App.fake_mouse_state.x = x App.fake_mouse_state.y = y end function App.mouse_down(button) return App.fake_mouse_state[button] end function App.mouse_x() return App.fake_mouse_state.x end function App.mouse_y() return App.fake_mouse_state.y end -- all textinput events are also keypresses function App.run_after_textinput(t) App.keypressed(t) App.textinput(t) App.keyreleased(t) App.screen.contents = {} App.draw() end -- not all keys are textinput function App.run_after_keychord(chord) App.keychord_pressed(chord) App.keyreleased(chord) App.screen.contents = {} App.draw() end function App.run_after_mouse_click(x,y, button) App.fake_mouse_press(x,y, button) App.mousepressed(x,y, button) App.fake_mouse_release(x,y, button) App.mousereleased(x,y, button) App.screen.contents = {} App.draw() end function App.run_after_mouse_press(x,y, button) App.fake_mouse_press(x,y, button) App.mousepressed(x,y, button) App.screen.contents = {} App.draw() end function App.run_after_mouse_release(x,y, button) App.fake_mouse_release(x,y, button) App.mousereleased(x,y, button) App.screen.contents = {} App.draw() end function App.screen.check(y, expected_contents, msg) --? print('checking for "'..expected_contents..'" at y '..tostring(y)) local screen_row = 'y'..tostring(y) local contents = '' if App.screen.contents[screen_row] == nil then error('no text at y '..tostring(y)) end for i,s in ipairs(App.screen.contents[screen_row]) do contents = contents..s end check_eq(contents, expected_contents, msg) end -- fake files function App.open_for_writing(filename) App.filesystem[filename] = '' return { write = function(self, ...) local args = {...} for i,s in ipairs(args) do App.filesystem[filename] = App.filesystem[filename]..s end end, close = function(self) end } end function App.open_for_reading(filename) return { lines = function(self) return App.filesystem[filename]:gmatch('[^\n]+') end, close = function(self) end } end function App.run_tests() local sorted_names = {} for name,binding in pairs(_G) do if name:find('test_') == 1 then table.insert(sorted_names, name) end end table.sort(sorted_names) for _,name in ipairs(sorted_names) do App.initialize_for_test() _G[name]() end print() -- clean up all test methods for _,name in ipairs(sorted_names) do _G[name] = nil end end -- call this once all tests are run -- can't run any tests after this function App.disable_tests() -- have LÖVE delegate all handlers to App if they exist for name in pairs(love.handlers) do if App[name] then love.handlers[name] = App[name] end end -- test methods are disallowed outside tests App.screen.init = nil App.filesystem = nil App.time = nil App.run_after_textinput = nil App.run_after_keychord = nil App.keypress = nil App.keyrelease = nil App.run_after_mouse_click = nil App.run_after_mouse_press = nil App.run_after_mouse_release = nil App.fake_key_pressed = nil App.fake_key_press = nil App.fake_key_release = nil App.fake_mouse_state = nil App.fake_mouse_press = nil App.fake_mouse_release = nil -- other methods dispatch to real hardware App.screen.print = love.graphics.print App.newText = love.graphics.newText App.screen.draw = love.graphics.draw App.width = function(text) return text:getWidth() end App.open_for_reading = function(filename) return io.open(filename, 'r') end App.open_for_writing = function(filename) return io.open(filename, 'w') end App.getTime = love.timer.getTime App.getClipboardText = love.system.getClipboardText App.setClipboardText = love.system.setClipboardText App.modifier_down = love.keyboard.isDown App.mouse_move = love.mouse.setPosition App.mouse_down = love.mouse.isDown App.mouse_x = love.mouse.getX App.mouse_y = love.mouse.getY end