# 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;
}
{
- package Test::Object::CopyOverload;
+ package Test::Object::WithOverload;
sub new { bless { key => 'magic' } }
use overload '~~' => sub { my %hash = %{ $_[0] }; $_[1] eq $hash{key} };
+ use overload '""' => sub { "stringified" };
+ use overload 'eq' => sub {"$_[0]" eq "$_[1]"};
}
-our $ov_obj = Test::Object::CopyOverload->new;
+our $ov_obj = Test::Object::WithOverload->new;
our $obj = Test::Object::NoOverload->new;
my @keyandmore = qw(key and more);
@ FALSE $obj
# object (overloaded or not) ~~ Any
-# TODO
+ $obj qr/NoOverload/
+ $ov_obj qr/^stringified$/
+ $ov_obj "stringified"
# ~~ Coderef
sub{0} sub { ref $_[0] eq "CODE" }
qr// \&bar
! [1] \&foo
! {a=>1} \&foo
+ $obj sub { ref($_[0]) =~ /NoOverload/ }
+ $ov_obj sub { ref($_[0]) =~ /WithOverload/ }
# empty stuff matches, because the sub is never called:
[] \&foo
{} \&foo
= \@fooormore %fooormore
# - a regex
-# TODO those should be symmetrical
- qr/^(fo[ox])$/ {foo => 1}
- /^(fo[ox])$/ %fooormore
+= qr/^(fo[ox])$/ {foo => 1}
+= /^(fo[ox])$/ %fooormore
=! qr/[13579]$/ +{0..99}
-! qr/a*/ {}
+=! qr/a*/ {}
= qr/a*/ {b=>2}
- qr/B/i {b=>2}
- /B/i {b=>2}
-! qr/a+/ {b=>2}
- qr/^à/ {"à"=>2}
+= qr/B/i {b=>2}
+= /B/i {b=>2}
+=! qr/a+/ {b=>2}
+= qr/^à/ {"à"=>2}
# - a scalar
"foo" +{foo => 1, bar => 2}
# - another array ref
[] []
=! [] [1]
-! [["foo"], ["bar"]] [qr/o/, qr/a/]
- [["foo"], ["bar"]] [qr/ARRAY/, qr/ARRAY/]
+ [["foo"], ["bar"]] [qr/o/, qr/a/]
+! [["foo"], ["bar"]] [qr/ARRAY/, qr/ARRAY/]
["foo", "bar"] [qr/o/, qr/a/]
! [qr/o/, qr/a/] ["foo", "bar"]
["foo", "bar"] [["foo"], ["bar"]]
= \@nums @tied_nums
= @nums @tied_nums
+# - an object
+! $obj @fooormore
+ $obj [sub{ref shift}]
+
# - works with lists instead of arrays
"foo" qw(foo bar) TODO
"foo" ('foo','bar') TODO
# - a regex
- qr/x/ [qw(foo bar baz quux)]
-! qr/y/ [qw(foo bar baz quux)]
- /x/ [qw(foo bar baz quux)]
-! /y/ [qw(foo bar baz quux)]
- /FOO/i @fooormore
-! /bar/ @fooormore
+= qr/x/ [qw(foo bar baz quux)]
+=! qr/y/ [qw(foo bar baz quux)]
+= /x/ [qw(foo bar baz quux)]
+=! /y/ [qw(foo bar baz quux)]
+= /FOO/i @fooormore
+=! /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)]
! "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