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/;
53 match_test($yn, $left, $right);
54 match_test($yn, $right, $left);
58 my ($yn, $left, $right) = @_;
60 die "Bad test spec: ($yn, $left, $right)"
61 unless $yn eq "" || $yn eq "!" || $yn eq '@';
63 my $tstr = "$left ~~ $right";
70 ok( $@ ne '', "$tstr dies" )
71 and print "# \$\@ was: $@\n";
73 my $test_name = $tstr . ($yn eq '!' ? " does not match" : " matches");
76 print "# \$\@ was: $@\n";
78 ok( ($yn eq '!' xor $res), $test_name );
88 sub fatal {die "fatal sub\n"}
90 sub a_const() {die "const\n" if @_; "a constant"}
91 sub b_const() {die "const\n" if @_; "a constant"}
98 # ! - expected to not match
99 # @ - expected to be a compilation failure
100 # Data types to test :
110 # Regex (// and qr//)
120 $ov_obj {"key" => 1, bar => 2} TODO
121 ! $ov_obj {"foo" => 1}
123 ! $ov_obj ["foo" => 1]
126 $ov_obj %keyandmore TODO
132 $ov_obj sub { shift ~~ "key" }
133 ! $ov_obj sub { shift eq "key" }
134 ! $ov_obj sub { shift ~~ "foo" }
158 # CODE ref against argument
162 ! \&foo sub { "$_[0]" =~ /^CODE/ }
167 # - arg is not code ref
187 # pass argument by reference
188 @fooormore sub{scalar @_ == 1}
189 @fooormore sub{"@_" =~ /ARRAY/}
190 %fooormore sub{"@_" =~ /HASH/}
191 /fooormore/ sub{ref $_[0] eq 'Regexp'}
193 # - null-prototyped subs
198 ! \&a_const \&b_const
214 # - non-null-prototyped subs
226 \%main:: {map {$_ => 'x'} keys %main::}
230 \%tied_hash \%tied_hash
237 { foo => 1 } ["foo", "bar"]
238 \%hash ["foo", "bar"]
241 \%hash [qw(foo quux)]
244 {foo => 1} qr/^(fo[ox])$/
245 ! +{0..99} qr/[13579]$/
248 +{foo => 1, bar => 2} "foo"
249 ! +{foo => 1, bar => 2} "baz"
253 # - another array ref
256 [["foo"], ["bar"]] [qr/o/, qr/a/]
257 ["foo", "bar"] [qr/o/, qr/a/]
258 ! ["foo", "bar"] [qr/o/, "foo"]
265 [qw(foo bar baz quux)] qr/x/
266 ! [qw(foo bar baz quux)] qr/y/
275 ! [qw(1foo 2bar)] "2"
276 [qw(1foo 2bar)] "2bar"
278 # Number against number
284 # Number against string
291 # Regex against string
295 # Regex against number
299 # Test the implicit referencing
314 %tied_hash %tied_hash
315 %hash { foo => 5, bar => 10 }
316 ! %hash { foo => 5, bar => 10, quux => 15 }
318 @nums { 1, '', 2, '' }
319 @nums { 1, '', 12, '' }
320 ! @nums { 11, '', 12, '' }