- Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathextending-arrays.t
71 lines (43 loc) · 1.37 KB
/
extending-arrays.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
useMONKEY-TYPING;
useTest;
plan13;
augmentclassArray { methodtest_method { 1 }; };
augmentclassHash { methodtest_method { 1 }; };
my@named_array;
ok@named_array.test_method, "Uninitialized array";
@named_array= (1,2,3);
ok@named_array.test_method, "Populated array";
oktry { [].test_method }, "Bare arrayitem";
my$arrayitem= [];
$arrayitem= [];
ok$arrayitem.test_method, "arrayitem in a variable";
my%named_hash;
ok%named_hash.test_method, "Uninitialized hash";
%named_hash= (Foo =>"bar");
ok%named_hash.test_method, "Populated hash";
oktry { ~{foo =>"bar"}.test_method }, "Bare hash item";
my$hashitem= {foo =>"bar"};
ok$hashitem.test_method, "Named hashitem";
# Now for pairs.
is(try { (:key<value>).value; }, 'value', "method on a bare pair");
my$pair=:key<value>;
is$pair.value, 'value', "method on a named pair";
{
augmentclassList {
methodtwice {
gather {
take$_*2forself.list;
}
}
}
is (1, 2, 3).twice.join('|'), "2|4|6", 'can extend class List';
}
# https://github.com/rakudo/rakudo/issues/1238
{
myroleA { has$.a=42 }
myroleB { has$.b=666 }
my$array= ([1,2,3] but A) but B;
is-deeply$array.a, 42, 'did the first mixin survive';
is-deeply$array.b, 666, 'did the second mixin survive';
}
# vim: expandtab shiftwidth=4