13 # Predeclare vars used in the tests:
14 my $deep1 = []; push @$deep1, \$deep1;
15 my $deep2 = []; push @$deep2, \$deep2;
18 tie my @tied_nums, 'Tie::StdArray';
21 my %hash = (foo => 17, bar => 23);
22 tie my %tied_hash, 'Tie::StdHash';
26 package Test::Object::NoOverload;
27 sub new { bless { key => 1 } }
31 package Test::Object::CopyOverload;
32 sub new { bless { key => 1 } }
33 use overload '~~' => sub { my %hash = %{ $_[0] }; %hash ~~ $_[1] };
36 our $ov_obj = Test::Object::CopyOverload->new;
37 our $obj = Test::Object::NoOverload->new;
39 my @keyandmore = qw(key and more);
40 my @fooormore = qw(foo or more);
41 my %keyandmore = map { $_ => 0 } @keyandmore;
42 my %fooormore = map { $_ => 0 } @fooormore;
44 # Load and run the tests
48 next if /^#/ || !/\S/;
50 my ($yn, $left, $right, $note) = split /\t+/;
52 local $::TODO = $note =~ /TODO/;
54 die "Bad test spec: ($yn, $left, $right)" if $yn =~ /[^!@=]/;
56 my $tstr = "$left ~~ $right";
64 ok( $@ ne '', "$tstr dies" )
65 and print "# \$\@ was: $@\n";
67 my $test_name = $tstr . ($yn =~ /!/ ? " does not match" : " matches");
70 print "# \$\@ was: $@\n";
72 ok( ($yn =~ /!/ xor $res), $test_name );
77 $tstr = "$right ~~ $left";
87 sub fatal {die "fatal sub\n"}
95 # ! - expected to not match
96 # @ - expected to be a compilation failure
97 # = - expected to match symmetrically (runs test twice)
98 # Data types to test :
107 # Tied arrays and hashes
108 # Arrays that reference themselves
109 # Regex (// and qr//)
113 # Other syntactic items of interest:
115 # Values returned by a sub call
140 # Any ~~ object overloaded
141 # object overloaded ~~ Any
147 = $ov_obj sub { shift ~~ "key" }
148 =! $ov_obj sub { shift eq "key" }
149 =! $ov_obj sub { shift ~~ "foo" }
150 = $ov_obj %keyandmore TODO
151 =! $ov_obj %fooormore
152 = $ov_obj {"key" => 1}
153 = $ov_obj {"key" => 1, bar => 2} TODO
154 =! $ov_obj {"foo" => 1}
155 = $ov_obj @keyandmore
156 =! $ov_obj @fooormore
157 = $ov_obj ["key" => 1]
158 =! $ov_obj ["foo" => 1]
184 # CODE ref against argument
188 # - arg is not code ref
208 # pass argument by reference
209 @fooormore sub{scalar @_ == 1}
210 @fooormore sub{"@_" =~ /ARRAY/}
211 %fooormore sub{"@_" =~ /HASH/}
212 /fooormore/ sub{ref $_[0] eq 'Regexp'}
214 # - null-prototyped subs
223 # - non-null-prototyped subs
234 \%main:: {map {$_ => 'x'} keys %main::}
238 \%tied_hash \%tied_hash
245 { foo => 1 } ["foo", "bar"]
246 \%hash ["foo", "bar"]
249 \%hash [qw(foo quux)]
252 {foo => 1} qr/^(fo[ox])$/
253 ! +{0..99} qr/[13579]$/
256 +{foo => 1, bar => 2} "foo"
257 ! +{foo => 1, bar => 2} "baz"
261 # - another array ref
264 [["foo"], ["bar"]] [qr/o/, qr/a/]
265 ["foo", "bar"] [qr/o/, qr/a/]
266 ! ["foo", "bar"] [qr/o/, "foo"]
273 [qw(foo bar baz quux)] qr/x/
274 ! [qw(foo bar baz quux)] qr/y/
283 ! [qw(1foo 2bar)] "2"
284 [qw(1foo 2bar)] "2bar"
286 # Number against number
292 # Number against string
299 # Regex against string
303 # Regex against number
307 # Test the implicit referencing
322 %tied_hash %tied_hash
323 %hash { foo => 5, bar => 10 }
324 ! %hash { foo => 5, bar => 10, quux => 15 }
326 @nums { 1, '', 2, '' }
327 @nums { 1, '', 12, '' }
328 ! @nums { 11, '', 12, '' }