1#!./perl 2 3print "1..44\n"; 4 5# test the optimization of constants 6 7if (1) { print "ok 1\n";} else { print "not ok 1\n";} 8unless (0) { print "ok 2\n";} else { print "not ok 2\n";} 9 10if (0) { print "not ok 3\n";} else { print "ok 3\n";} 11unless (1) { print "not ok 4\n";} else { print "ok 4\n";} 12 13unless (!1) { print "ok 5\n";} else { print "not ok 5\n";} 14if (!0) { print "ok 6\n";} else { print "not ok 6\n";} 15 16unless (!0) { print "not ok 7\n";} else { print "ok 7\n";} 17if (!1) { print "not ok 8\n";} else { print "ok 8\n";} 18 19$x = 1; 20if (1 && $x) { print "ok 9\n";} else { print "not ok 9\n";} 21if (0 && $x) { print "not ok 10\n";} else { print "ok 10\n";} 22$x = ''; 23if (1 && $x) { print "not ok 11\n";} else { print "ok 11\n";} 24if (0 && $x) { print "not ok 12\n";} else { print "ok 12\n";} 25 26$x = 1; 27if (1 || $x) { print "ok 13\n";} else { print "not ok 13\n";} 28if (0 || $x) { print "ok 14\n";} else { print "not ok 14\n";} 29$x = ''; 30if (1 || $x) { print "ok 15\n";} else { print "not ok 15\n";} 31if (0 || $x) { print "not ok 16\n";} else { print "ok 16\n";} 32 33 34# test the optimization of variables 35 36$x = 1; 37if ($x) { print "ok 17\n";} else { print "not ok 17\n";} 38unless ($x) { print "not ok 18\n";} else { print "ok 18\n";} 39 40$x = ''; 41if ($x) { print "not ok 19\n";} else { print "ok 19\n";} 42unless ($x) { print "ok 20\n";} else { print "not ok 20\n";} 43 44# test optimization of string operations 45 46$a = 'a'; 47if ($a eq 'a') { print "ok 21\n";} else { print "not ok 21\n";} 48if ($a ne 'a') { print "not ok 22\n";} else { print "ok 22\n";} 49 50if ($a =~ /a/) { print "ok 23\n";} else { print "not ok 23\n";} 51if ($a !~ /a/) { print "not ok 24\n";} else { print "ok 24\n";} 52# test interaction of logicals and other operations 53 54$a = 'a'; 55$x = 1; 56if ($a eq 'a' and $x) { print "ok 25\n";} else { print "not ok 25\n";} 57if ($a ne 'a' and $x) { print "not ok 26\n";} else { print "ok 26\n";} 58$x = ''; 59if ($a eq 'a' and $x) { print "not ok 27\n";} else { print "ok 27\n";} 60if ($a ne 'a' and $x) { print "not ok 28\n";} else { print "ok 28\n";} 61 62$x = 1; 63if ($a eq 'a' or $x) { print "ok 29\n";} else { print "not ok 29\n";} 64if ($a ne 'a' or $x) { print "ok 30\n";} else { print "not ok 30\n";} 65$x = ''; 66if ($a eq 'a' or $x) { print "ok 31\n";} else { print "not ok 31\n";} 67if ($a ne 'a' or $x) { print "not ok 32\n";} else { print "ok 32\n";} 68 69$x = 1; 70if ($a =~ /a/ && $x) { print "ok 33\n";} else { print "not ok 33\n";} 71if ($a !~ /a/ && $x) { print "not ok 34\n";} else { print "ok 34\n";} 72$x = ''; 73if ($a =~ /a/ && $x) { print "not ok 35\n";} else { print "ok 35\n";} 74if ($a !~ /a/ && $x) { print "not ok 36\n";} else { print "ok 36\n";} 75 76$x = 1; 77if ($a =~ /a/ || $x) { print "ok 37\n";} else { print "not ok 37\n";} 78if ($a !~ /a/ || $x) { print "ok 38\n";} else { print "not ok 38\n";} 79$x = ''; 80if ($a =~ /a/ || $x) { print "ok 39\n";} else { print "not ok 39\n";} 81if ($a !~ /a/ || $x) { print "not ok 40\n";} else { print "ok 40\n";} 82 83$x = 1; 84if ($a eq 'a' xor $x) { print "not ok 41\n";} else { print "ok 41\n";} 85if ($a ne 'a' xor $x) { print "ok 42\n";} else { print "not ok 42\n";} 86$x = ''; 87if ($a eq 'a' xor $x) { print "ok 43\n";} else { print "not ok 43\n";} 88if ($a ne 'a' xor $x) { print "not ok 44\n";} else { print "ok 44\n";} 89