1
1
use v6 ;
2
2
use Test ;
3
- plan 41 ;
3
+ plan 49 ;
4
4
5
5
# L<S02/Names and Variables/The empty>
6
6
@@ -10,23 +10,24 @@ plan 41;
10
10
ok (). defined , ' () is defined' ;
11
11
my @ a = 1 , Nil , 3 ;
12
12
is @ a . elems , 2 , ' Nil as part of list, is empty list' ;
13
- @ a . push : Nil ;
13
+ ok ( @ a . push : Nil ) =:= @ a , " Pushing Nil returns same array " ;
14
14
is @ a . elems , 2 , ' Pushing Nil in list context is empty list' ;
15
- @ a . unshift : Nil ;
15
+ ok ( @ a . unshift : Nil ) =:= @ a , " Unshifting Nil returns same array " ;
16
16
is @ a . elems , 2 , ' Unshifting Nil in list context is empty list' ;
17
- } # 5
17
+ is (@ a = Nil ), Nil , " Setting to Nil returns Nil" ;
18
+ is @ a . elems , 0 , ' Setting to Nil restores original state' ;
19
+ } # 7
18
20
19
21
# typed scalar
20
22
# ?pugs skip "doesn't know typed stuff"
21
23
# ?niecza skip "doesn't know typed stuff"
22
- # ?rakudo skip "not allowed to assign Nil to Int scalar"
23
24
{
24
25
my Int $ a = 1 ;
25
- is $ a . WHAT , ' (Int)' , " Check that we have an 'Int' scalar" ;
26
- ok ! defined ($ a = Nil ), " assigning Nil to Int should work" ;
26
+ # ?rakudo skip "not allowed to assign Nil to Int scalar"
27
+ is ($ a = Nil ), Nil , " assigning Nil to Int should work" ;
28
+ # ?rakudo todo "not allowed to assign Nil to Int scalar"
27
29
ok ! $ a . defined , " Nil makes undefined here" ;
28
- is $ a . WHAT , ' (Int)' , " Nil keeps Int type on scalar" ;
29
- } # 4
30
+ } # 2
30
31
31
32
# typed array
32
33
# ?pugs skip "doesn't know typed stuff"
@@ -36,15 +37,19 @@ plan 41;
36
37
# ?rakudo todo ".clone doesn't copy typedness"
37
38
is @ a . of , ' (Int)' , " Check that we have an 'Int' array" ;
38
39
is @ a . elems , 2 , ' Nil as part of Int list, is empty list' ;
39
- @ a . push : Nil ;
40
+ ok ( @ a . push : Nil ) =:= @ a , " assigning Nil returns same array " ;
40
41
is @ a . elems , 2 , ' Pushing Nil in Int list context is empty list' ;
41
- @ a . unshift : Nil ;
42
+ ok ( @ a . unshift : Nil ) =:= @ a , " assigning Nil returns same array " ;
42
43
is @ a . elems , 2 , ' Unshifting Nil in Int list context is empty list' ;
43
- # ?rakudo 3 skip "not allowed to assign Nil to Int scalar"
44
+ # ?rakudo skip "not allowed to assign Nil to Int scalar"
44
45
ok ! defined (@ a [1 ] = Nil ), " assigning Nil to Int should work" ;
46
+ # ?rakudo todo "not allowed to assign Nil to Int scalar"
45
47
ok ! @ a [1 ]. defined , " Nil makes undefined here" ;
46
- is @ a [1 ]. WHAT , ' (Int)' , " Nil keeps Int type on scalar" ;
47
- } # 7
48
+ is ( @ a = Nil ), Nil , " setting to Nil returns Nil" ;
49
+ # ?rakudo todo ".clone doesn't copy typedness"
50
+ is @ a . of , ' (Int)' , " Check that we still have an 'Int' array" ;
51
+ is @ a . elems , 0 , ' Setting to Nil restores original state' ;
52
+ } # 11
48
53
49
54
# typed hash
50
55
# ?pugs skip "doesn't know typed stuff"
@@ -54,11 +59,14 @@ plan 41;
54
59
# ?rakudo todo ".clone doesn't copy typedness"
55
60
is % a . of , ' (Int)' , " Check that we have an 'Int' hash" ;
56
61
is % a . elems , 2 , ' Nil as part of Int list, is empty pair' ;
57
- # ?rakudo 3 skip "not allowed to assign Nil to Int scalar"
58
- ok ! defined ( % a <b > = Nil ), " assigning Nil to hash element should work" ;
62
+ # ?rakudo skip "not allowed to assign Nil to Int scalar"
63
+ is ( % a <b > = Nil ), Nil , " assigning Nil to hash element should work" ;
59
64
ok ! % a <b >. defined , " Nil makes undefined here" ;
60
- is % a <b >. WHAT , ' (Int)' , " Nil keeps Int type on scalar" ;
61
- } # 5
65
+ is ( % a = Nil ), Nil , " setting to Nil returns Nil" ;
66
+ # ?rakudo todo ".clone doesn't copy typedness"
67
+ is % a . of , ' (Int)' , " Check that we still have an 'Int' hash" ;
68
+ is % a . elems , 0 , ' Setting to Nil restores original state' ;
69
+ } # 7
62
70
63
71
# sink context returns Nil
64
72
{
0 commit comments