AK+Tests: Make CaseInsensitiveStringViewTraits work with HashMap again

This commit is contained in:
Ben Wiederhake 2023-01-09 18:51:21 +01:00 committed by Andrew Kaster
parent 822e32eb11
commit 79b9dd6248
Notes: sideshowbarker 2024-07-17 01:42:39 +09:00
2 changed files with 9 additions and 0 deletions

View file

@ -348,6 +348,7 @@ struct CaseInsensitiveStringViewTraits : public Traits<StringView> {
return 0;
return case_insensitive_string_hash(s.characters_without_null_termination(), s.length());
}
static bool equals(StringView const& a, StringView const& b) { return a.equals_ignoring_case(b); }
};
}

View file

@ -108,6 +108,14 @@ TEST_CASE(case_insensitive)
EXPECT_EQ(casemap.size(), 1u);
}
TEST_CASE(case_insensitive_stringview)
{
HashMap<StringView, int, CaseInsensitiveStringViewTraits> casemap;
EXPECT_EQ(casemap.set("nickserv"sv, 3), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(casemap.set("NickServ"sv, 3), AK::HashSetResult::ReplacedExistingEntry);
EXPECT_EQ(casemap.size(), 1u);
}
TEST_CASE(hashmap_of_nonnullownptr_get)
{
struct Object {