4 # test the logical operators '&&', '||', '!', 'and', 'or', 'not'
15 for my $i (undef, 0 .. 2, "", "0 but true") {
18 for my $j (undef, 0 .. 2, "", "0 but true") {
20 ((!$i || !$j) != !($i && $j))
21 or (!($i || $j) != (!$i && !$j))
22 or (!!($i || $j) != !(!$i && !$j))
23 or (!(!$i || !$j) != !!($i && $j))
26 ((!$i || !$j) == !!($i && $j))
27 and (!!($i || $j) == (!$i && !$j))
28 and ((!$i || $j) == ($i && !$j))
29 and (($i || !$j) != (!$i && $j))
32 my $m = ! defined $i ? 'undef'
33 : $i eq '' ? 'empty string'
35 ok( $true, "true: $m");
36 ok( ! $false, "false: $m");
40 (($i ||= 1) &&= 3) += 4;
41 is( $i, 7, '||=, &&=');
45 is( $i, 8, 'negation precedence with ||' );
48 $i = !$x || !$x || !$x || $y;
49 is( $i, 9, 'negation precedence with ||, multiple operands' );
54 is( $i, 10, 'negation precedence with &&' );
57 $i = !$x && !$x && !$x && $y;
58 is( $i, 11, 'negation precedence with &&, multiple operands' );
60 # [perl #127952]. This relates to OP_AND and OP_OR with a negated constant
61 # on the lhs (either a negated bareword, or a negation of a do{} containing
62 # a constant) and a negated non-foldable expression on the rhs. These cases
63 # yielded 42 or "Bare" or "str" before the bug was fixed.
68 is( $i, '', 'neg-bareword on lhs of || with non-foldable neg-true on rhs' );
71 is( $i, '', 'neg-bareword on lhs of && with non-foldable neg-true on rhs' );
73 $i = do { !$x if !Bare };
74 is( $i, '', 'neg-bareword on rhs of modifier-if with non-foldable neg-true on lhs' );
76 $i = do { !$x unless !Bare };
77 is( $i, '', 'neg-bareword on rhs of modifier-unless with non-foldable neg-true on lhs' );
79 $i = !do { "str" } || !$x;
80 is( $i, '', 'neg-do-const on lhs of || with non-foldable neg-true on rhs' );
82 $i = !do { "str" } && !$x;
83 is( $i, '', 'neg-do-const on lhs of && with non-foldable neg-true on rhs' );