Skip to content

Commit 5a4d6e7

Browse files
committed
[WTF] Fix behavioral issues in searching in spans
https://bugs.webkit.org/show_bug.cgi?id=302925 Reviewed by Darin Adler. There were several cases where we were not handling properly certain cases when inspecting spans for data and some codepaths that had different behaviors. Fixed them and improved test coverage. reverseFind lost the starting offset that was not used anywhere and for coherence with the find counterpart. Test: Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp * Source/WTF/wtf/StdLibExtras.h: (WTF::find): * Source/WTF/wtf/text/StringCommon.h: (WTF::findIgnoringASCIICase): (WTF::reverseFindInner): (WTF::reverseFind): * Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp: (TestWebKitAPI::TEST(WTF_StringCommon, Equal)): (TestWebKitAPI::TEST(WTF_StringCommon, EqualIgnoringASCIICase)): (TestWebKitAPI::TEST(WTF_StringCommon, StartsWith)): (TestWebKitAPI::TEST(WTF_StringCommon, EndsWith)): (TestWebKitAPI::TEST(WTF_StringCommon, Find)): (TestWebKitAPI::TEST(WTF_StringCommon, ReverseFind)): (TestWebKitAPI::TEST(WTF_StringCommon, Contains)): (TestWebKitAPI::TEST(WTF_StringCommon, StartsWithLettersIgnoringASCIICase)): (TestWebKitAPI::TEST(WTF_StringCommon, EndsWithLettersIgnoringASCIICase)): (TestWebKitAPI::TEST(WTF_StringCommon, FindIgnoringASCIICase)): (TestWebKitAPI::TEST(WTF_StringCommon, ContainsIgnoringASCIICase)): (TestWebKitAPI::TEST(WTF_StringCommon, CharactersAreAllASCII)): Canonical link: https://commits.webkit.org/303965@main
1 parent baeb417 commit 5a4d6e7

3 files changed

Lines changed: 122 additions & 17 deletions

File tree

Source/WTF/wtf/StdLibExtras.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,10 @@ template<typename T, std::size_t TExtent, typename U, std::size_t UExtent>
794794
requires(TriviallyComparableOneByteCodeUnits<T, U>)
795795
size_t find(std::span<T, TExtent> haystack, std::span<U, UExtent> needle)
796796
{
797-
#if !HAVE(MEMMEM)
798797
if (needle.empty())
799798
return 0;
800799

800+
#if !HAVE(MEMMEM)
801801
if (haystack.size() < needle.size())
802802
return notFound;
803803

Source/WTF/wtf/text/StringCommon.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,9 @@ template<typename SearchCharacterType, typename MatchCharacterType>
482482
requires(TriviallyComparableCodeUnits<SearchCharacterType, MatchCharacterType>)
483483
size_t findIgnoringASCIICase(std::span<const SearchCharacterType> source, std::span<const MatchCharacterType> matchCharacters, size_t startOffset = 0)
484484
{
485-
ASSERT(source.size() >= matchCharacters.size());
486-
487-
auto startSearchedCharacters = source.subspan(startOffset);
488-
489-
// delta is the number of additional times to test; delta == 0 means test only once.
490-
size_t delta = startSearchedCharacters.size() - matchCharacters.size();
491-
492-
for (size_t i = 0; i <= delta; ++i) {
493-
if (equalIgnoringASCIICaseWithLength(startSearchedCharacters.subspan(i), matchCharacters, matchCharacters.size()))
494-
return startOffset + i;
485+
for (size_t offset = startOffset; offset <= source.size() && source.size() - offset >= matchCharacters.size(); ++offset) {
486+
if (equalIgnoringASCIICaseWithLength(source.subspan(offset), matchCharacters, matchCharacters.size()))
487+
return offset;
495488
}
496489
return notFound;
497490
}
@@ -791,6 +784,9 @@ inline bool contains(std::span<const CharacterType> characters, ASCIILiteral mat
791784
template <typename SearchCharacterType, typename MatchCharacterType>
792785
ALWAYS_INLINE static size_t reverseFindInner(std::span<const SearchCharacterType> searchCharacters, std::span<const MatchCharacterType> matchCharacters, size_t start)
793786
{
787+
if (searchCharacters.size() < matchCharacters.size())
788+
return notFound;
789+
794790
// Optimization: keep a running hash of the strings,
795791
// only call equal if the hashes match.
796792

@@ -817,9 +813,9 @@ ALWAYS_INLINE static size_t reverseFindInner(std::span<const SearchCharacterType
817813

818814
template<typename SearchCharacterType, typename MatchCharacterType>
819815
requires(TriviallyComparableCodeUnits<SearchCharacterType, MatchCharacterType>)
820-
ALWAYS_INLINE static size_t reverseFind(std::span<const SearchCharacterType> searchCharacters, std::span<const MatchCharacterType> matchCharacters, size_t start = std::numeric_limits<size_t>::max())
816+
ALWAYS_INLINE static size_t reverseFind(std::span<const SearchCharacterType> searchCharacters, std::span<const MatchCharacterType> matchCharacters)
821817
{
822-
return reverseFindInner(searchCharacters, matchCharacters, start);
818+
return reverseFindInner(searchCharacters, matchCharacters, std::numeric_limits<size_t>::max());
823819
}
824820

825821
template<OneByteCharacterType CharacterType>

Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ TEST(WTF_StringCommon, Equal)
111111
{
112112
EXPECT_TRUE(WTF::equal(u8"Water🍉Melon"_span, u8"Water🍉Melon"_span));
113113
EXPECT_FALSE(WTF::equal(u8"Water🍉Melon"_span, u8"🍉WaterMelon🍉"_span));
114+
EXPECT_TRUE(WTF::equal(std::span<const char8_t>(), std::span<const char8_t>()));
115+
EXPECT_TRUE(WTF::equal(std::span<const char8_t>(), u8""_span));
116+
EXPECT_FALSE(WTF::equal(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span));
117+
EXPECT_TRUE(WTF::equal(u8""_span, std::span<const char8_t>()));
118+
EXPECT_FALSE(WTF::equal(u8""_span, u8"🍉WaterMelon🍉"_span));
119+
EXPECT_FALSE(WTF::equal(u8"🍉"_span, std::span<const char8_t>()));
120+
EXPECT_FALSE(WTF::equal(u8"Water🍉Melon"_span, std::span<const char8_t>()));
121+
EXPECT_FALSE(WTF::equal(u8"Water🍉Melon"_span, u8""_span));
114122
// EXPECT_TRUE(WTF::equal("test"_span, "test"_span8)); // This should not compile.
115123
String string(u8"Water🍉Melon"_span);
116124
EXPECT_FALSE(string.is8Bit());
@@ -122,6 +130,15 @@ TEST(WTF_StringCommon, EqualIgnoringASCIICase)
122130
{
123131
EXPECT_TRUE(WTF::equalIgnoringASCIICase(u8"Test"_span, u8"test"_span));
124132
EXPECT_FALSE(WTF::equalIgnoringASCIICase(u8"another test"_span, u8"test"_span));
133+
EXPECT_TRUE(WTF::equalIgnoringASCIICase(std::span<const char8_t>(), std::span<const char8_t>()));
134+
EXPECT_TRUE(WTF::equalIgnoringASCIICase(std::span<const char8_t>(), u8""_span));
135+
EXPECT_TRUE(WTF::equalIgnoringASCIICase(u8""_span, std::span<const char8_t>()));
136+
EXPECT_FALSE(WTF::equalIgnoringASCIICase(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span));
137+
EXPECT_FALSE(WTF::equalIgnoringASCIICase(u8""_span, u8"🍉WaterMelon🍉"_span));
138+
EXPECT_FALSE(WTF::equalIgnoringASCIICase(u8"🍉"_span, std::span<const char8_t>()));
139+
EXPECT_TRUE(WTF::equalIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8"🍉WaterMelon🍉"_span));
140+
EXPECT_FALSE(WTF::equalIgnoringASCIICase(u8"🍉Watermelon🍉"_span, std::span<const char8_t>()));
141+
EXPECT_FALSE(WTF::equalIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8""_span));
125142
// EXPECT_TRUE(WTF::equalIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile.
126143
}
127144

@@ -132,6 +149,16 @@ TEST(WTF_StringCommon, StartsWith)
132149
EXPECT_FALSE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, "Water"_s));
133150
EXPECT_TRUE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, u8"🍉"_span));
134151
EXPECT_FALSE(WTF::startsWith(u8"Water🍉Melon"_span, u8"🍉"_span));
152+
EXPECT_TRUE(WTF::startsWith(std::span<const char8_t>(), std::span<const char8_t>()));
153+
EXPECT_TRUE(WTF::startsWith(std::span<const char8_t>(), u8""_span));
154+
EXPECT_FALSE(WTF::startsWith(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span));
155+
EXPECT_TRUE(WTF::startsWith(u8""_span, std::span<const char8_t>()));
156+
EXPECT_FALSE(WTF::startsWith(u8""_span, u8"🍉WaterMelon🍉"_span));
157+
EXPECT_TRUE(WTF::startsWith(u8"🍉"_span, std::span<const char8_t>()));
158+
EXPECT_FALSE(WTF::startsWith(u8"🍉"_span, u8"🍉WaterMelon🍉"_span));
159+
EXPECT_TRUE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, u8"🍉WaterMelon🍉"_span));
160+
EXPECT_TRUE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()));
161+
EXPECT_TRUE(WTF::startsWith(u8"🍉WaterMelon🍉"_span, u8""_span));
135162
// EXPECT_TRUE(WTF::startsWith(u8"test"_span, "test"_span8)); // This should not compile.
136163
}
137164

