Skip to content

Commit f8b1530

Browse files
committed
Add some more with/orwith/without tests
1 parent 41defae commit f8b1530

File tree

1 file changed

+64
-10
lines changed

1 file changed

+64
-10
lines changed

S04-statements/with.t

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,73 @@ use v6;
22

33
use Test;
44

5-
plan 1;
5+
plan 13;
66

7-
my $foo = 42;
8-
with 0 -> $pos {
9-
$foo = $pos;
7+
for
8+
0, 1,0
9+
, 1, 0,1
10+
,Int, 0,0
11+
# ,Int,Str,2 # enable when todo is fixed
12+
13+
-> $with, $orwith, $expected {
14+
15+
my $foo = 42;
16+
with $with {
17+
$foo = $_;
18+
}
19+
orwith $orwith {
20+
$foo = $_;
21+
}
22+
else {
23+
$foo = 2;
24+
}
25+
#?rakudo todo '$_ not yet set in with/without block'
26+
is $foo, $expected, "\$_: with on { $with // $with.^name }, orwith on { $orwith // $orwith.^name }";
27+
}
28+
29+
for
30+
0, 1,0
31+
, 1, 0,1
32+
,Int, 0,0
33+
,Int,Str,2
34+
35+
-> $with, $orwith, $expected {
36+
37+
my $foo = 42;
38+
with $with -> $pos {
39+
$foo = $pos;
40+
}
41+
orwith $orwith -> $pos {
42+
$foo = $pos;
43+
}
44+
else {
45+
$foo = 2;
46+
}
47+
is $foo, $expected, "\$pos: with on { $with // $with.^name }, orwith on { $orwith // $orwith.^name }";
1048
}
11-
orwith 1 -> $pos {
12-
$foo = $pos;
49+
50+
for
51+
0, 0
52+
, 1, 1
53+
,Int, 42
54+
55+
-> $with, $expected {
56+
57+
my $foo = 42;
58+
$foo = $_ with $with;
59+
is $foo, $expected, "postfix with on { $with // $with.^name }";
1360
}
14-
else {
15-
$foo = "bar";
61+
62+
for
63+
0, 42
64+
, 1, 42
65+
,Int,Int
66+
67+
-> $without, $expected {
68+
69+
my $foo = 42;
70+
$foo = $_ without $without;
71+
is $foo, $expected, "postfix without on { $without // $without.^name }";
1672
}
17-
#?rakudo todo 'with semantics not yet fully implemented'
18-
is $foo, 0, 'with on a false defined value triggers';
1973

2074
# vim: ft=perl6

0 commit comments

Comments
 (0)