Skip to content

Commit 84241ea

Browse files
committed
Tests: Add a test for HashTable<NonTrivial>::clear_with_capacity()
1 parent 744568c commit 84241ea

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tests/AK/TestHashTable.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,30 @@ TEST_CASE(clear_with_capacity_when_empty)
349349
VERIFY(map.size() == 2);
350350
}
351351

352+
struct NonTrivial {
353+
~NonTrivial() { }
354+
bool operator==(NonTrivial const&) const { return true; }
355+
};
356+
357+
namespace AK {
358+
359+
template<>
360+
struct Traits<NonTrivial> : public DefaultTraits<NonTrivial> {
361+
static unsigned hash(NonTrivial const&) { return 0; }
362+
};
363+
364+
}
365+
366+
TEST_CASE(clear_with_capacity_with_non_trivial_type)
367+
{
368+
static_assert(!IsTriviallyDestructible<NonTrivial>);
369+
370+
HashTable<NonTrivial> map;
371+
map.set({});
372+
map.clear_with_capacity();
373+
VERIFY(map.size() == 0);
374+
}
375+
352376
TEST_CASE(iterator_removal)
353377
{
354378
HashTable<int> map;

0 commit comments

Comments
 (0)