Skip to content

Commit a4cde9f

Browse files
committed
tests if the conditions of an if are checked in order
1 parent 6ba8ab4 commit a4cde9f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

S04-statements/if.t

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Basic "if" tests.
1111

1212
# L<S04/Conditional statements>
1313

14-
plan 25;
14+
plan 29;
1515

1616
my $x = 'test';
1717
if ($x eq $x) { pass('if ($x eq $x) {} works'); } else { flunk('if ($x eq $x) {} failed'); }
@@ -150,6 +150,21 @@ if (Mu) { flunk('if (Mu) {} failed'); } else { pass('if (Mu) {} works'); }
150150
is $got, '', 'else -> $c { } binding previous if';
151151
}
152152

153+
{
154+
my $called = 0;
155+
sub cond($when) {
156+
is $called,$when,"condition is checked in correct order";
157+
$called++;
158+
0;
159+
}
160+
if cond(0) {
161+
} elsif cond(1) {
162+
} elsif cond(2) {
163+
}
164+
is $called,3,"all conditions are checked";
165+
}
166+
167+
153168
#?niecza skip "eval_unimplemented"
154169
# L<S04/Statement parsing/keywords require whitespace>
155170
eval_dies_ok('if($x > 1) {}','keyword needs at least one whitespace after it');

0 commit comments

Comments
 (0)