diff options
Diffstat (limited to 'src/test/util_tests.cpp')
-rw-r--r-- | src/test/util_tests.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index fda56ccff7..6e59d2e8e6 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -23,6 +23,7 @@ #include <util/string.h> #include <util/time.h> #include <util/vector.h> +#include <util/bitdeque.h> #include <array> #include <fstream> @@ -238,15 +239,31 @@ BOOST_AUTO_TEST_CASE(span_write_bytes) BOOST_AUTO_TEST_CASE(util_Join) { // Normal version - BOOST_CHECK_EQUAL(Join({}, ", "), ""); - BOOST_CHECK_EQUAL(Join({"foo"}, ", "), "foo"); - BOOST_CHECK_EQUAL(Join({"foo", "bar"}, ", "), "foo, bar"); + BOOST_CHECK_EQUAL(Join(std::vector<std::string>{}, ", "), ""); + BOOST_CHECK_EQUAL(Join(std::vector<std::string>{"foo"}, ", "), "foo"); + BOOST_CHECK_EQUAL(Join(std::vector<std::string>{"foo", "bar"}, ", "), "foo, bar"); // Version with unary operator const auto op_upper = [](const std::string& s) { return ToUpper(s); }; - BOOST_CHECK_EQUAL(Join<std::string>({}, ", ", op_upper), ""); - BOOST_CHECK_EQUAL(Join<std::string>({"foo"}, ", ", op_upper), "FOO"); - BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, ", ", op_upper), "FOO, BAR"); + BOOST_CHECK_EQUAL(Join(std::list<std::string>{}, ", ", op_upper), ""); + BOOST_CHECK_EQUAL(Join(std::list<std::string>{"foo"}, ", ", op_upper), "FOO"); + BOOST_CHECK_EQUAL(Join(std::list<std::string>{"foo", "bar"}, ", ", op_upper), "FOO, BAR"); +} + +BOOST_AUTO_TEST_CASE(util_ReplaceAll) +{ + const std::string original("A test \"%s\" string '%s'."); + auto test_replaceall = [&original](const std::string& search, const std::string& substitute, const std::string& expected) { + auto test = original; + ReplaceAll(test, search, substitute); + BOOST_CHECK_EQUAL(test, expected); + }; + + test_replaceall("", "foo", original); + test_replaceall(original, "foo", "foo"); + test_replaceall("%s", "foo", "A test \"foo\" string 'foo'."); + test_replaceall("\"", "foo", "A test foo%sfoo string '%s'."); + test_replaceall("'", "foo", "A test \"%s\" string foo%sfoo."); } BOOST_AUTO_TEST_CASE(util_TrimString) @@ -265,14 +282,10 @@ BOOST_AUTO_TEST_CASE(util_TrimString) BOOST_CHECK_EQUAL(TrimStringView(std::string("\x05\x04\x03\x02\x01\x00", 6), std::string("\x05\x04\x03\x02\x01\x00", 6)), ""); } -BOOST_AUTO_TEST_CASE(util_FormatParseISO8601DateTime) +BOOST_AUTO_TEST_CASE(util_FormatISO8601DateTime) { BOOST_CHECK_EQUAL(FormatISO8601DateTime(1317425777), "2011-09-30T23:36:17Z"); BOOST_CHECK_EQUAL(FormatISO8601DateTime(0), "1970-01-01T00:00:00Z"); - - BOOST_CHECK_EQUAL(ParseISO8601DateTime("1970-01-01T00:00:00Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("1960-01-01T00:00:00Z"), 0); - BOOST_CHECK_EQUAL(ParseISO8601DateTime("2011-09-30T23:36:17Z"), 1317425777); } BOOST_AUTO_TEST_CASE(util_FormatISO8601Date) @@ -2494,13 +2507,13 @@ BOOST_AUTO_TEST_CASE(test_tracked_vector) auto v2 = Vector(std::move(t2)); BOOST_CHECK_EQUAL(v2.size(), 1U); - BOOST_CHECK(v2[0].origin == &t2); + BOOST_CHECK(v2[0].origin == &t2); // NOLINT(*-use-after-move) BOOST_CHECK_EQUAL(v2[0].copies, 0); auto v3 = Vector(t1, std::move(t2)); BOOST_CHECK_EQUAL(v3.size(), 2U); BOOST_CHECK(v3[0].origin == &t1); - BOOST_CHECK(v3[1].origin == &t2); + BOOST_CHECK(v3[1].origin == &t2); // NOLINT(*-use-after-move) BOOST_CHECK_EQUAL(v3[0].copies, 1); BOOST_CHECK_EQUAL(v3[1].copies, 0); @@ -2508,7 +2521,7 @@ BOOST_AUTO_TEST_CASE(test_tracked_vector) BOOST_CHECK_EQUAL(v4.size(), 3U); BOOST_CHECK(v4[0].origin == &t1); BOOST_CHECK(v4[1].origin == &t2); - BOOST_CHECK(v4[2].origin == &t3); + BOOST_CHECK(v4[2].origin == &t3); // NOLINT(*-use-after-move) BOOST_CHECK_EQUAL(v4[0].copies, 1); BOOST_CHECK_EQUAL(v4[1].copies, 1); BOOST_CHECK_EQUAL(v4[2].copies, 0); |