From: Rafael Garcia-Suarez Date: Sun, 3 May 2009 13:26:09 +0000 (+0200) Subject: Add tests for last and next in when() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1ebfab3267504c83de6c437969845b8fbe1e7383;p=p5sagit%2Fp5-mst-13.2.git Add tests for last and next in when() --- diff --git a/t/op/switch.t b/t/op/switch.t index 9fa5b08..a4977c7 100644 --- a/t/op/switch.t +++ b/t/op/switch.t @@ -8,7 +8,7 @@ BEGIN { use strict; use warnings; -use Test::More tests => 118; +use Test::More tests => 122; # The behaviour of the feature pragma should be tested by lib/switch.t # using the tests in t/lib/switch/*. This file tests the behaviour of @@ -955,6 +955,48 @@ SKIP: { } } +# Tests for last and next in when clauses +my $letter; + +$letter = ''; +for ("a".."e") { + given ($_) { + $letter = $_; + when ("b") { last } + } + $letter = "z"; +} +is($letter, "b", "last in when"); + +$letter = ''; +LETTER1: for ("a".."e") { + given ($_) { + $letter = $_; + when ("b") { last LETTER1 } + } + $letter = "z"; +} +is($letter, "b", "last LABEL in when"); + +$letter = ''; +for ("a".."e") { + given ($_) { + when (/b|d/) { next } + $letter .= $_; + } + $letter .= ','; +} +is($letter, "a,c,e,", "next in when"); + +$letter = ''; +LETTER2: for ("a".."e") { + given ($_) { + when (/b|d/) { next LETTER2 } + $letter .= $_; + } + $letter .= ','; +} +is($letter, "a,c,e,", "next LABEL in when"); # Okay, that'll do for now. The intricacies of the smartmatch # semantics are tested in t/op/smartmatch.t