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
40 my @tests = map [chomp and split /\t+/, $_, 3], grep !/^#/ && /\S/, <DATA>;
41 plan tests => 2 * @tests;
43 for my $test (@tests) {
44 my ($yn, $left, $right) = @$test;
46 match_test($yn, $left, $right);
47 match_test($yn, $right, $left);
51 my ($yn, $left, $right) = @_;
53 die "Bad test spec: ($yn, $left, $right)"
54 unless $yn eq "" || $yn eq "!" || $yn eq '@';
56 my $tstr = "$left ~~ $right";
59 $res = eval $tstr // ""; #/ <- fix syntax colouring
64 ok( $@ ne '', sprintf "%s%s: %s", $tstr, $@ ? ( ', $@', $@ ) : ( '', $res ) );
67 fail("$tstr, \$\@: $@");
69 ok( ($yn eq '!' xor $res), "$tstr: $res");
79 sub fatal {die "fatal sub\n"}
81 sub a_const() {die "const\n" if @_; "a constant"}
82 sub b_const() {die "const\n" if @_; "a constant"}
89 # ! - expected to not match
90 # @ - expected to be a compilation failure
97 $ov_obj sub { shift ~~ "key" }
98 ! $ov_obj sub { shift ~~ "foo" }
117 # CODE ref against argument
121 ! \&foo sub { "$_[0]" =~ /^CODE/ }
126 # - arg is not code ref
149 # - null-prototyped subs
154 ! \&a_const \&b_const
170 # - non-null-prototyped subs
182 \%main:: {map {$_ => 'x'} keys %main::}
186 \%tied_hash \%tied_hash
193 { foo => 1 } ["foo", "bar"]
194 \%hash ["foo", "bar"]
197 \%hash [qw(foo quux)]
200 {foo => 1} qr/^(fo[ox])$/
201 ! +{0..100} qr/[13579]$/
204 +{foo => 1, bar => 2} "foo"
205 ! +{foo => 1, bar => 2} "baz"
209 # - another array ref
212 [["foo"], ["bar"]] [qr/o/, qr/a/]
213 ["foo", "bar"] [qr/o/, qr/a/]
214 ! ["foo", "bar"] [qr/o/, "foo"]
221 [qw(foo bar baz quux)] qr/x/
222 ! [qw(foo bar baz quux)] qr/y/
231 ! [qw(1foo 2bar)] "2"
232 [qw(1foo 2bar)] "2bar"
234 # Number against number
240 # Number against string
247 # Regex against string
251 # Regex against number
255 # Test the implicit referencing
269 %tied_hash %tied_hash
270 %hash { foo => 5, bar => 10 }
271 ! %hash { foo => 5, bar => 10, quux => 15 }
273 @nums { 1, '', 2, '' }
274 @nums { 1, '', 12, '' }
275 ! @nums { 11, '', 12, '' }