aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2024-05-21 09:45:35 +0200
committerLouis Pilfold <louis@lpil.uk>2024-05-24 16:10:09 +0100
commitf66ad5672d061bbaba0af9458da6f1f4fe0211d9 (patch)
tree683edf993cd96254502b14972602f6498405893f /test
parent84f573260eddae1e581dd7894915cb3181440b02 (diff)
downloadgleam_stdlib-f66ad5672d061bbaba0af9458da6f1f4fe0211d9.tar.gz
gleam_stdlib-f66ad5672d061bbaba0af9458da6f1f4fe0211d9.zip
The `dict` module gains the `combine` function
Diffstat (limited to 'test')
-rw-r--r--test/gleam/dict_test.gleam26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/gleam/dict_test.gleam b/test/gleam/dict_test.gleam
index ca77bb9..0bcb334 100644
--- a/test/gleam/dict_test.gleam
+++ b/test/gleam/dict_test.gleam
@@ -403,3 +403,29 @@ pub fn extra_keys_equality_test() {
should.be_false(map1 == map2)
should.be_false(map2 == map1)
}
+
+pub fn combine_test() {
+ let map1 = dict.from_list([#("a", 3), #("b", 2)])
+ let map2 = dict.from_list([#("a", 2), #("c", 3), #("d", 4)])
+
+ dict.combine(map1, map2, fn(one, other) { one - other })
+ |> should.equal(dict.from_list([#("a", 1), #("b", 2), #("c", 3), #("d", 4)]))
+}
+
+pub fn combine_with_empty_test() {
+ let map1 = dict.from_list([#("a", 3), #("b", 2)])
+
+ dict.combine(map1, dict.new(), fn(one, _) { one })
+ |> should.equal(map1)
+
+ dict.combine(dict.new(), map1, fn(one, _) { one })
+ |> should.equal(map1)
+}
+
+pub fn combine_with_no_overlapping_keys_test() {
+ let map1 = dict.from_list([#("a", 1), #("b", 2)])
+ let map2 = dict.from_list([#("c", 3), #("d", 4)])
+
+ dict.combine(map1, map2, fn(one, _) { one })
+ |> should.equal(dict.from_list([#("a", 1), #("b", 2), #("c", 3), #("d", 4)]))
+}