/
smiley.t
134 lines (114 loc) · 6.26 KB
/
smiley.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use Test;
plan 54;
is class { has Int $.a }.new.a, Int, 'can Int be on its own';
is class { has Int $.a = Int }.new.a, Int, 'can Int take an Int:U';
is class { has Int $.a = 42 }.new.a, 42, 'can Int take an Int:D';
is class { has Int:_ $.a }.new.a, Int, 'can Int:_ be on its own';
is class { has Int:_ $.a = Int }.new.a, Int, 'can Int:_ take an Int:U';
is class { has Int:_ $.a = 42 }.new.a, 42, 'can Int:_ take an Int:D';
is class { has Int:U $.a }.new.a, Int, 'can Int:U be on its own';
is class { has Int:U $.a = Int }.new.a, Int, 'can Int:U take an Int:U';
throws-like 「class { has Int:U $.a = 42 }.new.a」,
X::TypeCheck::Attribute::Default,
name => '$!a', 'can Int:U take an Int:D';
throws-like 'class { has Int:D $.a }',
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'can Int:D be on its own';
throws-like { class { has Int:D $.a = Int }.new.a },
X::TypeCheck::Assignment,
symbol => '$!a', 'can Int:D take an Int:U';
is class { has Int:D $.a = 42 }.new.a, 42, 'can Int:D take an Int:D';
{
use attributes :_;
is class { has Int $.a }.new.a, Int, 'with :_, can Int be on its own';
is class { has Int $.a = Int }.new.a, Int, 'with :_, can Int take an Int:U';
is class { has Int $.a = 42 }.new.a, 42, 'with :_, can Int take an Int:D';
is class { has Int:_ $.a }.new.a, Int, 'with :_, can Int:_ be on its own';
is class { has Int:_ $.a = Int }.new.a, Int, 'with :_, can Int:_ take an Int:U';
is class { has Int:_ $.a = 42 }.new.a, 42, 'with :_, can Int:_ take an Int:D';
is class { has Int:U $.a }.new.a, Int, 'with :_, can Int:U be on its own';
is class { has Int:U $.a = Int }.new.a, Int, 'with :_, can Int:U take an Int:U';
throws-like 「class { has Int:U $.a = 42 }.new」,
X::TypeCheck::Attribute::Default,
name => '$!a', 'with :_, can Int:U take an Int:D';
throws-like 'class { has Int:D $.a }',
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'with :_, can Int:D be on its own';
throws-like { class { has Int:D $.a = Int }.new },
X::TypeCheck::Assignment,
symbol => '$!a', 'with :_, can Int:D take an Int:U';
is class { has Int:D $.a = 42 }.new.a, 42, 'with :_, can Int:D take an Int:D';
}
{
use attributes :U;
is class { has Int $.a }.new.a, Int, 'with :U, can Int be on its own';
is class { has Int $.a = Int }.new.a, Int, 'with :U, can Int take an Int:U';
throws-like 「use attributes :U; class { has Int $a = 42 }.new」, # XXX pragma's not seen in EVAL
X::TypeCheck::Attribute::Default,
name => '$!a', 'with :U, can Int take an Int:D';
is class { has Int:_ $.a }.new.a, Int, 'with :U, can Int:_ be on its own';
is class { has Int:_ $.a = Int }.new.a, Int, 'with :U, can Int:_ take an Int:U';
is class { has Int:_ $.a = 42 }.new.a, 42, 'with :U, can Int:_ take an Int:D';
is class { has Int:U $.a }.new.a, Int, 'with :U, can Int:U be on its own';
is class { has Int:U $.a = Int }.new.a, Int, 'with :U, can Int:U take an Int:U';
throws-like 「use attributes :U; class { has Int:U $.a = 42 }.new」,
X::TypeCheck::Attribute::Default,
name => '$!a', 'with :U, can Int:U take an Int:D';
throws-like 'use attributes :U; class { has Int:D $a }', # XXX pragma's not seen in EVAL
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'with :U, can Int:D be on its own';
throws-like { class { has Int:D $.a = Int }.new },
X::TypeCheck::Assignment,
symbol => '$!a', 'with :U, can Int:D take an Int:U';
is class { has Int:D $.a = 42 }.new.a, 42, 'with :U, can Int:D take an Int:D';
}
{
use attributes :D;
throws-like 'use attributes :D; class { has Int $a }', # XXX pragma's not seen in EVAL
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', implicit => ':D by pragma', 'with :D, can Int be on its own';
throws-like { class { has Int $a = Int }.new },
X::TypeCheck::Assignment,
symbol => '$!a', 'with :D, can Int take an Int:U';
is class { my Int $.a = 42 }.new.a, 42, 'with :D, can Int take an Int:D';
is class { has Int:_ $.a }.new.a, Int, 'with :D, can Int:_ be on its own';
is class { has Int:_ $.a = Int }.new.a, Int, 'with :D, can Int:_ take an Int:U';
is class { has Int:_ $.a = 42 }.new.a, 42, 'with :D, can Int:_ take an Int:D';
is class { has Int:U $.a }.new.a, Int, 'with :D, can Int:U be on its own';
is class { has Int:U $.a = Int }.new.a, Int, 'with :D, can Int:U take an Int:U';
throws-like 「class { has Int:U $.a = 42 }.new」,
X::TypeCheck::Attribute::Default,
name => '$!a', 'with :D, can Int:U take an Int:D';
throws-like 'use attributes :D; class { has Int:D $.a }', # XXX pragma's not seen in EVAL
X::Syntax::Variable::MissingInitializer,
type => 'Int:D', 'with :D, can Int:D be on its own';
throws-like { class { has Int:D $.a = Int }.new },
X::TypeCheck::Assignment,
symbol => '$!a', 'with :D, can Int:D take an Int:U';
is class { has Int:D $.a = 42 }.new.a, 42, 'with :D, can Int:D take an Int:D';
}
throws-like 'my Int:foo $a',
X::InvalidTypeSmiley, 'does Int:foo fail';
throws-like 'use attributes',
X::Pragma::MustOneOf,
name => "attributes",
'does use attributes fail';
throws-like 'no attributes',
X::Pragma::CannotWhat,
what => 'no',
name => "attributes",
'does no attributes fail';
throws-like 'use attributes "bar"',
X::Pragma::UnknownArg,
name => "attributes",
arg => "bar",
'does use attributes "bar" fail';
throws-like 'use attributes :U, :D',
X::Pragma::OnlyOne,
name => 'attributes',
'does use attributes :U, :D fail';
throws-like 'use attributes :foo',
X::InvalidTypeSmiley,
name => 'foo',
'does use attributes :foo fail';
# vim: expandtab shiftwidth=4