Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add some more with/orwith/without tests
  • Loading branch information
lizmat committed Aug 8, 2015
1 parent 41defae commit f8b1530
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions S04-statements/with.t
Expand Up @@ -2,19 +2,73 @@ use v6;

use Test;

plan 1;
plan 13;

my $foo = 42;
with 0 -> $pos {
$foo = $pos;
for
0, 1,0
, 1, 0,1
,Int, 0,0
# ,Int,Str,2 # enable when todo is fixed

-> $with, $orwith, $expected {

my $foo = 42;
with $with {
$foo = $_;
}
orwith $orwith {
$foo = $_;
}
else {
$foo = 2;
}
#?rakudo todo '$_ not yet set in with/without block'
is $foo, $expected, "\$_: with on { $with // $with.^name }, orwith on { $orwith // $orwith.^name }";
}

for
0, 1,0
, 1, 0,1
,Int, 0,0
,Int,Str,2

-> $with, $orwith, $expected {

my $foo = 42;
with $with -> $pos {
$foo = $pos;
}
orwith $orwith -> $pos {
$foo = $pos;
}
else {
$foo = 2;
}
is $foo, $expected, "\$pos: with on { $with // $with.^name }, orwith on { $orwith // $orwith.^name }";
}
orwith 1 -> $pos {
$foo = $pos;

for
0, 0
, 1, 1
,Int, 42

-> $with, $expected {

my $foo = 42;
$foo = $_ with $with;
is $foo, $expected, "postfix with on { $with // $with.^name }";
}
else {
$foo = "bar";

for
0, 42
, 1, 42
,Int,Int

-> $without, $expected {

my $foo = 42;
$foo = $_ without $without;
is $foo, $expected, "postfix without on { $without // $without.^name }";
}
#?rakudo todo 'with semantics not yet fully implemented'
is $foo, 0, 'with on a false defined value triggers';

# vim: ft=perl6

0 comments on commit f8b1530

Please sign in to comment.