diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/map_dict_test.gleam | 27 |
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}])) +} |