aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-08-20 14:51:43 -0400
committerMarcoFalke <falke.marco@gmail.com>2019-08-20 16:51:41 -0400
commitfa8cd6f9c13319baca467864661982a3dfb2320c (patch)
tree1d92c6fde4e276efa705802bfc57a944f13b5b3a /src/test
parente00ecb3d7aaee463643e486ca03c318e192b8058 (diff)
util: Add Join helper to join a list of strings
Diffstat (limited to 'src/test')
-rw-r--r--src/test/util_tests.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 7119f56fc3..65cb956fbe 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -6,11 +6,12 @@
#include <clientversion.h>
#include <sync.h>
+#include <test/setup_common.h>
#include <test/util.h>
-#include <util/strencodings.h>
#include <util/moneystr.h>
+#include <util/strencodings.h>
+#include <util/string.h>
#include <util/time.h>
-#include <test/setup_common.h>
#include <stdint.h>
#include <thread>
@@ -123,6 +124,19 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
);
}
+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");
+
+ // 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_AUTO_TEST_CASE(util_FormatISO8601DateTime)
{