fgerlits commented on a change in pull request #791: URL: https://github.com/apache/nifi-minifi-cpp/pull/791#discussion_r439384441
########## File path: libminifi/test/unit/StringUtilsTests.cpp ########## @@ -338,3 +338,30 @@ TEST_CASE("TestStringUtils::testJoinPackNegative", "[test join_pack negative]") == "rvalue c string, c string, rval std::string, std::string, char array"); } */ + +TEST_CASE("StringUtils::replaceOne works correctly", "[replaceOne]") { + REQUIRE(utils::StringUtils::replaceOne("", "x", "y") == ""); + REQUIRE(utils::StringUtils::replaceOne("banana", "a", "_") == "b_nana"); + REQUIRE(utils::StringUtils::replaceOne("banana", "b", "_") == "_anana"); + REQUIRE(utils::StringUtils::replaceOne("banana", "x", "y") == "banana"); + REQUIRE(utils::StringUtils::replaceOne("banana", "an", "") == "bana"); + REQUIRE(utils::StringUtils::replaceOne("banana", "an", "AN") == "bANana"); + REQUIRE(utils::StringUtils::replaceOne("banana", "an", "***") == "b***ana"); + REQUIRE(utils::StringUtils::replaceOne("banana", "banana", "kiwi") == "kiwi"); + REQUIRE(utils::StringUtils::replaceOne("banana", "banana", "grapefruit") == "grapefruit"); +} + +TEST_CASE("StringUtils::replaceAll works correctly", "[replaceAll]") { + auto replaceAll = [](std::string input, const std::string &from, const std::string &to) -> std::string { + return utils::StringUtils::replaceAll(input, from, to); + }; Review comment: The reason this lambda is there is that `replaceAll` takes its first argument as a non-const reference. I could make this clearer by copying explicity, eg. ```c++ auto replaceAll = [](const std::string &input, const std::string &from, const std::string &to) -> std::string { std::string input_copy{input}; return utils::StringUtils::replaceAll(input_copy, from, to); }; ``` Would you prefer that? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org