Skip to content

Commit 510b44a

Browse files
committed
Add autovivification tests for append/prepend
1 parent e427332 commit 510b44a

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

S02-types/autovivification.t

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v6;
22

33
use Test;
44

5-
plan 25;
5+
plan 22;
66

77
# L<S09/Autovivification/In Perl 6 these read-only operations are indeed non-destructive:>
88
{
@@ -69,15 +69,34 @@ sub bar ($baz is readonly) { }
6969
#?niecza skip "Unable to resolve method push in type Any"
7070
{
7171
my %h;
72-
push %h<a>, 4, 2;
73-
is %h<a>.join, '42', 'can autovivify in sub form of push';
74-
unshift %h<b>, 5, 3;
75-
is %h<b>.join, '53', 'can autovivify in sub form of unshift';
76-
%h<c><d>.push( 7, 8 );
77-
is %h<c><d>.join, '78', 'can autovivify in method form of push';
78-
%h<e><f>.unshift( 9, 10 );
79-
is %h<e><f>.join, '910', 'can autovivify in method form of unshift';
80-
is %h.keys.elems, 4, 'successfully autovivified lower level';
72+
push %h<s-push><a>, 1, 2;
73+
unshift %h<s-unsh><b>, 3, 4;
74+
append %h<s-appe><c>, 5, 6;
75+
prepend %h<s-prep><d>, 7, 8;
76+
%h<m-push><1>.push: <a b c>;
77+
%h<m-unsh><2>.unshift: <d e f>;
78+
%h<m-appe><3>.append: <g h i>;
79+
%h<m-prep><4>.prepend: <j k l>;
80+
81+
is %h.keys.elems, 8, 'successfully autovivified lower level';
82+
83+
subtest 'can autovivify in...' => {
84+
plan 2;
85+
subtest '...sub form of...' => {
86+
plan 4;
87+
is-deeply %h<s-push><a>, [ 1, 2 ], 'push';
88+
is-deeply %h<s-unsh><b>, [ 3, 4 ], 'unshift';
89+
is-deeply %h<s-appe><c>, [ 5, 6 ], 'append';
90+
is-deeply %h<s-prep><d>, [ 7, 8 ], 'prepend';
91+
}
92+
subtest '...method form of...' => {
93+
plan 4;
94+
is-deeply %h<m-push><1>, [ <a b c>,], 'push';
95+
is-deeply %h<m-unsh><2>, [ <d e f>,], 'unshift';
96+
is-deeply %h<m-appe><3>, [|<g h i> ], 'append';
97+
is-deeply %h<m-prep><4>, [|<j k l> ], 'prepend';
98+
}
99+
}
81100
}
82101

83102
{

0 commit comments

Comments
 (0)