mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
third pass
This commit is contained in:
parent
24813ff2ea
commit
e9f35319df
@ -13,7 +13,7 @@ Declare.module(
|
||||
for _, name in pairs(Gui._top_elements) do
|
||||
Declare.test(
|
||||
'can toggle - ' .. Gui.names[name],
|
||||
function(step)
|
||||
function(steps)
|
||||
local player = game.get_player(1)
|
||||
local element = player.gui.top[name]
|
||||
local event = EventFactory.on_gui_click(element, player.index)
|
||||
@ -32,9 +32,7 @@ Declare.module(
|
||||
)
|
||||
|
||||
-- Close
|
||||
step = step:next(click_action)
|
||||
|
||||
step:next(
|
||||
steps:next(click_action):next(
|
||||
function()
|
||||
local after_close_count = count_gui_elements(player.gui)
|
||||
Assert.equal(
|
||||
|
@ -9,7 +9,7 @@ local Public = {}
|
||||
|
||||
local function build_tests_inner(module, tests)
|
||||
for name, func in pairs(module.tests) do
|
||||
tests[#tests + 1] = {name = name, func = func, context = Steps.new()}
|
||||
tests[#tests + 1] = {name = name, func = func, steps = Steps.new(), current_step = 0}
|
||||
end
|
||||
|
||||
for _, child in pairs(module.children) do
|
||||
@ -32,15 +32,22 @@ local function print_success(test_name)
|
||||
end
|
||||
|
||||
local function run_test(test)
|
||||
local success, return_value = pcall(test.func, test.context)
|
||||
local steps = test.steps
|
||||
local current_step = test.current_step
|
||||
local func
|
||||
if current_step == 0 then
|
||||
func = test.func
|
||||
else
|
||||
func = steps[current_step].func
|
||||
end
|
||||
local success, return_value = pcall(func, steps)
|
||||
|
||||
if not success then
|
||||
print_error(test.name, return_value)
|
||||
return false
|
||||
end
|
||||
|
||||
local next_func = test.context._func
|
||||
if not next_func then
|
||||
if current_step == #steps then
|
||||
print_success(test.name)
|
||||
return true
|
||||
end
|
||||
@ -80,10 +87,10 @@ local function run_tests(data)
|
||||
return
|
||||
end
|
||||
|
||||
local context = test.context
|
||||
test.func = context._func
|
||||
test.context = context._child
|
||||
Task.set_timeout_in_ticks(context._delay or 1, run_tests_token, data)
|
||||
local step_index = test.current_step + 1
|
||||
test.current_step = step_index
|
||||
local step = test.steps[step_index]
|
||||
Task.set_timeout_in_ticks(step.delay or 1, run_tests_token, data)
|
||||
end
|
||||
|
||||
run_tests_token = Token.register(run_tests)
|
||||
|
@ -2,15 +2,16 @@ local Public = {}
|
||||
Public.__index = Public
|
||||
|
||||
function Public.new()
|
||||
return setmetatable({_child = nil, _func = nil, _delay = nil}, Public)
|
||||
return setmetatable({}, Public)
|
||||
end
|
||||
|
||||
function Public.next(self, func, delay)
|
||||
local context = Public.new()
|
||||
self._child = context
|
||||
self._func = func
|
||||
self._delay = delay
|
||||
return context
|
||||
function Public.timeout(self, delay, func)
|
||||
self[#self + 1] = {func = func, delay = delay or 1}
|
||||
return self
|
||||
end
|
||||
|
||||
function Public.next(self, func)
|
||||
return self:timeout(1, func)
|
||||
end
|
||||
|
||||
return Public
|
||||
|
Loading…
x
Reference in New Issue
Block a user