diff -r ea9b41b5ebbc -r d90cfa6721f9 test/test_map.cpp --- a/test/test_map.cpp Sun Oct 23 13:32:46 2022 +0200 +++ b/test/test_map.cpp Sun Oct 23 13:39:44 2022 +0200 @@ -249,4 +249,32 @@ cxMapDestroy(map); EXPECT_TRUE(allocator.verify()); +} + +TEST(CxHashMap, Clear) { + CxTestingAllocator allocator; + auto map = cxHashMapCreate(&allocator, 0); + auto hmap = reinterpret_cast(map); + EXPECT_GT(hmap->bucket_count, 0); + cx_for_n(i, hmap->bucket_count) { + EXPECT_EQ(hmap->buckets[i], nullptr); + } + EXPECT_EQ(map->size, 0); + EXPECT_EQ(map->allocator, &allocator); + + cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); + cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); + cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); + + EXPECT_EQ(map->size, 3); + + cxMapClear(map); + + EXPECT_EQ(map->size, 0); + EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 1")), nullptr); + EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 2")), nullptr); + EXPECT_EQ(cxMapGet(map, cx_hash_key_str("key 3")), nullptr); + + cxMapDestroy(map); + EXPECT_TRUE(allocator.verify()); } \ No newline at end of file