Skip to content

Commit 3e73c1e

Browse files
committed
Add/Adapt is default() compile-time checks tests
1 parent ae33205 commit 3e73c1e

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

S02-names/is_default.t

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 118;
4+
plan 107;
55

66
# L<S02/Variables Containing Undefined Values>
77

@@ -70,18 +70,7 @@ plan 118;
7070
my Int $b is default(42) = 768;
7171
is $b, 768, "typed variable should be initialized";
7272
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
8574

8675
#?niecza skip "is default NYI"
8776
# not specifically typed
@@ -132,18 +121,7 @@ plan 118;
132121
my Int @b is default(42) = 768;
133122
is @b[0], 768, "typed array element should be initialized";
134123
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
147125

148126
#?niecza skip "is default NYI"
149127
# not specifically typed
@@ -194,17 +172,60 @@ plan 118;
194172
my Int %b is default(42) = o => 768;
195173
is %b<o>, 768, "typed hash element should be initialized";
196174
is %b.VAR.default, 42, 'is the default set correctly for Int %b';
175+
} #12
197176

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
204208

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
209230

210231
# vim: ft=perl6

integration/advent2013-day20.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ plan 22;
2929
is-deeply @b[1000], False, 'array default';
3030
}
3131

32-
throws-like { EVAL 'my Bool $a is default(42)' }, X::TypeCheck::Assignment;
32+
throws-like 'my Bool $a is default(42)', X::Parameter::Default::TypeCheck;
3333
lives-ok { EVAL 'my Bool $a is default(True)' }, 'eval type check';
3434

3535
{

0 commit comments

Comments
 (0)