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 # - arg is not code ref
182 # pass argument by reference
183 @fooormore sub{scalar @_ == 1}
184 @fooormore sub{"@_" =~ /ARRAY/}
185 %fooormore sub{"@_" =~ /HASH/}
186 /fooormore/ sub{ref $_[0] eq 'Regexp'}
188 # - null-prototyped subs
200 # - non-null-prototyped subs
211 \%main:: {map {$_ => 'x'} keys %main::}
215 \%tied_hash \%tied_hash
222 { foo => 1 } ["foo", "bar"]
223 \%hash ["foo", "bar"]
226 \%hash [qw(foo quux)]
229 {foo => 1} qr/^(fo[ox])$/
230 ! +{0..99} qr/[13579]$/
233 +{foo => 1, bar => 2} "foo"
234 ! +{foo => 1, bar => 2} "baz"
238 # - another array ref
241 [["foo"], ["bar"]] [qr/o/, qr/a/]
242 ["foo", "bar"] [qr/o/, qr/a/]
243 ! ["foo", "bar"] [qr/o/, "foo"]
250 [qw(foo bar baz quux)] qr/x/
251 ! [qw(foo bar baz quux)] qr/y/
260 ! [qw(1foo 2bar)] "2"
261 [qw(1foo 2bar)] "2bar"
263 # Number against number
269 # Number against string
276 # Regex against string
280 # Regex against number
284 # Test the implicit referencing
299 %tied_hash %tied_hash
300 %hash { foo => 5, bar => 10 }
301 ! %hash { foo => 5, bar => 10, quux => 15 }
303 @nums { 1, '', 2, '' }
304 @nums { 1, '', 12, '' }
305 ! @nums { 11, '', 12, '' }