aboutsummaryrefslogtreecommitdiff
path: root/tests/test_hashmap.c
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-16 14:06:02 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-16 14:06:02 +0100
commit31e98ced014b9326ddfc990b003864df69cd4dcc (patch)
tree6a7b55b591c7152adac7110804c174d6dd05564d /tests/test_hashmap.c
parent19597032cdbaba1271e8134f865f56410d886c11 (diff)
downloadunja-31e98ced014b9326ddfc990b003864df69cd4dcc.tar.gz
unja-31e98ced014b9326ddfc990b003864df69cd4dcc.zip
return old values when inserting or removing from hashmap
Diffstat (limited to 'tests/test_hashmap.c')
-rw-r--r--tests/test_hashmap.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/tests/test_hashmap.c b/tests/test_hashmap.c
index 14ec552..82f340c 100644
--- a/tests/test_hashmap.c
+++ b/tests/test_hashmap.c
@@ -5,23 +5,49 @@ START_TESTS
TEST(hashmap) {
struct hashmap *hm = hashmap_new();
- assert(hashmap_get(hm, "foo") == NULL, "expected NULL");
- hashmap_insert(hm, "foo", "bar");
char *value = hashmap_get(hm, "foo");
+ assert_null(value);
+ value = hashmap_insert(hm, "foo", "bar");
+ assert_null(value);
+ value = hashmap_get(hm, "foo");
assert_str(value, "bar");
hashmap_free(hm);
}
TEST(dot_notation) {
+ void *val;
struct hashmap *user = hashmap_new();
- hashmap_insert(user, "name", "Danny");
+ val = hashmap_insert(user, "name", "Danny");
+ assert_null(val);
struct hashmap *hm = hashmap_new();
- hashmap_insert(hm, "user", user);
+ val = hashmap_insert(hm, "user", user);
+ assert_null(val);
assert(hashmap_resolve(hm, "user") == user, "expected user hashmap, got something else");
- char *value = (char *) hashmap_resolve(hm, "user.name");
- assert_str(value, "Danny");
+ val = hashmap_resolve(hm, "user.name");
+ assert_str(val, "Danny");
hashmap_free(user);
hashmap_free(hm);
}
+TEST(hashmap_remove) {
+ struct hashmap *hm = hashmap_new();
+ hashmap_insert(hm, "foo", "bar");
+ char *value = hashmap_get(hm, "foo");
+ assert_str(value, "bar");
+
+ // remove once
+ value = hashmap_remove(hm, "foo");
+ assert_str(value, "bar");
+ value = hashmap_get(hm, "foo");
+ assert_null(value);
+
+ // remove again (should no-op)
+ value = hashmap_remove(hm, "foo");
+ assert_null(value);
+ value = hashmap_get(hm, "foo");
+ assert_null(value);
+
+ hashmap_free(hm);
+}
+
END_TESTS \ No newline at end of file