mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-18 16:46:04 +00:00
Unit tests for each way of assigning an action to an event handler
This commit is contained in:
parent
d03116f829
commit
245cd57d24
99
data/test/scenarios/events-test_actions.cfg
Normal file
99
data/test/scenarios/events-test_actions.cfg
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
# This is kinda a duplicate of a basic unit test system sanity test, but... it seems to fit here as well...
|
||||
{GENERIC_UNIT_TEST "event_test_action_wml" (
|
||||
[event]
|
||||
name=start
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
# Test that dynamically adding an event from Lua works
|
||||
# There's two different ways of calling game_events.add, so test both
|
||||
{GENERIC_UNIT_TEST "event_test_lua" (
|
||||
[event]
|
||||
name=preload
|
||||
[lua]
|
||||
code=<<
|
||||
wesnoth.game_events.add('new turn', function()
|
||||
unit_test.succeed()
|
||||
end)
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
)}
|
||||
{GENERIC_UNIT_TEST "event_test_lua_advanced" (
|
||||
[event]
|
||||
name=preload
|
||||
[lua]
|
||||
code=<<
|
||||
wesnoth.game_events.add{
|
||||
name = 'new turn',
|
||||
action = function()
|
||||
unit_test.succeed()
|
||||
end
|
||||
}
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
# Test that first_time_only works correctly in Lua events
|
||||
{GENERIC_UNIT_TEST "event_test_lua_repeat" (
|
||||
[event]
|
||||
name=preload
|
||||
[lua]
|
||||
code=<<
|
||||
wml.variables.only_once = 0
|
||||
wml.variables.should_repeat = 0
|
||||
wesnoth.game_events.add{
|
||||
name = 'new turn',
|
||||
first_time_only = true,
|
||||
action = function()
|
||||
wml.variables.only_once = wml.variables.only_once + 1
|
||||
end
|
||||
}
|
||||
wesnoth.game_events.add{
|
||||
name = 'new turn',
|
||||
first_time_only = false,
|
||||
action = function()
|
||||
wml.variables.should_repeat = wml.variables.should_repeat + 1
|
||||
end
|
||||
}
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
[event]
|
||||
name=side 1 turn 1
|
||||
[end_turn][/end_turn]
|
||||
[/event]
|
||||
[event]
|
||||
name=side 2 turn 1
|
||||
[end_turn][/end_turn]
|
||||
[/event]
|
||||
[event]
|
||||
name=side 1 turn 2
|
||||
[end_turn][/end_turn]
|
||||
[/event]
|
||||
[event]
|
||||
name=side 2 turn 2
|
||||
{ASSERT ({VARIABLE_CONDITIONAL only_once equals 1})}
|
||||
{ASSERT ({VARIABLE_CONDITIONAL should_repeat equals 2})}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
# Verify that a warning is produced if adding an event that would break saved games
|
||||
{GENERIC_UNIT_TEST "event_test_lua_break_save" (
|
||||
[event]
|
||||
name=start
|
||||
[lua]
|
||||
code=<<
|
||||
wesnoth.game_events.add{
|
||||
name = 'new turn',
|
||||
action = function() end
|
||||
}
|
||||
unit_test.succeed()
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
)}
|
@ -139,6 +139,11 @@
|
||||
0 test_ability_id_active
|
||||
0 test_ability_id_not_active
|
||||
0 event_test_filter_attack
|
||||
0 event_test_action_wml
|
||||
0 event_test_lua
|
||||
0 event_test_lua_advanced
|
||||
0 event_test_lua_repeat
|
||||
9 event_test_lua_break_save
|
||||
0 test_lua_name
|
||||
0 filter_vision
|
||||
0 test_shroud_init
|
||||
|
Loading…
x
Reference in New Issue
Block a user