-
Notifications
You must be signed in to change notification settings - Fork 134
/
autoref.t
304 lines (241 loc) · 8.08 KB
/
autoref.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
use v6-alpha;
use Test;
# L<S02/"Literals"/"In scalar context, though, the implied parentheses are not removed">
=begin description
Tests testing that automatical referentiation (e.g. $arrayref = @array)
works. To be more detalled, things tested are:
* Implicit & explicit referentiation of arrays & hashes in assignment
* Implicit & explicit referentiation of arrays & hashes in assignment to an
array & hash element
* Implicit & explicit referentiation of array&hashes&array literals&arrayref
literals&hashref literals in pair creation with key => ... and :key(...)
and ... => key.
=end description
plan 57;
# Implicit referentiation of arrays in assignment
{
my @array = <a b c>;
my $ref = @array;
is ~$ref, "a b c", '$arrayref = @array works (1)';
is +$ref, 3, '$arrayref = @array works (2)';
}
# Explicit referentiation of arrays in assignment
#?rakudo 1 skip "parse error"
#?DOES 2
{
my @array = <a b c>;
my $ref = \@array;
is ~$ref, "a b c", '$arrayref = \@array works (1)';
is +$ref, 3, '$arrayref = \@array works (2)';
}
# Implicit referentiation of hashes in assignment
{
my %hash = (a => 1, b => 2, c => 3);
my $ref = %hash;
is ~$ref.values.sort, "1 2 3", '$hashref = %hash works (1)';
is +$ref.values, 3, '$hashref = %hash works (2)';
}
# Explicit referentiation of hashes in assignment
#?rakudo 1 skip "parse error"
#?DOES 2
{
my %hash = (a => 1, b => 2, c => 3);
my $ref = \%hash;
is ~$ref.values.sort, "1 2 3", '$hashref = \%hash works (1)';
is +$ref.values, 3, '$hashref = \%hash works (2)';
}
# Implicit referentiation of arrays in assignment to an array element
{
my @array = <a b c>;
my @other;
@other[1] = @array;
is ~@other, " a b c", '@other[$idx] = @array works (1)';
is +@other, 2, '@other[$idx] = @array works (2)';
is +@other[1], 3, '@other[$idx] = @array works (3)';
}
# Explicit referentiation of arrays in assignment to an array element
#?rakudo 1 skip "parse error"
#?DOES 3
{
my @array = <a b c>;
my @other;
@other[1] = \@array;
is ~@other, " a b c", '@other[$idx] = \@array works (1)';
is +@other, 2, '@other[$idx] = \@array works (2)';
is +@other[1], 3, '@other[$idx] = \@array works (3)';
}
# Implicit referentiation of hashes in assignment to an array element
{
my %hash = (a => 1, b => 2, c => 3);
my @other;
@other[1] = %hash;
is +@other, 2, '@other[$idx] = %hash works (1)';
is +@other[1], 3, '@other[$idx] = %hash works (2)';
}
# Explicit referentiation of hashes in assignment to an array element
#?rakudo 1 skip "parse error"
#?DOES 2
{
my %hash = (a => 1, b => 2, c => 3);
my @other;
@other[1] = \%hash;
is +@other, 2, '@other[$idx] = \%hash works (1)';
is +@other[1], 3, '@other[$idx] = \%hash works (2)';
}
# Implicit referentiation of arrays in assignment to a hash element
{
my @array = <a b c>;
my %other;
%other<a> = @array;
is +%other, 1, '%other[$key] = @array works (1)';
is +%other<a>, 3, '%other[$key] = @array works (2)';
}
# Explicit referentiation of arrays in assignment to a hash element
#?rakudo 1 skip "parse error"
#?DOES 2
{
my @array = <a b c>;
my %other;
%other<a> = \@array;
is +%other, 1, '%other[$key] = \@array works (1)';
is +%other<a>, 3, '%other[$key] = \@array works (2)';
}
# Implicit referentiation of hashes in assignment to a hash element
{
my %hash = (a => 1, b => 2, c => 3);
my %other;
%other<a> = %hash;
is +%other, 1, '%other[$key] = %hash works (1)';
is +%other<a>, 3, '%other[$key] = %hash works (2)';
}
# Explicit referentiation of hashes in assignment to a hash element
#?rakudo 1 skip "parse error"
#?DOES 2
{
my %hash = (a => 1, b => 2, c => 3);
my %other;
%other<a> = \%hash;
is +%other, 1, '%other[$key] = \%hash works (1)';
is +%other<a>, 3, '%other[$key] = \%hash works (2)';
}
# Implicit referentiation of arrays in pair creation with key => ...
{
my @array = <a b c>;
my $pair = (key => @array);
is ~$pair.value, "a b c", '(key => @array) works (1)';
is +$pair.value, 3, '(key => @array) works (2)';
}
# Explicit referentiation of arrays in pair creation with key => ...
#?rakudo 1 skip "parse error"
#?DOES 2
{
my @array = <a b c>;
my $pair = (key => \@array);
is ~$pair.value, "a b c", '(key => \@array) works (1)';
is +$pair.value, 3, '(key => \@array) works (2)';
}
# Implicit referentiation of hashes in pair creation with key => ...
{
my %hash = (a => 1, b => 2, c => 3);
my $pair = (key => %hash);
is ~$pair.value.values.sort, "1 2 3", '(key => %hash) works (1)';
is +$pair.value.values, 3, '(key => %hash) works (2)';
}
# Explicit referentiation of hashes in pair creation with key => ...
#?rakudo 1 skip "parse error"
#?DOES 2
{
my %hash = (a => 1, b => 2, c => 3);
my $pair = (key => \%hash);
is ~$pair.value.values.sort, "1 2 3", '(key => \%hash) works (1)';
is +$pair.value.values, 3, '(key => \%hash) works (2)';
}
# Implicit referentiation of arrays in pair creation with :key(...)
{
my @array = <a b c>;
my $pair = (:key(@array));
is ~$pair.value, "a b c", '(:key(@array)) works (1)';
is +$pair.value, 3, '(:key(@array)) works (2)';
}
# Explicit referentiation of arrays in pair creation with :key(...)
#?rakudo 1 skip "parse error"
#?DOES 2
{
my @array = <a b c>;
my $pair = (:key(\@array));
is ~$pair.value, "a b c", '(:key(\@array)) works (1)';
is +$pair.value, 3, '(:key(\@array)) works (2)';
}
# Implicit referentiation of hashes in pair creation with :key(...)
{
my %hash = (a => 1, b => 2, c => 3);
my $pair = (:key(%hash));
is ~$pair.value.values.sort, "1 2 3", '(:key(%hash)) works (1)';
is +$pair.value.values, 3, '(:key(%hash)) works (2)';
}
#?rakudo 1 skip "parse error"
#?DOES 2
# Explicit referentiation of hashes in pair creation with :key(...)
{
my %hash = (a => 1, b => 2, c => 3);
my $pair = (:key(\%hash));
is ~$pair.value.values.sort, "1 2 3", '(:key(\%hash)) works (1)';
is +$pair.value.values, 3, '(:key(\%hash)) works (2)';
}
# Implicit referentiation of array literals in pair creation with key => ...
{
my $pair = (key => <a b c>);
is ~$pair.value, "a b c", '(key => <...>) works (1)';
is +$pair.value, 3, '(key => <...>) works (2)';
}
# Arrayref literals in pair creation with key => ...
{
my $pair = (key => [<a b c>]);
is ~$pair.value, "a b c", '(key => [<...>]) works (1)';
is +$pair.value, 3, '(key => [<...>]) works (2)';
}
# Hashref literals in pair creation with key => ...
{
my $pair = (key => { a => 1, b => 2 });
is +$pair.value, 2, '(key => {...}) works';
}
# Implicit referentiation of array literals in pair creation with :key(...)
{
my $pair = (:key(<a b c>));
is ~$pair.value, "a b c", '(:key(<...>)) works (1)';
is +$pair.value, 3, '(:key(<...>)) works (2)';
}
# Arrayref literals in pair creation with :key(...)
{
my $pair = (:key([<a b c>]));
is ~$pair.value, "a b c", '(:key([<...>])) works (1)';
is +$pair.value, 3, '(:key([<...>])) works (2)';
}
# Hashref literals in pair creation with :key(...)
{
my $pair = (:key({ a => 1, b => 2 }));
is +$pair.value, 2, '(:key({...})) works';
}
# Implicit referentiation of array literals in pair creation with ... => "value"
#?rakudo 1 skip "parse error"
#?DOES 2
{
my $pair = (<a b c> => "value");
is ~$pair.key, "a b c", '(<...> => "value") works (1)';
is +$pair.key, 3, '(<...> => "value") works (2)';
}
# Arrayref literals in pair creation with ... => "value"
#?rakudo 1 skip "parse error"
#?DOES 2
{
my $pair = ([<a b c>] => "value");
is ~$pair.key, "a b c", '([<...>] => "value") works (1)';
is +$pair.key, 3, '([<...>] => "value") works (2)';
}
# Hashref literals in pair creation with ... => "value"
#?rakudo 1 skip "parse error"
#?DOES 1
{
my $pair = ({ a => 1, b => 2 } => "value");
is +$pair.key, 2, '({...} => "value") works';
}