From 8cd62dba844b9fdf6082b99dfba695aab338b0c9 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Sat, 20 May 2017 14:48:42 +0200 Subject: [PATCH] Add tests for BagHash.(values|kv|pairs) modifying --- S02-types/baghash.t | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/S02-types/baghash.t b/S02-types/baghash.t index aab35a9e09..ac364e7b9c 100644 --- a/S02-types/baghash.t +++ b/S02-types/baghash.t @@ -1,7 +1,7 @@ use v6; use Test; -plan 265; +plan 274; # L @@ -606,4 +606,43 @@ subtest 'BagHash autovivification of non-existent keys' => { is-deeply $bh5, 2, 'correct result of assignment'; } +{ + my $bh = .BagHash; + for $bh.values { $_-- } + is $bh, "a(2)", + 'Can use $_ from .values to remove occurrences from BagHash'; + for $bh.values { $_ = 42 } + is $bh, "a(42)", + 'Can use $_ from .values to set number occurrences in BagHash'; + for $bh.values { $_ = 0 } + is $bh, "", + 'Can use $_ from .values to remove items from BagHash'; +} + +{ + my $bh = .BagHash; + for $bh.kv -> \k, \v { v-- } + is $bh, "a(2)", + 'Can use value from .kv to remove occurrences from BagHash'; + for $bh.kv -> \k, \v { v = 42 } + is $bh, "a(42)", + 'Can use value from .kv to set number occurrences in BagHash'; + for $bh.kv -> \k, \v { v = 0 } + is $bh, "", + 'Can use $_ from .kv to remove items from BagHash'; +} + +{ + my $bh = .BagHash; + for $bh.pairs { .value-- } + is $bh, "a(2)", + 'Can use value from .pairs to remove occurrences from BagHash'; + for $bh.pairs { .value = 42 } + is $bh, "a(42)", + 'Can use value from .pairs to set number occurrences in BagHash'; + for $bh.pairs { .value = 0 } + is $bh, "", + 'Can use $_ from .pairs to remove items from BagHash'; +} + # vim: ft=perl6