[core] Add str_contains_ignore_case_p for PROGMEM needle strings

This commit is contained in:
J. Nick Koston
2026-08-20 17:34:39 -05:00
parent 46f90d0c54
commit f3a7b4795b
3 changed files with 47 additions and 0 deletions
+20
View File
@@ -129,4 +129,24 @@ TEST(StringContainsIgnoreCaseTest, FallbackMatchesLibc) {
EXPECT_EQ(str_contains_ignore_case_fallback("ab", "abc"), str_contains_ignore_case("ab", "abc"));
}
TEST(StringContainsIgnoreCaseTest, ProgmemVariantNullPointerAlwaysFalse) {
const char *haystack = nullptr;
const char *needle = nullptr;
EXPECT_FALSE(str_contains_ignore_case_p(haystack, needle));
EXPECT_FALSE(str_contains_ignore_case_p("Hello World", needle));
EXPECT_FALSE(str_contains_ignore_case_p(haystack, "anything"));
}
TEST(StringContainsIgnoreCaseTest, ProgmemVariantMatchesFallback) {
const char *haystack = "Hello World";
for (const char *needle : {"", "Hello", "hELLO", "HELLO", "Hell", "world", "World", "Heaven", "Hello!", "d"}) {
EXPECT_EQ(str_contains_ignore_case_p(haystack, needle), str_contains_ignore_case_fallback(haystack, needle))
<< "needle: " << needle;
}
EXPECT_TRUE(str_contains_ignore_case_p("", ""));
EXPECT_FALSE(str_contains_ignore_case_p("", "a"));
EXPECT_FALSE(str_contains_ignore_case_p("ab", "abc"));
}
} // namespace esphome