This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Document the last five tests of t/op/lop.t
[perl5.git] / t / op / lop.t
CommitLineData
bf4b1e52
GS
1#!./perl
2
3#
4# test the logical operators '&&', '||', '!', 'and', 'or', 'not'
5#
6
7BEGIN {
8 chdir 't' if -d 't';
20822f61 9 @INC = '../lib';
73ee8f56 10 require './test.pl';
bf4b1e52
GS
11}
12
73ee8f56 13plan tests => 17;
bf4b1e52
GS
14
15my $test = 0;
16for my $i (undef, 0 .. 2, "", "0 but true") {
17 my $true = 1;
18 my $false = 0;
19 for my $j (undef, 0 .. 2, "", "0 but true") {
20 $true &&= !(
21 ((!$i || !$j) != !($i && $j))
22 or (!($i || $j) != (!$i && !$j))
23 or (!!($i || $j) != !(!$i && !$j))
24 or (!(!$i || !$j) != !!($i && $j))
25 );
26 $false ||= (
27 ((!$i || !$j) == !!($i && $j))
28 and (!!($i || $j) == (!$i && !$j))
29 and ((!$i || $j) == ($i && !$j))
30 and (($i || !$j) != (!$i && $j))
31 );
32 }
73ee8f56
CK
33 my $m = ! defined $i ? 'undef'
34 : $i eq '' ? 'empty string'
35 : $i;
36 ok( $true, "true: $m");
37 ok( ! $false, "false: $m");
bf4b1e52
GS
38}
39
40# $test == 6
41my $i = 0;
42(($i ||= 1) &&= 3) += 4;
6f02a299 43is( $i, 7, '||=, &&=');
edbe35ea
VP
44
45my ($x, $y) = (1, 8);
46$i = !$x || $y;
6f02a299 47is( $i, 8, 'negation precedence with ||' );
edbe35ea 48
07f3cdf5
VP
49++$y;
50$i = !$x || !$x || !$x || $y;
6f02a299 51is( $i, 9, 'negation precedence with ||, multiple operands' );
07f3cdf5
VP
52
53$x = 0;
54++$y;
55$i = !$x && $y;
6f02a299 56is( $i, 10, 'negation precedence with &&' );
07f3cdf5
VP
57
58++$y;
59$i = !$x && !$x && !$x && $y;
6f02a299 60is( $i, 11, 'negation precedence with &&, multiple operands' );