X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fsmartmatch.t;h=b2a213ec35360e1575807fdf278da5b43d2bc87f;hb=2522c35a141b3975f20e7418066d600920f74ac7;hp=6993c2e732cc22898d5a6b018aede75f2730fba0;hpb=fc8390768718c75e7007d3afdce4bc61fb3ea97b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t index 6993c2e..b2a213e 100644 --- a/t/op/smartmatch.t +++ b/t/op/smartmatch.t @@ -29,8 +29,8 @@ tie my %tied_hash, 'Tie::StdHash'; { package Test::Object::CopyOverload; - sub new { bless { key => 1 } } - use overload '~~' => sub { my %hash = %{ $_[0] }; $_[1] ~~ %hash }; + sub new { bless { key => 'magic' } } + use overload '~~' => sub { my %hash = %{ $_[0] }; $_[1] eq $hash{key} }; } our $ov_obj = Test::Object::CopyOverload->new; @@ -87,6 +87,7 @@ sub fatal {die "fatal sub\n"} # to test constant folding sub FALSE() { 0 } sub TRUE() { 1 } +sub NOT_DEF() { undef } # Prefix character : # - expected to match @@ -134,18 +135,17 @@ __DATA__ ! !1 undef undef undef (my $u) undef + NOT_DEF undef + &NOT_DEF undef # Any ~~ object overloaded # object overloaded ~~ Any - $ov_obj $ov_obj =! $ov_obj \&fatal -= $ov_obj {"key" => 2} -=! $ov_obj {"key" => 1, bar => 2} -= $ov_obj /key/ -=! $ov_obj /bar/ += $ov_obj 'magic' +=! $ov_obj 'not magic' +=! $ov_obj $obj # regular object -=@ $obj $ov_obj @ $obj $obj =@ $obj \&fatal =@ $obj \&FALSE @@ -217,7 +217,7 @@ __DATA__ \%main:: {map {$_ => 'x'} keys %main::} # - tied hash ref - \%hash \%tied_hash += \%hash \%tied_hash \%tied_hash \%tied_hash # - an array ref @@ -245,6 +245,7 @@ __DATA__ ! "baz" +{foo => 1, bar => 2} # - undef +! undef { hop => 'zouu' } ! undef %hash ! undef +{"" => "empty key"} ! undef {} @@ -252,11 +253,15 @@ __DATA__ # ARRAY ref against: # - another array ref [] [] -! [] [1] +=! [] [1] ! [["foo"], ["bar"]] [qr/o/, qr/a/] [["foo"], ["bar"]] [qr/ARRAY/, qr/ARRAY/] ["foo", "bar"] [qr/o/, qr/a/] + ["foo", "bar"] [["foo"], ["bar"]] ! ["foo", "bar"] [qr/o/, "foo"] + ["foo", undef, "bar"] [qr/o/, undef, "bar"] + ["foo", undef, "bar"] [qr/o/, "", "bar"] +! ["foo", "", "bar"] [qr/o/, undef, "bar"] $deep1 $deep1 ! $deep1 $deep2 @@ -299,6 +304,7 @@ __DATA__ # Regex against number 12345 qr/3/ +! 12345 qr/7/ # Test the implicit referencing 7 @nums