mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Ensure string types are actually considered hash-compatible
The AnyString concept is currently broken because it checks whether a StringView is constructible from a type T. The StringView constructors, however, only accept constant rvalue references - i.e. `T const&`. This also adds a test to ensure this continues to work.
This commit is contained in:
parent
2f67f2ba3d
commit
f31bd190b0
Notes:
sideshowbarker
2024-07-17 00:52:09 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/f31bd190b0 Pull-request: https://github.com/SerenityOS/serenity/pull/17276
2 changed files with 25 additions and 1 deletions
|
@ -49,7 +49,7 @@ template<typename T, typename S>
|
|||
concept DerivedFrom = IsBaseOf<S, T>;
|
||||
|
||||
template<typename T>
|
||||
concept AnyString = IsConstructible<StringView, T>;
|
||||
concept AnyString = IsConstructible<StringView, RemoveCVReference<T> const&>;
|
||||
|
||||
template<typename T, typename U>
|
||||
concept HashCompatible = IsHashCompatible<Detail::Decay<T>, Detail::Decay<U>>;
|
||||
|
|
|
@ -6,9 +6,33 @@
|
|||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
TEST_CASE(hash_compatible)
|
||||
{
|
||||
static_assert(AK::Concepts::HashCompatible<String, StringView>);
|
||||
static_assert(AK::Concepts::HashCompatible<String, FlyString>);
|
||||
static_assert(AK::Concepts::HashCompatible<StringView, String>);
|
||||
static_assert(AK::Concepts::HashCompatible<StringView, FlyString>);
|
||||
static_assert(AK::Concepts::HashCompatible<FlyString, String>);
|
||||
static_assert(AK::Concepts::HashCompatible<FlyString, StringView>);
|
||||
|
||||
static_assert(AK::Concepts::HashCompatible<DeprecatedString, StringView>);
|
||||
static_assert(AK::Concepts::HashCompatible<DeprecatedString, DeprecatedFlyString>);
|
||||
static_assert(AK::Concepts::HashCompatible<StringView, DeprecatedString>);
|
||||
static_assert(AK::Concepts::HashCompatible<StringView, DeprecatedFlyString>);
|
||||
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, DeprecatedString>);
|
||||
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, StringView>);
|
||||
|
||||
static_assert(AK::Concepts::HashCompatible<StringView, ByteBuffer>);
|
||||
static_assert(AK::Concepts::HashCompatible<ByteBuffer, StringView>);
|
||||
}
|
||||
|
||||
TEST_CASE(matches_null)
|
||||
{
|
||||
EXPECT(AK::StringUtils::matches(StringView(), StringView()));
|
||||
|
|
Loading…
Reference in a new issue