Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Oct 11, 2024
1 parent 1155c9d commit 4931bd4
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions misc/test/loop_modifiers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use warnings;

###################
# Perl `next` Tests with `do ... while ...`
# `next` Tests with `do ... while ...`

my $next_do_while_count = 0;
eval q{
Expand All @@ -18,10 +18,10 @@
print "not "
if !($error_message
&& $error_message =~ /Can't "next" outside a loop block/ );
say "ok # Correct error message for `next` outside a loop";
say "ok # error message for `next` outside a loop";

###################
# Perl `next` Tests with `do ... while ...` with an outer loop
# `next` Tests with `do ... while ...` with an outer loop

$next_do_while_count = 0;
{
Expand All @@ -31,14 +31,31 @@
} while ( $next_do_while_count < 4 );
}
print "not " if $next_do_while_count != 2;
say "ok # Correct `next` outside a loop";
say "ok # `next` outside a loop";

###################
# Perl `next` Tests with `for` modifier
# `next` Tests with `for` modifier

my $next_for_count = 0;
$next_for_count++ for 1 .. 3;
$next_for_count == 2 && next for 1 .. 3; # Skip when count is 2
print "not " if $next_for_count != 3;
say "ok # `next` in `for` modifier";


###################
# `while` loop

my $while_mod_count = 0;
$while_mod_count++ while 0; # never executes
print "not " if $while_mod_count != 0;
say "ok # `while` loop with statement modifier";

###################
# `do-while` loop

$while_mod_count = 0;
do { $while_mod_count++ } while 0; # executes once
print "not " if $while_mod_count != 1;
say "ok # `while` loop with statement modifier";

0 comments on commit 4931bd4

Please sign in to comment.