mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:37:34 +00:00
AK: Move the wildcard-matching implementation to StringUtils
Provide wrappers in the String and StringView classes, and add some tests.
This commit is contained in:
parent
2a30a020c1
commit
055344f346
16 changed files with 147 additions and 62 deletions
|
@ -3,6 +3,7 @@ SHARED_TEST_SOURCES = \
|
|||
../StringImpl.cpp \
|
||||
../StringBuilder.cpp \
|
||||
../StringView.cpp \
|
||||
../StringUtils.cpp \
|
||||
../LogStream.cpp \
|
||||
../JsonValue.cpp \
|
||||
../JsonParser.cpp \
|
||||
|
|
44
AK/Tests/TestStringUtils.cpp
Normal file
44
AK/Tests/TestStringUtils.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <AK/StringUtils.h>
|
||||
#include <AK/TestSuite.h>
|
||||
|
||||
TEST_CASE(matches_null)
|
||||
{
|
||||
EXPECT(AK::StringUtils::matches(StringView(), StringView()));
|
||||
|
||||
EXPECT(!AK::StringUtils::matches(StringView(), ""));
|
||||
EXPECT(!AK::StringUtils::matches(StringView(), "*"));
|
||||
EXPECT(!AK::StringUtils::matches(StringView(), "?"));
|
||||
EXPECT(!AK::StringUtils::matches(StringView(), "a"));
|
||||
|
||||
EXPECT(!AK::StringUtils::matches("", StringView()));
|
||||
EXPECT(!AK::StringUtils::matches("a", StringView()));
|
||||
}
|
||||
|
||||
TEST_CASE(matches_empty)
|
||||
{
|
||||
EXPECT(AK::StringUtils::matches("", ""));
|
||||
|
||||
EXPECT(AK::StringUtils::matches("", "*"));
|
||||
EXPECT(!AK::StringUtils::matches("", "?"));
|
||||
EXPECT(!AK::StringUtils::matches("", "a"));
|
||||
|
||||
EXPECT(!AK::StringUtils::matches("a", ""));
|
||||
}
|
||||
|
||||
TEST_CASE(matches_case_sensitive)
|
||||
{
|
||||
EXPECT(AK::StringUtils::matches("a", "a", CaseSensitivity::CaseSensitive));
|
||||
EXPECT(!AK::StringUtils::matches("a", "A", CaseSensitivity::CaseSensitive));
|
||||
EXPECT(!AK::StringUtils::matches("A", "a", CaseSensitivity::CaseSensitive));
|
||||
}
|
||||
|
||||
TEST_CASE(matches_case_insensitive)
|
||||
{
|
||||
EXPECT(!AK::StringUtils::matches("aa", "a"));
|
||||
EXPECT(AK::StringUtils::matches("aa", "*"));
|
||||
EXPECT(!AK::StringUtils::matches("cb", "?a"));
|
||||
EXPECT(AK::StringUtils::matches("adceb", "a*b"));
|
||||
EXPECT(!AK::StringUtils::matches("acdcb", "a*c?b"));
|
||||
}
|
||||
|
||||
TEST_MAIN(StringUtils)
|
Loading…
Add table
Add a link
Reference in a new issue