Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String::replace doesn't work when replacing multiple occurencies of longer String by shorter one #199

Closed
kiiv-cz opened this issue Aug 29, 2023 · 0 comments · Fixed by #200
Labels

Comments

@kiiv-cz
Copy link

kiiv-cz commented Aug 29, 2023

TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace' multiple occurencies", "[String-replace-08]")
{
  arduino::String str("Hello Arduino! Hello, Hello, Hello");
  str.replace(arduino::String("ll"), arduino::String("lll"));
  REQUIRE(str == "Helllo Arduino! Helllo, Helllo, Helllo");
}

TEST_CASE ("Testing String::replace(String, String) substr 'find' same length as 'replace' multiple occurencies", "[String-replace-09]")
{
  arduino::String str("Hello Arduino! Hello, Hello, Hello");
  str.replace(arduino::String("ll"), arduino::String("11"));
  REQUIRE(str == "He11o Arduino! He11o, He11o, He11o");
}

TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace' multiple occurencies", "[String-replace-10]")
{
  arduino::String str("Helllo Arduino! Helllo, Helllo, Helllo");
  str.replace(arduino::String("lll"), arduino::String("ll"));
  REQUIRE(str == "Hello Arduino! Hello, Hello, Hello");
}

The last testcase fails as it doesn't replace anything at all. Other two works as expected.

Reported in arduino/ArduinoCore-megaavr#109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants