1
1
use v6 ;
2
2
use Test ;
3
3
4
- plan 58 ;
4
+ plan 61 ;
5
5
6
6
# L<S09/Typed arrays/>
7
7
@@ -20,26 +20,28 @@ plan 58;
20
20
is @ x . unshift (2 ), [2 , 2 , 3 ], ' can unshift from typed array' ;
21
21
} # 9
22
22
23
- # ?rakudo skip 'of Int'
24
23
{
25
- my @ x of Int ;
26
- ok @ x . of === Int , ' @x.of of typed array (my @x of Int )' ;
27
- lives_ok { @ x = 1 , 2 , 3 }, ' can assign values of the right type (@x of Int )' ;
28
- lives_ok { @ x = 1 .. 3 }, ' can assign range of the right type (@x of Int )' ;
29
- lives_ok { @ x . push : 3 , 4 }, ' can push values of the right type (@x of Int )' ;
30
- lives_ok { @ x . unshift : 3 }, ' can unshift values of the right type (@x of Int )' ;
31
- lives_ok { @ x [0 , 2 ] = 2 , 3 }, ' can assign values to a slice (@x of Int )' ;
24
+ my Int @ x ;
25
+ ok @ x . VAR . of === Int , ' @x.VAR. of of typed array (my Int @x )' ;
26
+ lives_ok { @ x = 1 , 2 , 3 }, ' can assign values of the right type (Int @x )' ;
27
+ lives_ok { @ x = 1 .. 3 }, ' can assign range of the right type (Int @x )' ;
28
+ lives_ok { @ x . push : 3 , 4 }, ' can push values of the right type (Int @x )' ;
29
+ lives_ok { @ x . unshift : 3 }, ' can unshift values of the right type (Int @x )' ;
30
+ lives_ok { @ x [0 , 2 ] = 2 , 3 }, ' can assign values to a slice (Int @x )' ;
32
31
@ x = 2 , 3 , 4 ;
33
- is @ x . pop , 4 , ' can pop from typed array (@x of Int )' ;
34
- is @ x . unshift (1 ), [1 , 2 , 3 ], ' can unshift from typed array (@x of Int )' ;
32
+ is @ x . pop , 4 , ' can pop from typed array (Int @x )' ;
33
+ is @ x . unshift (1 ), [1 , 2 , 3 ], ' can unshift from typed array (Int @x )' ;
35
34
} # 8
36
35
37
36
# initialization
38
- lives_ok { my @ x = 1 , 2 , 3 }, ' initialization of typed array' ;
39
- lives_ok { my @ x = 1 .. 3 }, ' initialization of typed array from range' ;
37
+ {
38
+ lives_ok { my Int @ x = 1 , 2 , 3 }, ' initialization of typed array' ;
39
+ lives_ok { my Int @ x = 1 .. 3 }, ' initialization of typed array from range' ;
40
+ } # 2
40
41
41
42
{
42
43
my @ x of Int ;
44
+ ok @ x . VAR . of === Int , ' @x.VAR.of of typed array (my @x of Int)' ;
43
45
lives_ok { @ x = 1 , 2 , 3 }, ' can assign values of the right type (@x of Int)' ;
44
46
lives_ok { @ x = 1 .. 3 }, ' can assign range of the right type (@x of Int)' ;
45
47
lives_ok { @ x . push : 3 , 4 }, ' can push values of the right type (@x of Int)' ;
@@ -49,10 +51,11 @@ lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
49
51
is @ x . pop , 4 , ' can pop from typed array (@x of Int)' ;
50
52
51
53
ok @ x . unshift , ' can unshift from typed array (@x of Int)' ;
52
- } # 7
54
+ } # 8
53
55
54
56
{
55
57
my Array @ x ;
58
+ ok @ x . VAR . of === Array , ' @x.VAR.of of typed array (my Array @x)' ;
56
59
dies_ok { @ x = 1 , 2 , 3 }, ' can not assign values of the wrong type' ;
57
60
dies_ok { @ x = 1 .. 3 }, ' can not assign range of the wrong type' ;
58
61
dies_ok { @ x . push : 3 , 4 }, ' can not push values of the wrong type' ;
@@ -61,28 +64,30 @@ lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
61
64
' can not assign values of wrong type to a slice' ;
62
65
lives_ok { @ x = [1 , 2 ], [3 , 4 ] },
63
66
' ... but assigning values of the right type is OK' ;
64
- } # 6
67
+ } # 7
65
68
66
69
{
67
70
my @ x of Array ;
71
+ ok @ x . VAR . of === Array , ' @x.VAR.of of typed array (my @x of Array)' ;
68
72
dies_ok { @ x = 1 , 2 , 3 }, ' can not assign values of the wrong type' ;
69
73
dies_ok { @ x = 1 .. 3 }, ' can not assign range of the wrong type' ;
70
- # ?rakudo 3 todo "no parametrization"
71
74
dies_ok { @ x . push : 3 , 4 }, ' can not push values of the wrong type' ;
72
75
dies_ok { @ x . unshift : 3 }, ' can not unshift values of the wrong type' ;
73
76
dies_ok { @ x [0 , 2 ] = 2 , 3 },
74
77
' can not assign values of wrong type to a slice' ;
75
78
lives_ok { @ x = [1 , 2 ], [3 , 4 ] },
76
79
' ... but assigning values of the right type is OK' ;
77
- } # 6
80
+ } # 7
78
81
79
- # ?rakudo skip 'Array not parametric'
80
82
{
81
83
my Array of Int @ x ;
82
84
ok @ x . of === Array [Int ], ' my Array of Int @x declares a nested array' ;
85
+ # ?rakudo skip "nested typechecks are borked"
83
86
lives_ok { @ x = [2 , 3 ], [5 , 6 ] }, ' assignment works' ;
87
+ # ?rakudo todo "nested typechecks are borked"
84
88
lives_ok { @ x . push : [8 , 9 ] }, ' pushing works' ;
85
89
dies_ok { @ x . push : 8 }, ' type constraint is enforced' ;
90
+ # ?rakudo todo "nested typechecks are borked"
86
91
lives_ok { @ x [0 ]. push : 3 }, ' pushing to the inner array is OK' ;
87
92
dies_ok { @ x [0 ]. push : ' foo' }, ' inner array enforces the type constraint' ;
88
93
} # 6
@@ -100,7 +105,7 @@ lives_ok { my @x = 1 .. 3 }, 'initialization of typed array from range';
100
105
# ?rakudo skip 'initialization'
101
106
{
102
107
my Str @ c = <foo bar baz >;
103
- ok @ c . keys . of . WHICH eqv Str . WHICH , ' @array.keys is typed with Int ' ;
108
+ ok @ c . keys . of . WHICH eqv Str . WHICH , ' @array.keys is typed with Str ' ;
104
109
} # 1
105
110
106
111
# test that we can have parametric array return types
0 commit comments