Add unit tests for the Lua shroud functions

This commit is contained in:
Celtic Minstrel 2021-07-25 18:18:40 -04:00 committed by Celtic Minstrel
parent cda910854e
commit ab16cc614f
2 changed files with 283 additions and 0 deletions

View file

@ -0,0 +1,274 @@
#textdomain wesnoth-test
#define OBJECT_HALF_VISION
[object]
[effect]
apply_to=vision
increase=-50%
[/effect]
[/object]
#enddef
#define TEST_SHROUD_SCEN ID EVENTS
[test]
name = _ "Unit Test " + {ID}
map_file=test/maps/generic_unit_test.map
id = {ID}
random_start_time = no
#is_unit_test = yes
{DAWN}
[side]
side=1
controller=human
name = _ "Alice"
type = Elvish Archer
id=alice
shroud=yes
[modifications]
{OBJECT_HALF_VISION}
[/modifications]
[/side]
[side]
side=2
controller=ai
name = _ "Bob"
type = Orcish Grunt
id=bob
shroud=yes
[modifications]
{OBJECT_HALF_VISION}
[/modifications]
[/side]
{EVENTS}
[/test]
#enddef
#define ASSERT_SHROUDED FILTER STATE
[lua]
code=<<
local locs = wesnoth.get_locations(wml.get_child(..., 'filter'))
--print(wml.tostring(wml.get_child(..., 'filter')))
--ilua._pretty_print(locs)
local state = (...).state
for _,loc in ipairs(locs) do
local x, y = loc[1], loc[2]
unit_test.assert_equal(wesnoth.is_shrouded(1, loc), state, string.format('shroud check at (%d,%d)', loc[1], loc[2]))
end
>>
[args]
[filter]
include_borders=yes
{FILTER}
[/filter]
state={STATE}
[/args]
[/lua]
#enddef
#define ASSERT_SHROUD_DATA DATA
[lua]
code=<<
local data = (...).data
unit_test.assert_equal(data, wesnoth.get_sides{side=1}[1].__cfg.shroud_data, 'data equal')
>>
[args]
data={DATA}
[/args]
[/lua]
#enddef
# Verifies starting shroud is what we expect it to be.
# If this test fails, none of the other shroud tests can be trusted.
{TEST_SHROUD_SCEN test_shroud_init (
[event]
name=start
{ASSERT_SHROUDED x=0-2 true}
{ASSERT_SHROUDED x,y=3,0 true}
{ASSERT_SHROUDED x,y=3,6-9 true}
{ASSERT_SHROUDED x,y=3,1-5 false}
{ASSERT_SHROUDED x,y=4,6-9 true}
{ASSERT_SHROUDED x,y=4,0-5 false}
{ASSERT_SHROUDED x,y=5,7-9 true}
{ASSERT_SHROUDED x,y=5,0-6 false}
{ASSERT_SHROUDED x,y=6,7-9 true}
{ASSERT_SHROUDED x,y=6,0-6 false}
{ASSERT_SHROUDED x,y=7,8,9 true}
{ASSERT_SHROUDED x,y=7,0-7 false}
{ASSERT_SHROUDED x,y=8,7-9 true}
{ASSERT_SHROUDED x,y=8,0-6 false}
{ASSERT_SHROUDED x,y=9,7-9 true}
{ASSERT_SHROUDED x,y=9,0-6 false}
{ASSERT_SHROUDED x,y=10,6-9 true}
{ASSERT_SHROUDED x,y=10,0-5 false}
{ASSERT_SHROUDED x,y=11,0 true}
{ASSERT_SHROUDED x,y=11,6-9 true}
{ASSERT_SHROUDED x,y=11,1-5 false}
{ASSERT_SHROUDED x=12-17 true}
{ASSERT_SHROUD_DATA "|
|
|
|011111
|111111
|1111111
|1111111
|11111111
|1111111
|1111111
|111111
|011111
"}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_place_wml (
[event]
name=start
[place_shroud]
side=1
x,y=7,5
[/place_shroud]
{ASSERT_SHROUDED x,y=7,5 true}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_place_lua (
[event]
name=start
[lua]
code=<<wesnoth.place_shroud(1, {{7,5}})>>
[/lua]
{ASSERT_SHROUDED x,y=7,5 true}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_place_lua_data (
[event]
name=start
[lua]
code=<<wesnoth.place_shroud(1, (...).data)>>
[args]
data="|
|
|
|011111
|111111
|1111111
|1100011
|11010111
|1100011
|1111111
|111111
|011111
"
[/args]
[/lua]
{ASSERT_SHROUDED x,y=6,2-4 true}
{ASSERT_SHROUDED x,y=8,2-4 true}
{ASSERT_SHROUDED x,y=6-8,2 true}
{ASSERT_SHROUDED x,y=6-8,4 true}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_place_lua_all (
[event]
name=start
[lua]
code=<<wesnoth.place_shroud(1, 'all')>>
[/lua]
{ASSERT_SHROUDED x,y=0-17,0-9 true}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_remove_wml (
[event]
name=start
[remove_shroud]
side=1
x,y=13,8
[/remove_shroud]
{ASSERT_SHROUDED x,y=13,8 false}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_remove_lua (
[event]
name=start
[lua]
code=<<wesnoth.remove_shroud(1, {{13,8}})>>
[/lua]
{ASSERT_SHROUDED x,y=13,8 false}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_modify_wml (
[event]
name=start
[modify_side]
side=1
shroud_data="|
|
|
|011111
|111111
|1111111
|1111111
|11111111
|1111111
|1111111
|111111
|011111
|00111
|000111
|00111
"
[/modify_side]
{ASSERT_SHROUDED x,y=12,2-4 false}
{ASSERT_SHROUDED x,y=13,3-5 false}
{ASSERT_SHROUDED x,y=14,2-4 false}
{SUCCEED}
[/event]
)}
{TEST_SHROUD_SCEN test_shroud_modify_lua (
[event]
name=start
[lua]
code=<<
wesnoth.sides[1].shroud_data = [[|
|
|
|011111
|111111
|1111111
|1111111
|11111111
|1111111
|1111111
|111111
|011111
|00111
|000111
|00111
]]
>>
[/lua]
{ASSERT_SHROUDED x,y=12,2-4 false}
{ASSERT_SHROUDED x,y=13,3-5 false}
{ASSERT_SHROUDED x,y=14,2-4 false}
{SUCCEED}
[/event]
)}
#undef ASSERT_SHROUDED
#undef ASSERT_SHROUD_DATA
#undef OBJECT_HALF_VISION

View file

@ -134,6 +134,15 @@
0 test_ability_id_not_active
0 event_test_filter_attack
0 filter_vision
0 test_shroud_init
0 test_shroud_place_wml
0 test_shroud_place_lua
0 test_shroud_place_lua_data
0 test_shroud_place_lua_all
0 test_shroud_remove_wml
0 test_shroud_remove_lua
0 test_shroud_modify_wml
0 test_shroud_modify_lua
0 scatter_units
0 has_ally
0 xp_mod_1