Skip to content

Commit 857526e

Browse files
committed
test: Add test case for ReplaceAll() function
1 parent b1a2021 commit 857526e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/util_tests.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ BOOST_AUTO_TEST_CASE(util_Join)
249249
BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, ", ", op_upper), "FOO, BAR");
250250
}
251251

252+
BOOST_AUTO_TEST_CASE(util_ReplaceAll)
253+
{
254+
const std::string original("A test \"%s\" string '%s'.");
255+
auto test_replaceall = [&original](const std::string& search, const std::string& substitute, const std::string& expected) {
256+
auto test = original;
257+
ReplaceAll(test, search, substitute);
258+
BOOST_CHECK_EQUAL(test, expected);
259+
};
260+
261+
test_replaceall("", "foo", original);
262+
test_replaceall(original, "foo", "foo");
263+
test_replaceall("%s", "foo", "A test \"foo\" string 'foo'.");
264+
test_replaceall("\"", "foo", "A test foo%sfoo string '%s'.");
265+
test_replaceall("'", "foo", "A test \"%s\" string foo%sfoo.");
266+
}
267+
252268
BOOST_AUTO_TEST_CASE(util_TrimString)
253269
{
254270
BOOST_CHECK_EQUAL(TrimString(" foo bar "), "foo bar");

0 commit comments

Comments
 (0)