Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add tests for cloning objects with array and hash attributes
  • Loading branch information
Samuel Sutch committed Jun 21, 2013
1 parent eb3daa3 commit f17765d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions S12-attributes/clone.t
Expand Up @@ -65,4 +65,25 @@ is($val2, 42, '... cloned object has proper attr value');
is ~$q{'foo'}, 'a', 'cloned Match object retained named capture value';
}

# test cloning of array and hash attributes
{
# array
class A {
has @.array;
}
my $a1 = A.new(:array<a b>);
my $a2 = $a1.clone(:array<c d>);
is $a1.array, <a b>, 'original object has its original array';
is $a2.array, <c d>, 'cloned object has the newly-provided array';

# hash
class B {
has %.hash;
}
my $b1 = B.new(hash=>{'a' => 'b'});
my $b2 = $b1.clone(hash=>{'c' => 'd'});
is $b1.hash, {'a' => 'b'}, 'original object has its original hash';
is $b2.hash, {'c' => 'd'}, 'cloned object has the newly-provided hash';
}

# vim: ft=perl6

0 comments on commit f17765d

Please sign in to comment.