diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-01-23 10:44:33 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
| commit | 03555830784a2856e0c9651d2643b3ee5ce2084d (patch) | |
| tree | 9796bff7a6ea1a3035565645ab41c49b32d457c8 /tests/core | |
| parent | ef507bc7bdd736d2379a0d0614b3db1341d77187 (diff) | |
| download | libgit2-03555830784a2856e0c9651d2643b3ee5ce2084d.tar.gz | |
strmap: introduce high-level setter for key/value pairs
Currently, one would use the function `git_strmap_insert` to insert key/value
pairs into a map. This function has historically been a macro, which is why its
syntax is kind of weird: instead of returning an error code directly, it instead
has 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.
Introduce a new function `git_strmap_set`, which takes as parameters the map,
key and value and directly returns an error code. Convert all callers of
`git_strmap_insert` to make use of it.
Diffstat (limited to 'tests/core')
| -rw-r--r-- | tests/core/strmap.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/core/strmap.c b/tests/core/strmap.c index 72885c8b1..4d36b744e 100644 --- a/tests/core/strmap.c +++ b/tests/core/strmap.c @@ -129,3 +129,30 @@ void test_core_strmap__get_returns_null_on_nonexisting_key(void) cl_assert_equal_p(git_strmap_get(g_table, "other"), NULL); } + +void test_core_strmap__set_persists_key(void) +{ + cl_git_pass(git_strmap_set(g_table, "foo", "oof")); + cl_assert_equal_s(git_strmap_get(g_table, "foo"), "oof"); +} + +void test_core_strmap__set_persists_multpile_keys(void) +{ + cl_git_pass(git_strmap_set(g_table, "foo", "oof")); + cl_git_pass(git_strmap_set(g_table, "bar", "rab")); + cl_assert_equal_s(git_strmap_get(g_table, "foo"), "oof"); + cl_assert_equal_s(git_strmap_get(g_table, "bar"), "rab"); +} + +void test_core_strmap__set_updates_existing_key(void) +{ + cl_git_pass(git_strmap_set(g_table, "foo", "oof")); + cl_git_pass(git_strmap_set(g_table, "bar", "rab")); + cl_git_pass(git_strmap_set(g_table, "gobble", "elbbog")); + cl_assert_equal_i(git_strmap_size(g_table), 3); + + cl_git_pass(git_strmap_set(g_table, "foo", "other")); + cl_assert_equal_i(git_strmap_size(g_table), 3); + + cl_assert_equal_s(git_strmap_get(g_table, "foo"), "other"); +} |