@@ -142,6 +169,16 @@ TEST(WTF_StringCommon, EndsWith)
142169
EXPECT_FALSE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, "Melon"_s));
143170
EXPECT_TRUE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, u8"🍉"_span));
144171
EXPECT_FALSE(WTF::endsWith(u8"Water🍉Melon"_span, u8"🍉"_span));
172+
EXPECT_TRUE(WTF::endsWith(std::span<const char8_t>(), std::span<const char8_t>()));
173+
EXPECT_TRUE(WTF::endsWith(std::span<const char8_t>(), u8""_span));
174+
EXPECT_FALSE(WTF::endsWith(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span));
175+
EXPECT_TRUE(WTF::endsWith(u8""_span, std::span<const char8_t>()));
176+
EXPECT_FALSE(WTF::endsWith(u8""_span, u8"🍉WaterMelon🍉"_span));
177+
EXPECT_TRUE(WTF::endsWith(u8"🍉"_span, std::span<const char8_t>()));
178+
EXPECT_FALSE(WTF::endsWith(u8"🍉"_span, u8"🍉WaterMelon🍉"_span));
179+
EXPECT_TRUE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, u8"🍉WaterMelon🍉"_span));
180+
EXPECT_TRUE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()));
181+
EXPECT_TRUE(WTF::endsWith(u8"🍉WaterMelon🍉"_span, u8""_span));
145182
// EXPECT_TRUE(WTF::endsWith(u8"test"_span, "test"_span8)); // This should not compile.
146183
}
147184

@@ -151,7 +188,17 @@ TEST(WTF_StringCommon, Find)
151188
EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, "ter"_s), 6UZ);
152189
EXPECT_EQ(WTF::find(u8"Water🍉Melon"_span, u8"🍉"_span), 5UZ);
153190
EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, u8"🍉"_span), 0UZ);
154-
// EXPECT_NEQ(WTF::find(u8"test"_span, "test"_span8), notFound); // This should not compile.
191+
EXPECT_EQ(WTF::find(std::span<const char8_t>(), std::span<const char8_t>()), 0UZ);
192+
EXPECT_EQ(WTF::find(std::span<const char8_t>(), u8""_span), 0UZ);
193+
EXPECT_EQ(WTF::find(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span), notFound);
194+
EXPECT_EQ(WTF::find(u8""_span, std::span<const char8_t>()), 0UZ);
195+
EXPECT_EQ(WTF::find(u8""_span, u8"🍉WaterMelon🍉"_span), notFound);
196+
EXPECT_EQ(WTF::find(u8"🍉"_span, std::span<const char8_t>()), 0UZ);
197+
EXPECT_EQ(WTF::find(u8"🍉"_span, u8"🍉WaterMelon🍉"_span), notFound);
198+
EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, u8"🍉WaterMelon🍉"_span), 0UZ);
199+
EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()), 0UZ);
200+
EXPECT_EQ(WTF::find(u8"🍉WaterMelon🍉"_span, u8""_span), 0UZ);
201+
// EXPECT_NE(WTF::find(u8"test"_span, "test"_span8), notFound); // This should not compile.
155202
}
156203

