Skip to content

Commit

Permalink
add a few junction tests relevant to the optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Jan 27, 2013
1 parent 645eda3 commit ef58502
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions S03-junctions/boolean-context.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,72 @@ ok (so Bool::True & Bool::False) !~~ Junction, $message2;
ok ( not Bool::True & Bool::False) == Bool::True, $message1;
ok not(Bool::True & Bool::False) !~~ Junction, $message2;


ok do if 1 | 2 | 3 == 2 { 1 } else { 0 }, "3x very simple invocation of | and & in if";
ok do if 2 & 2 & 2 == 2 { 1 } else { 0 };
ok do if 2 & 2 & 2 == 3 { 0 } else { 1 };

{
my $foo = 0;
sub infix:<|>(*@a) { $foo++; any(|@a) };
sub infix:<&>(*@a) { $foo++; all(|@a) };
ok do if 1 | 2 | 3 | 4 == 3 { 1 } else { 0 }, "4x local sub shadows | and &";
is $foo, 1;
ok do if 1 & 2 & 3 & 4 == 3 { 0 } else { 1 };
is $foo, 2;
}

{
my $count = 0;
sub side-effect() { $count++ };
ok do if side-effect() == 0 | 1 | 2 | 3 { 1 } else { 0 }, "6x side effect executed only once";
is $count, 1;
ok do if side-effect() == any(1, 2, 3) { 1 } else { 0 };
is $count, 2;
ok do if 1 | 2 | 3 | 4 == side-effect() { 1 } else { 0 };
is $count, 3;
ok do if any(1, 2, 3, 4) == side-effect() { 1 } else { 0 };
is $count, 4;
}

{
my $c = 0;
for (-4..4)X(-4..4) -> $x, $y {
if $x & $y == -1 | 0 | 1 {
$c++;
}
}
is $c, 9, "junctions on both sides of a comparison";
}

given 1 {
when 0 | 1 | 2 {
ok 1, "2x given + when";
}
when 3 | 4 | 5 {
ok 0;
}
}

{
my $ctr = 0;
while $ctr == 0 | 1 | 2 | 3 | 4 {
$ctr++;
}
is $ctr, 5, "junction and while";
}

ok do if 5 & 6 & 7 <= 10 { 1 } else { 0 }, "using <=";

ok do if 5 < 3 | 5 | 10 { 1 } else { 0 }, "using <";

ok do if 3 & 5 & 6 != 4 { 1 } else { 0 }, "using !=";

ok do if 3 & 5 & 6 <= 5 | 10 { 1 } else { 0 }, "&, <= and |";

ok do if 1 | 2 | 3 <= 3 <= 5 { 1 } else { 0 }, "4x triple-chaining works";
ok do if 1 | 2 | 3 <= 3 <= 2 { 0 } else { 1 };
ok do if 1 <= 1 & 2 & 3 & 4 <= 4 { 1 } else { 0 };
ok do if 1 <= 1 & 2 & 3 & 4 <= 3 { 0 } else { 1 };

# vim: ft=perl6

0 comments on commit ef58502

Please sign in to comment.