|
1 | 1 | use v6;
|
2 | 2 | use Test;
|
3 | 3 |
|
4 |
| -plan 118; |
| 4 | +plan 107; |
5 | 5 |
|
6 | 6 | # L<S02/Variables Containing Undefined Values>
|
7 | 7 |
|
@@ -70,18 +70,7 @@ plan 118;
|
70 | 70 | my Int $b is default(42) = 768;
|
71 | 71 | is $b, 768, "typed variable should be initialized";
|
72 | 72 | is $b.VAR.default, 42, 'is the default set correctly for Int $b';
|
73 |
| - |
74 |
| - my Int $c is default(Nil); |
75 |
| - ok $c.VAR.default === Nil, 'is the default set correctly for Int $c'; |
76 |
| - lives-ok { $c++ }, 'should be able to increment typed variable'; |
77 |
| - is $c, 1, "typed variable should be incremented"; |
78 |
| - lives-ok { $c = Nil }, "should be able to assign Nil to typed variable"; |
79 |
| - ok $c === Nil, 'is the default value correctly reset for Int $c'; |
80 |
| - |
81 |
| - my Int $d is default(Nil) = 353; |
82 |
| - is $d, 353, "typed variable should be initialized"; |
83 |
| - ok $d.VAR.default === Nil, 'is the default set correctly for Int $d'; |
84 |
| -} #19 |
| 73 | +} #11 |
85 | 74 |
|
86 | 75 | #?niecza skip "is default NYI"
|
87 | 76 | # not specifically typed
|
@@ -132,18 +121,7 @@ plan 118;
|
132 | 121 | my Int @b is default(42) = 768;
|
133 | 122 | is @b[0], 768, "typed array element should be initialized";
|
134 | 123 | is @b.VAR.default, 42, 'is the default set correctly for Int @b';
|
135 |
| - |
136 |
| - my Int @c is default(Nil); |
137 |
| - ok @c.VAR.default === Nil, 'is the default set correctly for Int @c'; |
138 |
| - lives-ok { @c[0]++ }, 'should be able to increment typed variable'; |
139 |
| - is @c[0], 1, "typed variable should be incremented"; |
140 |
| - lives-ok { @c[0] = Nil }, "able to assign Nil to typed variable"; |
141 |
| - ok @c[0] === Nil, 'is the default value correctly reset for Int @c[0]'; |
142 |
| - |
143 |
| - my Int @d is default(Nil) = 353; |
144 |
| - is @d[0], 353, "typed variable should be initialized"; |
145 |
| - ok @d.VAR.default === Nil, 'is the default set correctly for Int @d'; |
146 |
| -} #19 |
| 124 | +} #12 |
147 | 125 |
|
148 | 126 | #?niecza skip "is default NYI"
|
149 | 127 | # not specifically typed
|
@@ -194,17 +172,60 @@ plan 118;
|
194 | 172 | my Int %b is default(42) = o => 768;
|
195 | 173 | is %b<o>, 768, "typed hash element should be initialized";
|
196 | 174 | is %b.VAR.default, 42, 'is the default set correctly for Int %b';
|
| 175 | +} #12 |
197 | 176 |
|
198 |
| - my Int %c is default(Nil); |
199 |
| - ok %c.VAR.default === Nil, 'is the default set correctly for Int %c'; |
200 |
| - lives-ok { %c<o>++ }, 'should be able to increment typed variable'; |
201 |
| - is %c<o>, 1, "typed variable should be incremented"; |
202 |
| - lives-ok { %c<o> = Nil }, "able to assign Nil to typed variable"; |
203 |
| - ok %c<o> === Nil, 'is the default value correctly reset for Int %c<o>'; |
| 177 | +#?niecza skip "is default NYI" |
| 178 | +# type mismatches in setting default |
| 179 | +{ |
| 180 | + throws-like 'my Int $a is default("foo")', |
| 181 | + X::Parameter::Default::TypeCheck, |
| 182 | + expected => Int, |
| 183 | + got => 'foo'; |
| 184 | + #?rakudo todo 'Nil does not survive passing to the exception' |
| 185 | + throws-like 'my Int $a is default(Nil)', |
| 186 | + X::Parameter::Default::TypeCheck, |
| 187 | + expected => Int, |
| 188 | + got => Nil; |
| 189 | + throws-like 'my Int @a is default("foo")', |
| 190 | + X::Parameter::Default::TypeCheck, |
| 191 | + expected => Array[Int], |
| 192 | + got => 'foo'; |
| 193 | + #?rakudo todo 'Nil does not survive passing to the exception' |
| 194 | + throws-like 'my Int @a is default(Nil)', |
| 195 | + X::Parameter::Default::TypeCheck, |
| 196 | + expected => Array[Int], |
| 197 | + got => Nil; |
| 198 | + throws-like 'my Int %a is default("foo")', |
| 199 | + X::Parameter::Default::TypeCheck, |
| 200 | + expected => Hash[Int], |
| 201 | + got => 'foo'; |
| 202 | + #?rakudo todo 'Nil does not survive passing to the exception' |
| 203 | + throws-like 'my Int %a is default(Nil)', |
| 204 | + X::Parameter::Default::TypeCheck, |
| 205 | + expected => Hash[Int], |
| 206 | + got => Nil; |
| 207 | +} #6 |
204 | 208 |
|
205 |
| - my Int %d is default(Nil) = o => 353; |
206 |
| - is %d<o>, 353, "typed variable should be initialized"; |
207 |
| - ok %d.VAR.default === Nil, 'is the default set correctly for Int %d'; |
208 |
| -} #19 |
| 209 | +#?niecza skip "is default NYI" |
| 210 | +# native types |
| 211 | +{ |
| 212 | + throws-like 'my int $a is default(42)', |
| 213 | + X::Comp::Trait::NotOnNative, |
| 214 | + type => 'is', |
| 215 | + subtype => 'default'; |
| 216 | + throws-like 'my int @a is default(42)', |
| 217 | + X::Comp::Trait::NotOnNative, |
| 218 | + type => 'is', |
| 219 | + subtype => 'default'; |
| 220 | + #?rakudo todo 'fails first on native int hashes being NYI' |
| 221 | + throws-like 'my int %a is default(42)', |
| 222 | + X::Comp::Trait::NotOnNative, |
| 223 | + type => 'is', |
| 224 | + subtype => 'default'; |
| 225 | + |
| 226 | + #?rakudo todo 'native int default(*) is NYI' |
| 227 | + lives-ok { EVAL 'my int $a is default(*)' }, |
| 228 | + 'the default(*) trait on natives'; |
| 229 | +} #4 |
209 | 230 |
|
210 | 231 | # vim: ft=perl6
|
0 commit comments