157204
TEST(WTF_StringCommon, ReverseFind)
@@ -160,7 +207,17 @@ TEST(WTF_StringCommon, ReverseFind)
160207
EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, "ter"_s), 6UZ);
161208
EXPECT_EQ(WTF::reverseFind(u8"Water🍉Melon"_span, u8"🍉"_span), 5UZ);
162209
EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, u8"🍉"_span), 14UZ);
163-
// EXPECT_NEQ(WTF::reverseFind(u8"test"_span, "test"_span8), notFound); // This should not compile.
210+
EXPECT_EQ(WTF::reverseFind(std::span<const char8_t>(), std::span<const char8_t>()), 0UZ);
211+
EXPECT_EQ(WTF::reverseFind(std::span<const char8_t>(), u8""_span), 0UZ);
212+
EXPECT_EQ(WTF::reverseFind(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span), notFound);
213+
EXPECT_EQ(WTF::reverseFind(u8""_span, std::span<const char8_t>()), 0UZ);
214+
EXPECT_EQ(WTF::reverseFind(u8""_span, u8"🍉WaterMelon🍉"_span), notFound);
215+
EXPECT_EQ(WTF::reverseFind(u8"🍉"_span, std::span<const char8_t>()), 4UZ);
216+
EXPECT_EQ(WTF::reverseFind(u8"🍉"_span, u8"🍉WaterMelon🍉"_span), notFound);
217+
EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, u8"🍉WaterMelon🍉"_span), 0UZ);
218+
EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()), 18UZ);
219+
EXPECT_EQ(WTF::reverseFind(u8"🍉WaterMelon🍉"_span, u8""_span), 18UZ);
220+
// EXPECT_NE(WTF::reverseFind(u8"test"_span, "test"_span8), notFound); // This should not compile.
164221
}
165222

166223
TEST(WTF_StringCommon, Contains)
@@ -173,20 +230,50 @@ TEST(WTF_StringCommon, Contains)
173230
EXPECT_FALSE(WTF::contains(u8"🍉WaterMelon🍉"_span, "pear"_s));
174231
EXPECT_FALSE(WTF::contains(u8"Water🍉Melon"_span, u8"🍈"_span));
175232
EXPECT_FALSE(WTF::contains(u8"🍉WaterMelon🍉"_span, u8"🍈"_span));
233+
EXPECT_TRUE(WTF::contains(std::span<const char8_t>(), std::span<const char8_t>()));
234+
EXPECT_TRUE(WTF::contains(std::span<const char8_t>(), u8""_span));
235+
EXPECT_FALSE(WTF::contains(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span));
236+
EXPECT_TRUE(WTF::contains(u8""_span, std::span<const char8_t>()));
237+
EXPECT_FALSE(WTF::contains(u8""_span, u8"🍉WaterMelon🍉"_span));
238+
EXPECT_TRUE(WTF::contains(u8"🍉"_span, std::span<const char8_t>()));
239+
EXPECT_FALSE(WTF::contains(u8"🍉"_span, u8"🍉WaterMelon🍉"_span));
240+
EXPECT_TRUE(WTF::contains(u8"🍉WaterMelon🍉"_span, u8"🍉WaterMelon🍉"_span));
241+
EXPECT_TRUE(WTF::contains(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()));
242+
EXPECT_TRUE(WTF::contains(u8"🍉WaterMelon🍉"_span, u8""_span));
176243
// EXPECT_TRUE(WTF::contains(u8"test"_span, "test"_span8)); // This should not compile.
177244
}
178245

179246
TEST(WTF_StringCommon, StartsWithLettersIgnoringASCIICase)
180247
{
181248
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"Water🍉Melon"_span, "water"_s));
182249
EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "water"_s));
250+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(std::span<const char8_t>(), std::span<const char8_t>()));
251+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(std::span<const char8_t>(), u8""_span));
252+
EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(std::span<const char8_t>(), u8"watermelon"_span));
253+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8""_span, std::span<const char8_t>()));
254+
EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(u8""_span, u8"watermelon"_span));
255+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"Water"_span, std::span<const char8_t>()));
256+
EXPECT_FALSE(WTF::startsWithLettersIgnoringASCIICase(u8"Water"_span, u8"watermelon"_span));
257+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"WaterMelon"_span, u8"watermelon"_span));
258+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()));
259+
EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, u8""_span));
183260
// EXPECT_TRUE(WTF::startsWithLettersIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile.
184261
}
185262

