mirror of
https://github.com/esphome/esphome.git
synced 2026-10-03 09:46:03 +00:00
[core] Add str_contains_ignore_case_p for PROGMEM needle strings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user