summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-18 18:02:07 +0000
committerLinus Groh <mail@linusgroh.de>2022-03-18 23:51:56 +0000
commit7e98c8eaf66698fb28a8c3ac825559ce380c1624 (patch)
tree3d5deece68042fff9e2369c3808002c32e3aff6c /Tests
parent00eca260858ee9a9327476409a89ff03499c3b8a (diff)
downloadserenity-7e98c8eaf66698fb28a8c3ac825559ce380c1624.zip
AK+Tests: Fix StringUtils::contains() being confused by repeating text
Previously, case-insensitively searching the haystack "Go Go Back" for the needle "Go Back" would return false: 1. Match the first three characters. "Go ". 2. Notice that 'G' and 'B' don't match. 3. Skip ahead 3 characters, plus 1 for the outer for-loop. 4. Now, the haystack is effectively "o Back", so the match fails. Reducing the skip by 1 fixes this issue. I'm not 100% convinced this fixes all cases, but I haven't been able to find any cases where it doesn't work now. :^)
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/TestStringUtils.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/Tests/AK/TestStringUtils.cpp b/Tests/AK/TestStringUtils.cpp
index bff9aa5dcd..b82a73886d 100644
--- a/Tests/AK/TestStringUtils.cpp
+++ b/Tests/AK/TestStringUtils.cpp
@@ -321,6 +321,10 @@ TEST_CASE(contains)
EXPECT(!AK::StringUtils::contains("", test_string, CaseSensitivity::CaseInsensitive));
EXPECT(!AK::StringUtils::contains(test_string, "L", CaseSensitivity::CaseSensitive));
EXPECT(!AK::StringUtils::contains(test_string, "L", CaseSensitivity::CaseInsensitive));
+
+ String command_palette_bug_string = "Go Go Back";
+ EXPECT(AK::StringUtils::contains(command_palette_bug_string, "Go Back", AK::CaseSensitivity::CaseSensitive));
+ EXPECT(AK::StringUtils::contains(command_palette_bug_string, "gO bAcK", AK::CaseSensitivity::CaseInsensitive));
}
TEST_CASE(is_whitespace)