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] };
37 package Test::Object::OverloadCodeRef;
38 sub new { bless $_[1] }
39 use overload '~~' => sub { shift->($_[1]) };
42 our $ov_obj = Test::Object::CopyOverload->new;
43 our $obj = Test::Object::NoOverload->new;
44 our $false_obj = Test::Object::OverloadCodeRef->new(sub { 0 });
45 our $true_obj = Test::Object::OverloadCodeRef->new(sub { 1 });
48 # Load and run the tests
49 my @tests = map [chomp and split /\t+/, $_, 3], grep !/^#/ && /\S/, <DATA>;
50 plan tests => 2 * @tests;
52 for my $test (@tests) {
53 my ($yn, $left, $right) = @$test;
55 match_test($yn, $left, $right);
56 match_test($yn, $right, $left);
60 my ($yn, $left, $right) = @_;
62 die "Bad test spec: ($yn, $left, $right)"
63 unless $yn eq "" || $yn eq "!" || $yn eq '@';
65 my $tstr = "$left ~~ $right";
68 $res = eval $tstr // ""; #/ <- fix syntax colouring
73 ok( $@ ne '', sprintf "%s%s: %s", $tstr, $@ ? ( ', $@', $@ ) : ( '', $res ) );
76 fail("$tstr, \$\@: $@");
78 ok( ($yn eq '!' xor $res), "$tstr: $res");
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"}
95 # ! - expected to not match
96 # @ - expected to be a compilation failure
116 # CODE ref against argument
124 # - arg is not code ref
146 # - null-prototyped subs
151 ! \&a_const \&b_const
153 # - non-null-prototyped subs
165 \%main:: {map {$_ => 'x'} keys %main::}
169 \%tied_hash \%tied_hash
176 { foo => 1 } ["foo", "bar"]
177 \%hash ["foo", "bar"]
180 \%hash [qw(foo quux)]
183 {foo => 1} qr/^(fo[ox])$/
184 ! +{0..100} qr/[13579]$/
187 +{foo => 1, bar => 2} "foo"
188 ! +{foo => 1, bar => 2} "baz"
192 # - another array ref
195 [["foo"], ["bar"]] [qr/o/, qr/a/]
196 ["foo", "bar"] [qr/o/, qr/a/]
197 ! ["foo", "bar"] [qr/o/, "foo"]
204 [qw(foo bar baz quux)] qr/x/
205 ! [qw(foo bar baz quux)] qr/y/
214 ! [qw(1foo 2bar)] "2"
215 [qw(1foo 2bar)] "2bar"
217 # Number against number
221 # Number against string
227 # Regex against string
231 # Regex against number
235 # Test the implicit referencing
249 %tied_hash %tied_hash
250 %hash { foo => 5, bar => 10 }
251 ! %hash { foo => 5, bar => 10, quux => 15 }
253 @nums { 1, '', 2, '' }
254 @nums { 1, '', 12, '' }
255 ! @nums { 11, '', 12, '' }