Skip to content

Commit

Permalink
Test Array.clone
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Feb 16, 2017
1 parent 4f224be commit a460cdc
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion S32-array/create.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use v6;
use Test;
plan 9;
plan 11;

# L<S32::Containers/"Array"/"=item ">

Expand Down Expand Up @@ -30,4 +30,37 @@ is(+$array_obj, 3, 'Finding the length functions properly.');
eval-lives-ok (1,2,3).Array[0]++,
'array elements get writable containers';

{ # RT #129762
subtest 'Array.clone [partially-reified]' => {
plan 3;

my @a = 1, {rand} … *;
my @b = @a.clone;
is-deeply @a[^20], @b[^20], 'clone and original array share reifier';

@b[5] = 42;
cmp-ok @a[5], '!=', 42, 'changing clone does not impact original';
@a[3] = 72;
cmp-ok @b[3], '!=', 72, 'changing original does not impact clone';
}

subtest 'Array.clone [fully-reified]' => {
plan 5;

my @a = 1, 2, 3, 4;
my @b = @a.clone;
is-deeply @a, @b, 'clone and original array have same values';

@b[3] = 42;
cmp-ok @a[3], '!=', 42, 'changing clone does not impact original';
@a[2] = 72;
cmp-ok @b[2], '!=', 72, 'changing original does not impact clone';

@b.push: 42;
is-deeply +@b, 1+@a, 'adding items to clone does not affect original';
@a.append: 42, 72;
is-deeply +@a, 1+@b, 'adding items to original does not affect clone';
}
}

# vim: ft=perl6

0 comments on commit a460cdc

Please sign in to comment.