3 # $RCSfile: cond.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:41 $
7 print 1 ? "ok 1\n" : "not ok 1\n"; # compile time
8 print 0 ? "not ok 2\n" : "ok 2\n";
11 print $x ? "ok 3\n" : "not ok 3\n"; # run time
12 print !$x ? "not ok 4\n" : "ok 4\n";
14 # Very low precedence between the ? and the :
15 print $x ? "ok 5\n" or "not ok 5\n" : "not ok 5\n";
16 # Binds tighter than assignment
17 $msg = "not ok 6\n" ? "ok 6\n" : "ok 6\n";
19 # Binds looser than ".."
20 print "ok ", $x ? 7 : -2..15, "\n";
22 print $x ? "ok 8\n" : 0 ? "not ok 8\n" : "not ok 8\n";
23 # No parens needed when nested like an if-elsif-elsif-elsif-else
25 print $n == 7 ? "not ok 9\n" :
26 $n == 8 ? "not ok 9\n" :
28 $n == 10 ? "not ok 9\n" :
30 # Nor when used like a deeply nested if-else chain
44 # A random pathologically nested example, which parses like
45 # $a ? ($b ? ($c ? $d : ($e ? $f : $g)) : $h) : ($i ? $j : $k),
68 # We exercise all the branches. The ".5"s should be dont-cares.
69 ($d, $f, $g, $h, $j, $k) =
70 ("ok 11\n", "ok 12\n", "ok 13\n", "ok 14\n", "ok 15\n", "ok 16\n");
71 ($a, $b, $c, $e, $i) = (1, 1, 1, .5, .5);
72 print $a ? $ b ? $c ? $d : $e ? $f : $g : $h : $i ? $j : $k;
73 ($a, $b, $c, $e, $i) = (1, 1, 0, 1, .5);
74 print $a ? $ b ? $c ? $d : $e ? $f : $g : $h : $i ? $j : $k;
75 ($a, $b, $c, $e, $i) = (1, 1, 0, 0, .5);
76 print $a ? $ b ? $c ? $d : $e ? $f : $g : $h : $i ? $j : $k;
77 ($a, $b, $c, $e, $i) = (1, 0, .5, .5, .5);
78 print $a ? $ b ? $c ? $d : $e ? $f : $g : $h : $i ? $j : $k;
79 ($a, $b, $c, $e, $i) = (0, .5, .5, .5, 1);
80 print $a ? $ b ? $c ? $d : $e ? $f : $g : $h : $i ? $j : $k;
81 ($a, $b, $c, $e, $i) = (0, .5, .5, .5, 0);
82 print $a ? $ b ? $c ? $d : $e ? $f : $g : $h : $i ? $j : $k;