Fix erroneous handling of [break]/[continue] in [elseif]
This commit is contained in:
parent
0d49eeeb39
commit
7e26e09061
4 changed files with 93 additions and 15 deletions
|
@ -300,12 +300,11 @@ wml_actions["if"] = function(cfg)
|
|||
if wesnoth.eval_conditional(elseif_child) then -- we'll evaluate the [elseif] tags one by one
|
||||
for then_tag in helper.child_range(elseif_child, "then") do
|
||||
local action = utils.handle_event_commands(then_tag, "conditional")
|
||||
if action ~= "none" then goto exit end
|
||||
if action ~= "none" then break end
|
||||
end
|
||||
return -- stop on first matched condition
|
||||
end
|
||||
end
|
||||
::exit::
|
||||
|
||||
-- no matched condition, try the [else] tags
|
||||
for else_child in helper.child_range(cfg, "else") do
|
||||
|
|
|
@ -141,7 +141,7 @@ function utils.handle_event_commands(cfg, scope_type)
|
|||
end
|
||||
scope_stack:pop()
|
||||
if #scope_stack == 0 then
|
||||
if current_exit == "continue" and scope_type ~= "loop" then
|
||||
if current_exit == "continue" and scope_type ~= "loop" then
|
||||
helper.wml_error("[continue] found outside a loop scope!")
|
||||
end
|
||||
current_exit = "none"
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
{VARIABLE_OP x add 1}
|
||||
[/do]
|
||||
[/while]
|
||||
{RETURN ([false][/false])}
|
||||
{FAIL}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
|
@ -48,14 +48,14 @@
|
|||
name=start
|
||||
{VARIABLE x 0}
|
||||
[while]
|
||||
{VARIABLE_CONDITIONAL x less_than 1}
|
||||
{VARIABLE_CONDITIONAL x less_than 5}
|
||||
[do]
|
||||
{VARIABLE_OP x add 1}
|
||||
{VARIABLE_OP x add 5}
|
||||
[continue][/continue]
|
||||
{RETURN ([false][/false])}
|
||||
{FAIL}
|
||||
[/do]
|
||||
[/while]
|
||||
{RETURN ([true][/true])}
|
||||
{RETURN ({VARIABLE_CONDITIONAL x equals 5})}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
|
@ -63,11 +63,11 @@
|
|||
[event]
|
||||
name=start
|
||||
[break][/break]
|
||||
{RETURN ([false][/false])}
|
||||
{FAIL}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
{RETURN ([true][/true])}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
|
@ -90,11 +90,11 @@
|
|||
[/event]
|
||||
[event]
|
||||
name=success
|
||||
{RETURN ([true][/true])}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
[event]
|
||||
name=fail
|
||||
{RETURN ([false][/false])}
|
||||
{FAIL}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
|
@ -103,12 +103,89 @@
|
|||
name=start
|
||||
[command]
|
||||
[return][/return]
|
||||
{RETURN ([false][/false])}
|
||||
{FAIL}
|
||||
[/command]
|
||||
{RETURN ([false][/false])}
|
||||
{FAIL}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
{RETURN ([true][/true])}
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{GENERIC_UNIT_TEST check_interrupts_elseif (
|
||||
[event]
|
||||
name=start
|
||||
{VARIABLE x 9}
|
||||
[if]
|
||||
{VARIABLE_CONDITIONAL x greater_than 10}
|
||||
[then]
|
||||
{FAIL}
|
||||
[/then]
|
||||
[elseif]
|
||||
{VARIABLE_CONDITIONAL x less_than 10}
|
||||
[then]
|
||||
[return][/return]
|
||||
[/then]
|
||||
[/elseif]
|
||||
[else]
|
||||
[wml_message]
|
||||
message="Reached the [else] block!"
|
||||
logger=error
|
||||
[/wml_message]
|
||||
{FAIL}
|
||||
[/else]
|
||||
[/if]
|
||||
[wml_message]
|
||||
message="Passed the [if] block!"
|
||||
logger=error
|
||||
[/wml_message]
|
||||
{FAIL}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{GENERIC_UNIT_TEST check_interrupts_case (
|
||||
[event]
|
||||
name=start
|
||||
{VARIABLE x 0}
|
||||
[switch]
|
||||
variable=x
|
||||
[case]
|
||||
value=1,3,5,7,9
|
||||
{FAIL}
|
||||
[/case]
|
||||
[case]
|
||||
value=0,2,4,6,8
|
||||
[return][/return]
|
||||
[/case]
|
||||
[case]
|
||||
value=0
|
||||
[wml_message]
|
||||
message="Reached next [case] block!"
|
||||
logger=error
|
||||
[/wml_message]
|
||||
{FAIL}
|
||||
[/case]
|
||||
[else]
|
||||
[wml_message]
|
||||
message="Reached the [else] block!"
|
||||
logger=error
|
||||
[/wml_message]
|
||||
{FAIL}
|
||||
[/else]
|
||||
[/switch]
|
||||
[wml_message]
|
||||
message="Passed the [switch] block!"
|
||||
logger=error
|
||||
[/wml_message]
|
||||
{FAIL}
|
||||
[/event]
|
||||
[event]
|
||||
name=start
|
||||
{SUCCEED}
|
||||
[/event]
|
||||
)}
|
||||
|
|
|
@ -154,3 +154,5 @@
|
|||
0 check_interrupts_break_global
|
||||
0 check_interrupts_return_nested
|
||||
0 check_interrupts_continue_global
|
||||
0 check_interrupts_elseif
|
||||
0 check_interrupts_case
|
||||
|
|
Loading…
Add table
Reference in a new issue