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";
51 $res = eval $tstr // ""; #/ <- fix syntax colouring
54 ok( ($yn =~ /!/ xor $res), "$tstr: $res");
63 sub a_const() {die if @_; "a constant"}
64 sub b_const() {die if @_; "a constant"}
67 # CODE ref against argument
73 # - arg is not code ref
81 # - null-prototyped subs
93 \%main:: {map {$_ => 'x'} keys %main::}
97 \%tied_hash \%tied_hash
104 { foo => 1 } ["foo", "bar"]
105 \%hash ["foo", "bar"]
108 \%hash [qw(foo quux)]
111 {foo => 1} qr/^(fo[ox])$/
112 ! +{0..100} qr/[13579]$/
115 +{foo => 1, bar => 2} "foo"
116 ! +{foo => 1, bar => 2} "baz"
120 # - another array ref
123 [["foo"], ["bar"]] [qr/o/, qr/a/]
124 ["foo", "bar"] [qr/o/, qr/a/]
125 ! ["foo", "bar"] [qr/o/, "foo"]
132 [qw(foo bar baz quux)] qr/x/
133 ! [qw(foo bar baz quux)] qr/y/
139 ! [qw(1foo 2bar)] "2"
141 # Number against number
145 # Number against string
151 # Regex against string
155 # Regex against number
159 # Test the implicit referencing
173 %tied_hash %tied_hash
174 %hash { foo => 5, bar => 10 }
175 ! %hash { foo => 5, bar => 10, quux => 15 }
177 @nums { 1, '', 2, '' }
178 @nums { 1, '', 12, '' }
179 ! @nums { 11, '', 12, '' }