Implement distributivity in $scalar ~~ @array
[p5sagit/p5-mst-13.2.git] / t / op / smartmatch.t
index 3838518..2c6e5f1 100644 (file)
@@ -13,6 +13,7 @@ use Tie::Hash;
 # Predeclare vars used in the tests:
 my @empty;
 my %empty;
+my @sparse; $sparse[2] = 2;
 
 my $deep1 = []; push @$deep1, \$deep1;
 my $deep2 = []; push @$deep2, \$deep2;
@@ -150,7 +151,7 @@ __DATA__
 
 # regular object
 @      $obj            $obj
-@      $ov_obj         $obj    TODO
+@      $ov_obj         $obj
 @      \&fatal         $obj
 @      \&FALSE         $obj
 @      \&foo           $obj
@@ -200,6 +201,8 @@ __DATA__
        qr//            \&bar
 !      [1]             \&foo
 !      {a=>1}          \&foo
+       $obj            sub { ref $_[0] =~ /NoOverload/ }       TODO
+       $ov_obj         sub { ref $_[0] =~ /CopyOverload/ }     TODO
 # empty stuff matches, because the sub is never called:
        []              \&foo
        {}              \&foo
@@ -312,6 +315,10 @@ __DATA__
 =      \@nums                  @tied_nums
 =      @nums                   @tied_nums
 
+#  - an object
+!      $obj            @fooormore
+       $obj            [sub{ref shift}]        TODO
+
 #  - works with lists instead of arrays
        "foo"                   qw(foo bar)     TODO
        "foo"                   ('foo','bar')   TODO
@@ -325,7 +332,7 @@ __DATA__
 !      /bar/           @fooormore
 
 # - a number
-       2               [qw(1foo 2bar)]
+       2               [qw(1.00 2.00)]
        2               [qw(foo 2)]
        2.0_0e+0        [qw(foo 2)]
 !      2               [qw(1foo bar2)]
@@ -334,6 +341,18 @@ __DATA__
 !      "2"             [qw(1foo 2bar)]
        "2bar"          [qw(1foo 2bar)]
 
+# - undef
+       undef           [1, 2, undef, 4]
+!      undef           [1, 2, [undef], 4]
+!      undef           @fooormore
+       undef           @sparse
+
+# - nested arrays and ~~ distributivity
+       11              [[11]]
+!      11              [[12]]
+       "foo"           [{foo => "bar"}]
+!      "bar"           [{foo => "bar"}]
+
 # Number against number
        2               2
        20              2_0