Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (44 sloc) 1.743 kb
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
1 use v6;
2
3 use Test;
4
5 plan 8;
6
7 # "The context inside of hash and array scripts seems to be/is wrong"
8
b73fa24 Added more smartlinks.
rocket authored
9 # L<S02/Names and Variables/"The context in which a subscript is evaluated is no longer controlled by the sigil either.">
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
10 {
11 sub return_01 { my @sub_array = ("0", "1"); return @sub_array }
12
13 my @array = <a b c d>;
14 my @sliced = @array[return_01()];
15 # @sliced *should* be <a b>, but it is <c>.
16 # This is because return_012() is called in numeric context, and so return_012
17 # returns the *number* of elems in @sub_array instead of the array @sub_array.
18 is ~@sliced, "a b", "context inside of array subscripts for slices";
19 }
20
21 # Same for hashes.
22 {
23 sub return_ab { my @sub_array = <a b>; return @sub_array }
24
25 my %hash = (a => 1, b => 2, c => 3);
26 my @sliced = %hash{return_ab()};
27 # @sliced *should* be ("1, "2").
28 # The above for bug explanation.
29 is ~@sliced, "1 2", "context inside of hash subscripts for slices";
30 }
31
32 # This time we return a single value.
33 {
34 sub return_3 { 3 }
35 sub return_c { "c" }
36
37 my @array = <a b c d e>;
38 my %hash = (c => 12);
39
40 is ~@array[return_3()], "d",
41 "context inside of array subscripts in normal rvalue context";
42 is ~%hash{return_c()}, 12,
43 "context inside of hash subscripts in normal rvalue context";
44
45 @array[return_3()] = "Z";
46 %hash{return_c()} = 23;
47
48 is @array[3], "Z", "context inside of array subscripts in lvalue context";
49 is %hash<c>, 23, "context inside of hash subscripts in lvalue context";
50
51 @array[3] = 15;
52 @array[return_3()]++;
53 %hash{return_c()}++;
54
31a1c80 [t/spec] git rid of accidential interpolation of &postfix<stuff>
moritz authored
55 is @array[3], 16, 'context inside of array subscripts when used with &postfix:<++>';
56 is %hash<c>, 24, 'context inside of hash subscripts when used with &postfix:<++>';
0ca4c11 [gsoc_spectest] t/data_types/* -> t/spec/S02-builtin_data_types/
Auzon authored
57 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
58
59 # vim: ft=perl6
Something went wrong with that request. Please try again.