This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
More tests for when(slice)
authorRafael Garcia-Suarez <rgs@consttype.org>
Tue, 7 Sep 2010 14:18:14 +0000 (16:18 +0200)
committerRafael Garcia-Suarez <rgs@consttype.org>
Tue, 7 Sep 2010 14:18:14 +0000 (16:18 +0200)
t/op/switch.t

index 1452b78..fa05918 100644 (file)
@@ -9,7 +9,7 @@ BEGIN {
 use strict;
 use warnings;
 
-plan tests => 160;
+plan tests => 164;
 
 # 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
@@ -1162,6 +1162,44 @@ unreified_check(undef,"");
     @list = $smart_hash->(999);
     is("@list", '',      "rvalue given - list context propagation [999]");
 }
+{
+    # Array slices
+    my @list = 10 .. 15;
+    my @in_list;
+    my @in_slice;
+    for (5, 10, 15) {
+        given ($_) {
+            when (@list) {
+                push @in_list, $_;
+                continue;
+            }
+            when (@list[0..2]) {
+                push @in_slice, $_;
+            }
+        }
+    }
+    is("@in_list", "10 15", "when(array)");
+    is("@in_slice", "10", "when(array slice)");
+}
+{
+    # Hash slices
+    my %list = map { $_ => $_ } "a" .. "f";
+    my @in_list;
+    my @in_slice;
+    for ("a", "e", "i") {
+        given ($_) {
+            when (%list) {
+                push @in_list, $_;
+                continue;
+            }
+            when (@list{"a".."c"}) {
+                push @in_slice, $_;
+            }
+        }
+    }
+    is("@in_list", "a e", "when(hash)");
+    is("@in_slice", "a", "when(hash slice)");
+}
 
 # Okay, that'll do for now. The intricacies of the smartmatch
 # semantics are tested in t/op/smartmatch.t