diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-01-23 10:48:55 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
commit | 2e0a304839764236654e73d38fa380b317a3fac1 (patch) | |
tree | fdba155593c31b1bb6260ad6bb09dba644bb8a56 /tests/core | |
parent | 9694ef2064be3ecc3f173af296ab091f0498234d (diff) | |
download | libgit2-2e0a304839764236654e73d38fa380b317a3fac1.tar.gz |
oidmap: introduce high-level setter for key/value pairs
Currently, one would use either `git_oidmap_insert` to insert key/value pairs
into a map or `git_oidmap_put` to insert a key only. These function have
historically been macros, which is why their syntax is kind of weird: instead of
returning an error code directly, they instead have to be passed a pointer to
where the return value shall be stored. This does not match libgit2's common
idiom of directly returning error codes.Furthermore, `git_oidmap_put` is tightly
coupled with implementation details of the map as it exposes the index of
inserted entries.
Introduce a new function `git_oidmap_set`, which takes as parameters the map,
key and value and directly returns an error code. Convert all trivial callers of
`git_oidmap_insert` and `git_oidmap_put` to make use of it.
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/oidmap.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/core/oidmap.c b/tests/core/oidmap.c index 0e66b7291..38b4c7d2a 100644 --- a/tests/core/oidmap.c +++ b/tests/core/oidmap.c @@ -182,3 +182,47 @@ void test_core_oidmap__get_fails_with_nonexisting_key(void) git_oidmap_free(map); } + +void test_core_oidmap__setting_oid_persists(void) +{ + git_oid oids[] = { + {{ 0x01 }}, + {{ 0x02 }}, + {{ 0x03 }} + }; + git_oidmap *map; + + cl_git_pass(git_oidmap_new(&map)); + cl_git_pass(git_oidmap_set(map, &oids[0], "one")); + cl_git_pass(git_oidmap_set(map, &oids[1], "two")); + cl_git_pass(git_oidmap_set(map, &oids[2], "three")); + + cl_assert_equal_s(git_oidmap_get(map, &oids[0]), "one"); + cl_assert_equal_s(git_oidmap_get(map, &oids[1]), "two"); + cl_assert_equal_s(git_oidmap_get(map, &oids[2]), "three"); + + git_oidmap_free(map); +} + +void test_core_oidmap__setting_existing_key_updates(void) +{ + git_oid oids[] = { + {{ 0x01 }}, + {{ 0x02 }}, + {{ 0x03 }} + }; + git_oidmap *map; + + cl_git_pass(git_oidmap_new(&map)); + cl_git_pass(git_oidmap_set(map, &oids[0], "one")); + cl_git_pass(git_oidmap_set(map, &oids[1], "two")); + cl_git_pass(git_oidmap_set(map, &oids[2], "three")); + cl_assert_equal_i(git_oidmap_size(map), 3); + + cl_git_pass(git_oidmap_set(map, &oids[1], "other")); + cl_assert_equal_i(git_oidmap_size(map), 3); + + cl_assert_equal_s(git_oidmap_get(map, &oids[1]), "other"); + + git_oidmap_free(map); +} |