186263
TEST(WTF_StringCommon, EndsWithLettersIgnoringASCIICase)
187264
{
188265
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"Water🍉Melon"_span, "melon"_s));
189266
EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "melon"_s));
267+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(std::span<const char8_t>(), std::span<const char8_t>()));
268+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(std::span<const char8_t>(), u8""_span));
269+
EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(std::span<const char8_t>(), u8"watermelon"_span));
270+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8""_span, std::span<const char8_t>()));
271+
EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(u8""_span, u8"watermelon"_span));
272+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"Water"_span, std::span<const char8_t>()));
273+
EXPECT_FALSE(WTF::endsWithLettersIgnoringASCIICase(u8"Water"_span, u8"watermelon"_span));
274+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"WaterMelon"_span, u8"watermelon"_span));
275+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, std::span<const char8_t>()));
276+
EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, u8""_span));
190277
// EXPECT_TRUE(WTF::endsWithLettersIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile.
191278
}
192279

@@ -196,7 +283,18 @@ TEST(WTF_StringCommon, FindIgnoringASCIICase)
196283
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "water"_s), 4UZ);
197284
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"Water🍉Melon"_span, u8"🍉"_span), 5UZ);
198285
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, u8"🍉"_span), 0UZ);
199-
// EXPECT_NEQ(WTF::findIgnoringASCIICase(u8"test"_span, "test"_span8), notFound); // This should not compile.
286+
EXPECT_EQ(WTF::findIgnoringASCIICase(std::span<const char8_t>(), std::span<const char8_t>()), 0UZ);
287+
EXPECT_EQ(WTF::findIgnoringASCIICase(std::span<const char8_t>(), u8""_span), 0UZ);
288+
EXPECT_EQ(WTF::findIgnoringASCIICase(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span), notFound);
289+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8""_span, std::span<const char8_t>()), 0UZ);
290+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8""_span, u8"🍉WaterMelon🍉"_span), notFound);
291+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉"_span, std::span<const char8_t>()), 0UZ);
292+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉"_span, u8"🍉WaterMelon🍉"_span), notFound);
293+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8"🍉WaterMelon🍉"_span), 0UZ);
294+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8"🍉WaterMelon🍉"_span, 5UZ), notFound);
295+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉Watermelon🍉"_span, std::span<const char8_t>()), 0UZ);
296+
EXPECT_EQ(WTF::findIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8""_span), 0UZ);
297+
// EXPECT_NE(WTF::findIgnoringASCIICase(u8"test"_span, "test"_span8), notFound); // This should not compile.
200298
}
201299

202300
TEST(WTF_StringCommon, ContainsIgnoringASCIICase)
@@ -205,14 +303,25 @@ TEST(WTF_StringCommon, ContainsIgnoringASCIICase)
205303
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, "melon"_s));
206304
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"Water🍉Melon"_span, u8"🍉"_span));
207305
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉WaterMelon🍉"_span, u8"🍉"_span));
306+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(std::span<const char8_t>(), std::span<const char8_t>()));
307+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(std::span<const char8_t>(), u8""_span));
308+
EXPECT_FALSE(WTF::containsIgnoringASCIICase(std::span<const char8_t>(), u8"🍉WaterMelon🍉"_span));
309+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8""_span, std::span<const char8_t>()));
310+
EXPECT_FALSE(WTF::containsIgnoringASCIICase(u8""_span, u8"🍉WaterMelon🍉"_span));
311+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉"_span, std::span<const char8_t>()));
312+
EXPECT_FALSE(WTF::containsIgnoringASCIICase(u8"🍉"_span, u8"🍉WaterMelon🍉"_span));
313+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8"🍉WaterMelon🍉"_span));
314+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉Watermelon🍉"_span, std::span<const char8_t>()));
315+
EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"🍉Watermelon🍉"_span, u8""_span));
208316
// EXPECT_TRUE(WTF::containsIgnoringASCIICase(u8"test"_span, "test"_span8)); // This should not compile.
209317
}
210318

211319
TEST(WTF_StringCommon, CharactersAreAllASCII)
212320
{
213321
EXPECT_TRUE(WTF::charactersAreAllASCII(u8"Test"_span));
214-
EXPECT_TRUE(WTF::charactersAreAllASCII(std::span<const char8_t>()));
215322
EXPECT_FALSE(WTF::charactersAreAllASCII(u8"🍉"_span));
323+
EXPECT_TRUE(WTF::charactersAreAllASCII(std::span<const char8_t>()));
324+
EXPECT_TRUE(WTF::charactersAreAllASCII(u8""_span));
216325
}
217326

218327
TEST(WTF_StringCommon, CopyElements64To8)

0 commit comments

Comments
 (0)