10 no warnings qw(experimental::smartmatch experimental::isa);
12 my @cheqop = qw(== != eq ne);
13 my @nceqop = qw(<=> cmp ~~);
14 my @chrelop = qw(< > <= >= lt gt le ge);
15 my @ncrelop = qw(isa);
17 plan tests => @nceqop*@nceqop + 2*@cheqop*@nceqop + 2*@cheqop*@cheqop*@nceqop +
18 @ncrelop*@ncrelop + 2*@chrelop*@ncrelop + 2*@chrelop*@chrelop*@ncrelop +
20 @cheqop*@cheqop + @chrelop*@chrelop +
21 @cheqop*@cheqop*@cheqop + @chrelop*@chrelop*@chrelop +
24 foreach my $c0 (@nceqop) {
25 foreach my $c1 (@nceqop) {
26 is eval("sub { \$a $c0 \$b $c1 \$c }"), undef,
27 "$c0 $c1 non-associative";
30 foreach my $c (@nceqop) {
31 foreach my $e (@cheqop) {
32 is eval("sub { \$a $c \$b $e \$c }"), undef, "$c $e non-associative";
33 is eval("sub { \$a $e \$b $c \$c }"), undef, "$e $c non-associative";
36 foreach my $c (@nceqop) {
37 foreach my $e0 (@cheqop) {
38 foreach my $e1 (@cheqop) {
39 is eval("sub { \$a $c \$b $e0 \$c $e1 \$d }"), undef,
40 "$c $e0 $e1 non-associative";
41 is eval("sub { \$a $e0 \$b $e1 \$c $c \$d }"), undef,
42 "$e0 $e1 $c non-associative";
47 foreach my $c0 (@ncrelop) {
48 foreach my $c1 (@ncrelop) {
49 is eval("sub { \$a $c0 \$b $c1 \$c }"), undef,
50 "$c0 $c1 non-associative";
53 foreach my $c (@ncrelop) {
54 foreach my $e (@chrelop) {
55 is eval("sub { \$a $c \$b $e \$c }"), undef, "$c $e non-associative";
56 is eval("sub { \$a $e \$b $c \$c }"), undef, "$e $c non-associative";
59 foreach my $c (@ncrelop) {
60 foreach my $e0 (@chrelop) {
61 foreach my $e1 (@chrelop) {
62 is eval("sub { \$a $c \$b $e0 \$c $e1 \$d }"), undef,
63 "$c $e0 $e1 non-associative";
64 is eval("sub { \$a $e0 \$b $e1 \$c $c \$d }"), undef,
65 "$e0 $e1 $c non-associative";
70 foreach my $e0 (@cheqop) {
71 foreach my $e1 (@cheqop) {
72 isnt eval("sub { \$a $e0 \$b $e1 \$c }"), undef, "$e0 $e1 legal";
75 foreach my $r0 (@chrelop) {
76 foreach my $r1 (@chrelop) {
77 isnt eval("sub { \$a $r0 \$b $r1 \$c }"), undef, "$r0 $r1 legal";
80 foreach my $e0 (@cheqop) {
81 foreach my $e1 (@cheqop) {
82 foreach my $e2 (@cheqop) {
83 isnt eval("sub { \$a $e0 \$b $e1 \$c $e2 \$d }"), undef,
88 foreach my $r0 (@chrelop) {
89 foreach my $r1 (@chrelop) {
90 foreach my $r2 (@chrelop) {
91 isnt eval("sub { \$a $r0 \$b $r1 \$c $r2 \$d }"), undef,
98 [5,3,2], [5,3,3], [5,3,4], [5,3,5], [5,3,6],
99 [5,5,4], [5,5,5], [5,5,6],
100 [5,7,4], [5,7,5], [5,7,6], [5,7,7], [5,7,8],
102 is join(",", "x", $_->[0] == $_->[1] != $_->[2], "y"),
103 join(",", "x", !!($_->[0] == $_->[1] && $_->[1] != $_->[2]), "y"),
104 "$_->[0] == $_->[1] != $_->[2]";
105 is join(",", "x", $_->[0] != $_->[1] == $_->[2], "y"),
106 join(",", "x", !!($_->[0] != $_->[1] && $_->[1] == $_->[2]), "y"),
107 "$_->[0] != $_->[1] == $_->[2]";
108 is join(",", "x", $_->[0] < $_->[1] <= $_->[2], "y"),
109 join(",", "x", !!($_->[0] < $_->[1] && $_->[1] <= $_->[2]), "y"),
110 "$_->[0] < $_->[1] <= $_->[2]";
111 is join(",", "x", $_->[0] > $_->[1] >= $_->[2], "y"),
112 join(",", "x", !!($_->[0] > $_->[1] && $_->[1] >= $_->[2]), "y"),
113 "$_->[0] > $_->[1] >= $_->[2]";
114 is join(",", "x", $_->[0] < $_->[1] > $_->[2], "y"),
115 join(",", "x", !!($_->[0] < $_->[1] && $_->[1] > $_->[2]), "y"),
116 "$_->[0] < $_->[1] > $_->[2]";
119 ($e .= "a", $_->[0]) == ($e .= "b", $_->[1]) !=
120 ($e .= "c", $_->[2]),
122 join(",", "x", !!($_->[0] == $_->[1] && $_->[1] != $_->[2]), "y"),
123 "$_->[0] == $_->[1] != $_->[2] with side effects";
124 is $e, "ab".($_->[0] == $_->[1] ? "c" : ""), "operand evaluation order";
127 ($e .= "a", $_->[0]) < ($e .= "b", $_->[1]) <= ($e .= "c", $_->[2]),
129 join(",", "x", !!($_->[0] < $_->[1] && $_->[1] <= $_->[2]), "y"),
130 "$_->[0] < $_->[1] <= $_->[2] with side effects";
131 is $e, "ab".($_->[0] < $_->[1] ? "c" : ""), "operand evaluation order";
132 foreach my $p (1..9) {
133 is join(",", "x", $_->[0] == $_->[1] != $_->[2] == $p, "y"),
135 !!($_->[0] == $_->[1] && $_->[1] != $_->[2] && $_->[2] == $p),
137 "$_->[0] == $_->[1] != $_->[2] == $p";
138 is join(",", "x", $_->[0] < $_->[1] <= $_->[2] > $p, "y"),
140 !!($_->[0] < $_->[1] && $_->[1] <= $_->[2] && $_->[2] > $p),
142 "$_->[0] < $_->[1] <= $_->[2] > $p";
145 ($e .= "a", $_->[0]) == ($e .= "b", $_->[1]) !=
146 ($e .= "c", $_->[2]) == ($e .= "d", $p),
149 !!($_->[0] == $_->[1] && $_->[1] != $_->[2] && $_->[2] == $p),
151 "$_->[0] == $_->[1] != $_->[2] == $p with side effects";
153 "ab".($_->[0] == $_->[1] ?
154 ("c".($_->[1] != $_->[2] ? "d" : "")) : ""),
155 "operand evaluation order";
158 ($e .= "a", $_->[0]) < ($e .= "b", $_->[1]) <=
159 ($e .= "c", $_->[2]) > ($e .= "d", $p),
162 !!($_->[0] < $_->[1] && $_->[1] <= $_->[2] && $_->[2] > $p),
164 "$_->[0] < $_->[1] <= $_->[2] > $p with side effects";
166 "ab".($_->[0] < $_->[1] ?
167 ("c".($_->[1] <= $_->[2] ? "d" : "")) : ""),
168 "operand evaluation order";