Skip to content

Commit

Permalink
Add autovivification tests for append/prepend
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Sep 18, 2016
1 parent e427332 commit 510b44a
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions S02-types/autovivification.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 25;
plan 22;

# L<S09/Autovivification/In Perl 6 these read-only operations are indeed non-destructive:>
{
Expand Down Expand Up @@ -69,15 +69,34 @@ sub bar ($baz is readonly) { }
#?niecza skip "Unable to resolve method push in type Any"
{
my %h;
push %h<a>, 4, 2;
is %h<a>.join, '42', 'can autovivify in sub form of push';
unshift %h<b>, 5, 3;
is %h<b>.join, '53', 'can autovivify in sub form of unshift';
%h<c><d>.push( 7, 8 );
is %h<c><d>.join, '78', 'can autovivify in method form of push';
%h<e><f>.unshift( 9, 10 );
is %h<e><f>.join, '910', 'can autovivify in method form of unshift';
is %h.keys.elems, 4, 'successfully autovivified lower level';
push %h<s-push><a>, 1, 2;
unshift %h<s-unsh><b>, 3, 4;
append %h<s-appe><c>, 5, 6;
prepend %h<s-prep><d>, 7, 8;
%h<m-push><1>.push: <a b c>;
%h<m-unsh><2>.unshift: <d e f>;
%h<m-appe><3>.append: <g h i>;
%h<m-prep><4>.prepend: <j k l>;

is %h.keys.elems, 8, 'successfully autovivified lower level';

subtest 'can autovivify in...' => {
plan 2;
subtest '...sub form of...' => {
plan 4;
is-deeply %h<s-push><a>, [ 1, 2 ], 'push';
is-deeply %h<s-unsh><b>, [ 3, 4 ], 'unshift';
is-deeply %h<s-appe><c>, [ 5, 6 ], 'append';
is-deeply %h<s-prep><d>, [ 7, 8 ], 'prepend';
}
subtest '...method form of...' => {
plan 4;
is-deeply %h<m-push><1>, [ <a b c>,], 'push';
is-deeply %h<m-unsh><2>, [ <d e f>,], 'unshift';
is-deeply %h<m-appe><3>, [|<g h i> ], 'append';
is-deeply %h<m-prep><4>, [|<j k l> ], 'prepend';
}
}
}

{
Expand Down

0 comments on commit 510b44a

Please sign in to comment.