10 no warnings qw(experimental::smartmatch);
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 foreach my $c0 (@nceqop) {
18 foreach my $c1 (@nceqop) {
19 is eval("sub { \$a $c0 \$b $c1 \$c }"), undef,
20 "$c0 $c1 non-associative";
23 foreach my $c (@nceqop) {
24 foreach my $e (@cheqop) {
25 is eval("sub { \$a $c \$b $e \$c }"), undef, "$c $e non-associative";
26 is eval("sub { \$a $e \$b $c \$c }"), undef, "$e $c non-associative";
29 foreach my $c (@nceqop) {
30 foreach my $e0 (@cheqop) {
31 foreach my $e1 (@cheqop) {
32 is eval("sub { \$a $c \$b $e0 \$c $e1 \$d }"), undef,
33 "$c $e0 $e1 non-associative";
34 is eval("sub { \$a $e0 \$b $e1 \$c $c \$d }"), undef,
35 "$e0 $e1 $c non-associative";
40 foreach my $c0 (@ncrelop) {
41 foreach my $c1 (@ncrelop) {
42 is eval("sub { \$a $c0 \$b $c1 \$c }"), undef,
43 "$c0 $c1 non-associative";
46 foreach my $c (@ncrelop) {
47 foreach my $e (@chrelop) {
48 is eval("sub { \$a $c \$b $e \$c }"), undef, "$c $e non-associative";
49 is eval("sub { \$a $e \$b $c \$c }"), undef, "$e $c non-associative";
52 foreach my $c (@ncrelop) {
53 foreach my $e0 (@chrelop) {
54 foreach my $e1 (@chrelop) {
55 is eval("sub { \$a $c \$b $e0 \$c $e1 \$d }"), undef,
56 "$c $e0 $e1 non-associative";
57 is eval("sub { \$a $e0 \$b $e1 \$c $c \$d }"), undef,
58 "$e0 $e1 $c non-associative";
63 foreach my $e0 (@cheqop) {
64 foreach my $e1 (@cheqop) {
65 isnt eval("sub { \$a $e0 \$b $e1 \$c }"), undef, "$e0 $e1 legal";
68 foreach my $r0 (@chrelop) {
69 foreach my $r1 (@chrelop) {
70 isnt eval("sub { \$a $r0 \$b $r1 \$c }"), undef, "$r0 $r1 legal";
73 foreach my $e0 (@cheqop) {
74 foreach my $e1 (@cheqop) {
75 foreach my $e2 (@cheqop) {
76 isnt eval("sub { \$a $e0 \$b $e1 \$c $e2 \$d }"), undef,
81 foreach my $r0 (@chrelop) {
82 foreach my $r1 (@chrelop) {
83 foreach my $r2 (@chrelop) {
84 isnt eval("sub { \$a $r0 \$b $r1 \$c $r2 \$d }"), undef,
91 [5,3,2], [5,3,3], [5,3,4], [5,3,5], [5,3,6],
92 [5,5,4], [5,5,5], [5,5,6],
93 [5,7,4], [5,7,5], [5,7,6], [5,7,7], [5,7,8],
95 is join(",", "x", $_->[0] == $_->[1] != $_->[2], "y"),
96 join(",", "x", !!($_->[0] == $_->[1] && $_->[1] != $_->[2]), "y"),
97 "$_->[0] == $_->[1] != $_->[2]";
98 is join(",", "x", $_->[0] != $_->[1] == $_->[2], "y"),
99 join(",", "x", !!($_->[0] != $_->[1] && $_->[1] == $_->[2]), "y"),
100 "$_->[0] != $_->[1] == $_->[2]";
101 is join(",", "x", $_->[0] < $_->[1] <= $_->[2], "y"),
102 join(",", "x", !!($_->[0] < $_->[1] && $_->[1] <= $_->[2]), "y"),
103 "$_->[0] < $_->[1] <= $_->[2]";
104 is join(",", "x", $_->[0] > $_->[1] >= $_->[2], "y"),
105 join(",", "x", !!($_->[0] > $_->[1] && $_->[1] >= $_->[2]), "y"),
106 "$_->[0] > $_->[1] >= $_->[2]";
107 is join(",", "x", $_->[0] < $_->[1] > $_->[2], "y"),
108 join(",", "x", !!($_->[0] < $_->[1] && $_->[1] > $_->[2]), "y"),
109 "$_->[0] < $_->[1] > $_->[2]";
112 ($e .= "a", $_->[0]) == ($e .= "b", $_->[1]) !=
113 ($e .= "c", $_->[2]),
115 join(",", "x", !!($_->[0] == $_->[1] && $_->[1] != $_->[2]), "y"),
116 "$_->[0] == $_->[1] != $_->[2] with side effects";
117 is $e, "ab".($_->[0] == $_->[1] ? "c" : ""), "operand evaluation order";
120 ($e .= "a", $_->[0]) < ($e .= "b", $_->[1]) <= ($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";
125 foreach my $p (1..9) {
126 is join(",", "x", $_->[0] == $_->[1] != $_->[2] == $p, "y"),
128 !!($_->[0] == $_->[1] && $_->[1] != $_->[2] && $_->[2] == $p),
130 "$_->[0] == $_->[1] != $_->[2] == $p";
131 is join(",", "x", $_->[0] < $_->[1] <= $_->[2] > $p, "y"),
133 !!($_->[0] < $_->[1] && $_->[1] <= $_->[2] && $_->[2] > $p),
135 "$_->[0] < $_->[1] <= $_->[2] > $p";
138 ($e .= "a", $_->[0]) == ($e .= "b", $_->[1]) !=
139 ($e .= "c", $_->[2]) == ($e .= "d", $p),
142 !!($_->[0] == $_->[1] && $_->[1] != $_->[2] && $_->[2] == $p),
144 "$_->[0] == $_->[1] != $_->[2] == $p with side effects";
146 "ab".($_->[0] == $_->[1] ?
147 ("c".($_->[1] != $_->[2] ? "d" : "")) : ""),
148 "operand evaluation order";
151 ($e .= "a", $_->[0]) < ($e .= "b", $_->[1]) <=
152 ($e .= "c", $_->[2]) > ($e .= "d", $p),
155 !!($_->[0] < $_->[1] && $_->[1] <= $_->[2] && $_->[2] > $p),
157 "$_->[0] < $_->[1] <= $_->[2] > $p with side effects";
159 "ab".($_->[0] < $_->[1] ?
160 ("c".($_->[1] <= $_->[2] ? "d" : "")) : ""),
161 "operand evaluation order";
165 # https://github.com/Perl/perl5/issues/18380
166 fresh_perl_is(<<'CODE', "", {}, "stack underflow");
167 no warnings "uninitialized";