aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2019-05-04 22:07:48 +0000
committerLouis Pilfold <louis@lpil.uk>2019-05-04 22:07:48 +0000
commit49df300ffe6f020a4df26dede27bef42d000c671 (patch)
treeae931ab693c58e3e174f06004514d1406a4119c8 /test
parent50021b4d4061f1fa1eac90986695531d8c4772e8 (diff)
downloadgleam_stdlib-49df300ffe6f020a4df26dede27bef42d000c671.tar.gz
gleam_stdlib-49df300ffe6f020a4df26dede27bef42d000c671.zip
map_dict:update
Diffstat (limited to 'test')
-rw-r--r--test/map_dict_test.gleam27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/map_dict_test.gleam b/test/map_dict_test.gleam
index 359df7c..551a333 100644
--- a/test/map_dict_test.gleam
+++ b/test/map_dict_test.gleam
@@ -174,3 +174,30 @@ pub fn delete_test() {
|> map_dict:delete(_, "d")
|> expect:equal(_, map_dict:from_list([{"b", 1}, {"c", 2}]))
}
+
+pub fn update_test() {
+ let dict = map_dict:from_list([
+ {"a", 0},
+ {"b", 1},
+ {"c", 2},
+ ])
+
+ let inc_or_zero = fn(x) {
+ case x {
+ | Ok(i) -> i + 1
+ | Error(_) -> 0
+ }
+ }
+
+ dict
+ |> map_dict:update(_, "a", inc_or_zero)
+ |> expect:equal(_, map_dict:from_list([{"a", 1}, {"b", 1}, {"c", 2}]))
+
+ dict
+ |> map_dict:update(_, "b", inc_or_zero)
+ |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 2}, {"c", 2}]))
+
+ dict
+ |> map_dict:update(_, "z", inc_or_zero)
+ |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}, {"c", 2}, {"z", 0}]))
+}