fixup wesnoth.wml_conditionals, add unit tests
This commit is contained in:
parent
28ee933dd8
commit
f4c99b3a1a
4 changed files with 81 additions and 2 deletions
77
data/test/scenarios/test_lua_wml.cfg
Normal file
77
data/test/scenarios/test_lua_wml.cfg
Normal file
|
@ -0,0 +1,77 @@
|
|||
{GENERIC_UNIT_TEST "test_wml_actions" (
|
||||
[event]
|
||||
name = start
|
||||
[lua]
|
||||
code = <<
|
||||
function wesnoth.wml_actions.foo(cfg)
|
||||
if cfg.bar then
|
||||
wesnoth.set_variable("result", cfg.bar)
|
||||
end
|
||||
end
|
||||
>>
|
||||
[/lua]
|
||||
|
||||
{VARIABLE result 0}
|
||||
{ASSERT {VARIABLE_CONDITIONAL result equals 0}}
|
||||
|
||||
[foo]
|
||||
bar = 1
|
||||
[/foo]
|
||||
|
||||
{ASSERT {VARIABLE_CONDITIONAL result equals "1"}}
|
||||
|
||||
[foo]
|
||||
baz = 0
|
||||
[/foo]
|
||||
|
||||
{ASSERT {VARIABLE_CONDITIONAL result equals "1"}}
|
||||
|
||||
[foo]
|
||||
bar = 2
|
||||
[/foo]
|
||||
|
||||
{RETURN {VARIABLE_CONDITIONAL result equals "2"}}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{GENERIC_UNIT_TEST "test_wml_conditionals" (
|
||||
[event]
|
||||
name = start
|
||||
[lua]
|
||||
code = <<
|
||||
function wesnoth.wml_conditionals.foo(cfg)
|
||||
return (cfg.bar == "baz")
|
||||
end
|
||||
>>
|
||||
[/lua]
|
||||
|
||||
{ASSERT ([foo]
|
||||
bar = "baz"
|
||||
[/foo])}
|
||||
{ASSERT ([not]
|
||||
[foo]
|
||||
bar = "boo"
|
||||
[/foo]
|
||||
[/not])}
|
||||
{ASSERT ([foo]
|
||||
bar = "baz"
|
||||
[/foo]
|
||||
[or]
|
||||
[foo]
|
||||
bar = "boo"
|
||||
[/foo]
|
||||
[/or])}
|
||||
{ASSERT ([not]
|
||||
[foo]
|
||||
bar = "baz"
|
||||
[/foo]
|
||||
[and]
|
||||
[foo]
|
||||
bar = "boo"
|
||||
[/foo]
|
||||
[/and]
|
||||
[/not])}
|
||||
|
||||
{RETURN ([true][/true])}
|
||||
[/event]
|
||||
)}
|
|
@ -174,7 +174,7 @@ namespace { // Support functions
|
|||
|
||||
vconfig::all_children_iterator cond_end = cond.ordered_end();
|
||||
static const boost::container::flat_set<std::string> hard_coded = boost::assign::list_of("true")("false")("have_unit")("have_location")("variable")
|
||||
("then")("else")("elseif")("not")("and")("or")("do");
|
||||
("then")("else")("elseif")("not")("and")("or")("do").convert_to_container<boost::container::flat_set<std::string> >();
|
||||
|
||||
assert(resources::lua_kernel);
|
||||
|
||||
|
|
|
@ -4445,7 +4445,7 @@ bool game_lua_kernel::run_wml_conditional(std::string const &cmd, vconfig const
|
|||
}
|
||||
|
||||
luaW_pushvconfig(L, cfg);
|
||||
luaW_pcall(L, 1, 0, true);
|
||||
luaW_pcall(L, 1, 1, true);
|
||||
|
||||
bool b = luaW_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
|
|
@ -93,6 +93,8 @@
|
|||
0 lua_dofile
|
||||
0 lua_require
|
||||
0 lua_get_sides
|
||||
0 test_wml_actions
|
||||
0 test_wml_conditionals
|
||||
#
|
||||
# Pathfinding
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue