Skip to content

Commit 8cd62db

Browse files
committed
Add tests for BagHash.(values|kv|pairs) modifying
1 parent 6bad631 commit 8cd62db

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

S02-types/baghash.t

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v6;
22
use Test;
33

4-
plan 265;
4+
plan 274;
55

66
# L<S02/Mutable types/QuantHash of UInt>
77

@@ -606,4 +606,43 @@ subtest 'BagHash autovivification of non-existent keys' => {
606606
is-deeply $bh5<as>, 2, 'correct result of assignment';
607607
}
608608

609+
{
610+
my $bh = <a a a>.BagHash;
611+
for $bh.values { $_-- }
612+
is $bh, "a(2)",
613+
'Can use $_ from .values to remove occurrences from BagHash';
614+
for $bh.values { $_ = 42 }
615+
is $bh, "a(42)",
616+
'Can use $_ from .values to set number occurrences in BagHash';
617+
for $bh.values { $_ = 0 }
618+
is $bh, "",
619+
'Can use $_ from .values to remove items from BagHash';
620+
}
621+
622+
{
623+
my $bh = <a a a>.BagHash;
624+
for $bh.kv -> \k, \v { v-- }
625+
is $bh, "a(2)",
626+
'Can use value from .kv to remove occurrences from BagHash';
627+
for $bh.kv -> \k, \v { v = 42 }
628+
is $bh, "a(42)",
629+
'Can use value from .kv to set number occurrences in BagHash';
630+
for $bh.kv -> \k, \v { v = 0 }
631+
is $bh, "",
632+
'Can use $_ from .kv to remove items from BagHash';
633+
}
634+
635+
{
636+
my $bh = <a a a>.BagHash;
637+
for $bh.pairs { .value-- }
638+
is $bh, "a(2)",
639+
'Can use value from .pairs to remove occurrences from BagHash';
640+
for $bh.pairs { .value = 42 }
641+
is $bh, "a(42)",
642+
'Can use value from .pairs to set number occurrences in BagHash';
643+
for $bh.pairs { .value = 0 }
644+
is $bh, "",
645+
'Can use $_ from .pairs to remove items from BagHash';
646+
}
647+
609648
# vim: ft=perl6

0 commit comments

Comments
 (0)