From 0920daf2511d0a44b581712af2c1798a7646c49a Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 10 Jun 2019 12:51:43 -0700 Subject: [PATCH] Add some more CI tests for String::replace (#6193) --- tests/host/core/test_string.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/host/core/test_string.cpp b/tests/host/core/test_string.cpp index a6488ee6e..93dc85e46 100644 --- a/tests/host/core/test_string.cpp +++ b/tests/host/core/test_string.cpp @@ -494,3 +494,21 @@ TEST_CASE("Strings with NULs", "[core][String]") const char *p = str3.c_str(); REQUIRE(!memcmp(p, zeros, 64)); } + +TEST_CASE("Replace and string expansion", "[core][String]") +{ + String s, l; + // Make these large enough to span SSO and non SSO + String whole = "#123456789012345678901234567890"; + const char *res = "abcde123456789012345678901234567890"; + for (size_t i=1; i < whole.length(); i++) { + s = whole.substring(0, i); + l = s; + l.replace("#", "abcde"); + char buff[64]; + strcpy(buff, res); + buff[5 + i-1] = 0; + REQUIRE(!strcmp(l.c_str(), buff)); + REQUIRE(l.length() == strlen(buff)); + } +}