Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for cloning objects with array and hash attributes #29

Merged
merged 3 commits into from Jun 21, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion S12-attributes/clone.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 14;
plan 18;

# L<S12/Cloning/You can clone an object, changing some of the attributes:>
class Foo {
Expand Down 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_deeply $a1.array, ['a', 'b'], 'original object has its original array';
is_deeply $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_deeply $b1.hash, {'a' => 'b'}, 'original object has its original hash';
is_deeply $b2.hash, {'c' => 'd'}, 'cloned object has the newly-provided hash';
}

# vim: ft=perl6