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 {"foo" => 1}
102 ! $ov_obj ["foo" => 1]
103 $ov_obj sub { shift ~~ "key" }
104 ! $ov_obj sub { shift ~~ "foo" }
126 # CODE ref against argument
130 ! \&foo sub { "$_[0]" =~ /^CODE/ }
135 # - arg is not code ref
156 # - null-prototyped subs
161 ! \&a_const \&b_const
177 # - non-null-prototyped subs
189 \%main:: {map {$_ => 'x'} keys %main::}
193 \%tied_hash \%tied_hash
200 { foo => 1 } ["foo", "bar"]
201 \%hash ["foo", "bar"]
204 \%hash [qw(foo quux)]
207 {foo => 1} qr/^(fo[ox])$/
208 ! +{0..99} qr/[13579]$/
211 +{foo => 1, bar => 2} "foo"
212 ! +{foo => 1, bar => 2} "baz"
216 # - another array ref
219 [["foo"], ["bar"]] [qr/o/, qr/a/]
220 ["foo", "bar"] [qr/o/, qr/a/]
221 ! ["foo", "bar"] [qr/o/, "foo"]
228 [qw(foo bar baz quux)] qr/x/
229 ! [qw(foo bar baz quux)] qr/y/
238 ! [qw(1foo 2bar)] "2"
239 [qw(1foo 2bar)] "2bar"
241 # Number against number
247 # Number against string
254 # Regex against string
258 # Regex against number
262 # Test the implicit referencing
276 %tied_hash %tied_hash
277 %hash { foo => 5, bar => 10 }
278 ! %hash { foo => 5, bar => 10, quux => 15 }
280 @nums { 1, '', 2, '' }
281 @nums { 1, '', 12, '' }
282 ! @nums { 11, '', 12, '' }