Skip to content

Commit

Permalink
Test .clone works on SetHash, BagHash, and MixHash
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Jan 4, 2017
1 parent fed7442 commit 37b3e12
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
26 changes: 25 additions & 1 deletion S02-types/baggy.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 3;
plan 5;

# Tests of the Baggy role

Expand All @@ -12,3 +12,27 @@ plan 3;
is-deeply $b.invert, (2 => "a", 1 => "b"), '.invert';
is-deeply $b.SetHash, SetHash.new(<a b>), '.SetHash';
}

{ # RT#127863
subtest 'cloned BagHash gets its own elements storage' => {
plan 2;
my $a = BagHash.new: <a b c>;
my $b = $a.clone;
$a<a>--; $a<b>++; $a<z> = 42;
is-deeply $a, BagHash.new-from-pairs("b" => 2, "c" => 1, "z" => 42),
'modifying first bag works, even after we created its clone';
is-deeply $b, BagHash.new(<a b c>),
'modifying first bag does not affect cloned bag';
}

subtest 'cloned MixHash gets its own elements storage' => {
plan 2;
my $a = MixHash.new: <a b c>;
my $b = $a.clone;
$a<a>--; $a<b>++; $a<z> = 42;
is-deeply $a, MixHash.new-from-pairs("b" => 2, "c" => 1, "z" => 42),
'modifying first mix works, even after we created its clone';
is-deeply $b, MixHash.new(<a b c>),
'modifying first mix does not affect cloned mix';
}
}
14 changes: 13 additions & 1 deletion S02-types/sethash.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 209;
plan 210;

# L<S02/Mutable types/"QuantHash of Bool">

Expand Down Expand Up @@ -477,4 +477,16 @@ subtest 'SetHash autovivification of non-existent keys' => {
is-deeply $sh5<as>, Bool::True, 'correct result of assignment';
}

# RT#127863
subtest 'cloned SetHash gets its own elements storage' => {
plan 2;
my $a = SetHash.new: <a b c>;
my $b = $a.clone;
$a<a>--; $a<b>++; $a<z> = 1;
is-deeply $a, SetHash.new-from-pairs("b" => 1, "c" => 1, "z" => 1),
'modifying first set works, even after we created its clone';
is-deeply $b, SetHash.new(<a b c>),
'modifying first set does not affect cloned set';
}

# vim: ft=perl6

0 comments on commit 37b3e12

Please sign in to comment.