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 # Load and run the tests
43 next if /^#/ || !/\S/;
45 my ($yn, $left, $right) = split /\t+/;
47 match_test($yn, $left, $right);
48 match_test($yn, $right, $left);
52 my ($yn, $left, $right) = @_;
54 die "Bad test spec: ($yn, $left, $right)"
55 unless $yn eq "" || $yn eq "!" || $yn eq '@';
57 my $tstr = "$left ~~ $right";
64 ok( $@ ne '', "$tstr dies" )
65 and print "# \$\@ was: $@\n";
67 my $test_name = $tstr . ($yn eq '!' ? " does not match" : " matches");
70 print "# \$\@ was: $@\n";
72 ok( ($yn eq '!' xor $res), $test_name );
82 sub fatal {die "fatal sub\n"}
84 sub a_const() {die "const\n" if @_; "a constant"}
85 sub b_const() {die "const\n" if @_; "a constant"}
92 # ! - expected to not match
93 # @ - expected to be a compilation failure
100 $ov_obj sub { shift ~~ "key" }
101 ! $ov_obj sub { shift ~~ "foo" }
120 # CODE ref against argument
124 ! \&foo sub { "$_[0]" =~ /^CODE/ }
129 # - arg is not code ref
152 # - null-prototyped subs
157 ! \&a_const \&b_const
173 # - non-null-prototyped subs
185 \%main:: {map {$_ => 'x'} keys %main::}
189 \%tied_hash \%tied_hash
196 { foo => 1 } ["foo", "bar"]
197 \%hash ["foo", "bar"]
200 \%hash [qw(foo quux)]
203 {foo => 1} qr/^(fo[ox])$/
204 ! +{0..100} qr/[13579]$/
207 +{foo => 1, bar => 2} "foo"
208 ! +{foo => 1, bar => 2} "baz"
212 # - another array ref
215 [["foo"], ["bar"]] [qr/o/, qr/a/]
216 ["foo", "bar"] [qr/o/, qr/a/]
217 ! ["foo", "bar"] [qr/o/, "foo"]
224 [qw(foo bar baz quux)] qr/x/
225 ! [qw(foo bar baz quux)] qr/y/
234 ! [qw(1foo 2bar)] "2"
235 [qw(1foo 2bar)] "2bar"
237 # Number against number
243 # Number against string
250 # Regex against string
254 # Regex against number
258 # Test the implicit referencing
272 %tied_hash %tied_hash
273 %hash { foo => 5, bar => 10 }
274 ! %hash { foo => 5, bar => 10, quux => 15 }
276 @nums { 1, '', 2, '' }
277 @nums { 1, '', 12, '' }
278 ! @nums { 11, '', 12, '' }