13 # The feature mechanism is tested in t/lib/feature/smartmatch:
14 # This file tests the semantics of the operator, without worrying
15 # about feature issues such as scoping etc.
17 # Predeclare vars used in the tests:
18 my $deep1 = []; push @$deep1, \$deep1;
19 my $deep2 = []; push @$deep2, \$deep2;
21 {my $const = "a constant"; sub a_const () {$const}}
24 tie my @tied_nums, 'Tie::StdArray';
27 my %hash = (foo => 17, bar => 23);
28 tie my %tied_hash, 'Tie::StdHash';
31 # Load and run the tests
32 my @tests = map [chomp and split /\t+/, $_, 3], grep !/^#/ && /\S/, <DATA>;
33 plan tests => 2 * @tests;
35 for my $test (@tests) {
36 my ($yn, $left, $right) = @$test;
38 match_test($yn, $left, $right);
39 match_test($yn, $right, $left);
43 my ($yn, $left, $right) = @_;
45 die "Bad test spec: ($yn, $left, $right)"
46 unless $yn eq "" || $yn eq "!";
48 my $tstr = "$left ~~ $right";
53 $res = eval $tstr // ""; #/ <- fix syntax colouring
57 ok( ($yn =~ /!/ xor $res), "$tstr: $res");
66 sub a_const() {die if @_; "a constant"}
67 sub b_const() {die if @_; "a constant"}
70 # CODE ref against argument
76 # - arg is not code ref
84 # - null-prototyped subs
96 \%main:: {map {$_ => 'x'} keys %main::}
100 \%tied_hash \%tied_hash
108 {foo => 1} qr/^(fo[ox])$/
109 ! +{0..100} qr/[13579]$/
112 +{foo => 1, bar => 2} "foo"
113 ! +{foo => 1, bar => 2} "baz"
117 # - another array ref
120 [["foo"], ["bar"]] [qr/o/, qr/a/]
121 ["foo", "bar"] [qr/o/, qr/a/]
128 [qw(foo bar baz quux)] qr/x/
129 ! [qw(foo bar baz quux)] qr/y/
135 ! [qw(1foo 2bar)] "2"
137 # Number against number
141 # Number against string
147 # Regex against string
151 # Regex against number
155 # Test the implicit referencing