diff -r 461d256e32c6 -r 7b23c6db9500 tests/test_kv_list.c --- a/tests/test_kv_list.c Wed Sep 24 23:52:36 2025 +0200 +++ b/tests/test_kv_list.c Thu Sep 25 14:30:28 2025 +0200 @@ -542,6 +542,40 @@ cxListFree(list); } +CX_TEST(test_kv_list_get_key) { + CxList *list = cxKvListCreateSimple(sizeof(int)); + int x; + CX_TEST_DO { + CxMap *map = cxKvListAsMap(list); + + x = 47; + cxMapPut(map, "xyz", &x); + x = 11; + cxMapPut(map, "abc", &x); + x = 1337; + cxMapPut(map, "efg", &x); + CX_TEST_ASSERT(cxMapSize(map) == 3); + + const CxHashKey *key = cxKvListGetKey(list, 1); + int *y = cxMapGet(map, *key); + CX_TEST_ASSERT(y != NULL); + CX_TEST_ASSERT(*y == 11); + + // removing the element + CX_TEST_ASSERT(0 == cxMapRemove(map, cx_strn(key->data, key->len))); + key = cxKvListGetKey(list, 1); + CX_TEST_ASSERT(0 == cx_strcmp(CX_STR("efg"), cx_strn(key->data, key->len))); + + // remove the key of element + CX_TEST_ASSERT(0 == cxKvListRemoveKey(list, 1)); + CX_TEST_ASSERT(NULL == cxKvListGetKey(list, 1)); + + // index out of bounds: + CX_TEST_ASSERT(NULL == cxKvListGetKey(list, 3)); + } + cxListFree(list); +} + CX_TEST(test_kv_list_insert_with_key) { CxList *list = cxKvListCreateSimple(sizeof(int)); int x; @@ -993,6 +1027,7 @@ cx_test_register(suite, test_kv_list_set_key_already_exists); cx_test_register(suite, test_kv_list_set_key_again); cx_test_register(suite, test_kv_list_remove_key); + cx_test_register(suite, test_kv_list_get_key); cx_test_register(suite, test_kv_list_insert_with_key); cx_test_register(suite, test_kv_list_insert_ptr_with_key); cx_test_register(suite, test_kv_list_insert_array_and_set_keys);