tests/test_kv_list.c

changeset 1377
1562bdf948da
parent 1375
e0ba5e20e77a
child 1378
1b4fa55f7caa
--- a/tests/test_kv_list.c	Tue Sep 16 22:32:23 2025 +0200
+++ b/tests/test_kv_list.c	Wed Sep 17 22:45:00 2025 +0200
@@ -350,6 +350,42 @@
     cxListFree(list);
 }
 
+CX_TEST(test_kv_list_remove_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);
+
+        int *y = cxMapGet(map, "abc");
+        CX_TEST_ASSERT(y != NULL);
+        CX_TEST_ASSERT(*y == 11);
+
+        cxKvListRemoveKey(list, 1);
+        CX_TEST_ASSERT(cxMapGet(map, "abc") == NULL);
+        CX_TEST_ASSERT(cxMapSize(map) == 2);
+        CX_TEST_ASSERT(cxListSize(list) == 3);
+
+        CX_TEST_ASSERT(*(int*)cxListAt(list, 1) == 11);
+
+        y = cxMapGet(map, "xyz");
+        CX_TEST_ASSERT(y != NULL);
+        CX_TEST_ASSERT(*y == 47);
+
+        y = cxMapGet(map, "efg");
+        CX_TEST_ASSERT(y != NULL);
+        CX_TEST_ASSERT(*y == 1337);
+    }
+    cxListFree(list);
+}
+
 CX_TEST(test_kv_list_insert_array_and_set_keys) {
     CxList *list = cxKvListCreateSimple(sizeof(int));
     CX_TEST_DO {
@@ -533,6 +569,7 @@
     cx_test_register(suite, test_kv_list_map_put_ptr);
     cx_test_register(suite, test_kv_list_map_remove);
     cx_test_register(suite, test_kv_list_set_key);
+    cx_test_register(suite, test_kv_list_remove_key);
     cx_test_register(suite, test_kv_list_insert_array_and_set_keys);
     cx_test_register(suite, test_kv_list_list_remove_destr_in_list);
     cx_test_register(suite, test_kv_list_list_remove_destr_in_map);

mercurial