rippled
Loading...
Searching...
No Matches
join_test.cpp
1#include <test/jtx/Account.h>
2
3#include <xrpl/basics/join.h>
4#include <xrpl/beast/unit_test.h>
5
6namespace xrpl {
7namespace test {
8
10{
11 void
12 run() override
13 {
14 auto test = [this](auto collectionanddelimiter, std::string expected) {
16 // Put something else in the buffer before and after to ensure that
17 // the << operator returns the stream correctly.
18 ss << "(" << collectionanddelimiter << ")";
19 auto const str = ss.str();
20 BEAST_EXPECT(str.substr(1, str.length() - 2) == expected);
21 BEAST_EXPECT(str.front() == '(');
22 BEAST_EXPECT(str.back() == ')');
23 };
24
25 // C++ array
26 test(CollectionAndDelimiter(std::array<int, 4>{2, -1, 5, 10}, "/"), "2/-1/5/10");
27 // One item C++ array edge case
28 test(CollectionAndDelimiter(std::array<std::string, 1>{"test"}, " & "), "test");
29 // Empty C++ array edge case
31 {
32 // C-style array
33 char letters[4]{'w', 'a', 's', 'd'};
34 test(CollectionAndDelimiter(letters, std::to_string(0)), "w0a0s0d");
35 }
36 {
37 // Auto sized C-style array
38 std::string words[]{"one", "two", "three", "four"};
39 test(CollectionAndDelimiter(words, "\n"), "one\ntwo\nthree\nfour");
40 }
41 {
42 // One item C-style array edge case
43 std::string words[]{"thing"};
44 test(CollectionAndDelimiter(words, "\n"), "thing");
45 }
46 // Initializer list
47 test(CollectionAndDelimiter(std::initializer_list<size_t>{19, 25}, "+"), "19+25");
48 // vector
49 test(CollectionAndDelimiter(std::vector<int>{0, 42}, std::to_string(99)), "09942");
50 {
51 // vector with one item edge case
52 using namespace jtx;
54 }
55 // empty vector edge case
57 // C-style string
58 test(CollectionAndDelimiter("string", " "), "s t r i n g");
59 // Empty C-style string edge case
60 test(CollectionAndDelimiter("", "*"), "");
61 // Single char C-style string edge case
62 test(CollectionAndDelimiter("x", "*"), "x");
63 // std::string
64 test(CollectionAndDelimiter(std::string{"string"}, "-"), "s-t-r-i-n-g");
65 // Empty std::string edge case
66 test(CollectionAndDelimiter(std::string{""}, "*"), "");
67 // Single char std::string edge case
68 test(CollectionAndDelimiter(std::string{"y"}, "*"), "y");
69 }
70}; // namespace test
71
72BEAST_DEFINE_TESTSUITE(join, basics, xrpl);
73
74} // namespace test
75} // namespace xrpl
A testsuite class.
Definition suite.h:52
static Account const master
The master account.
Definition Account.h:29
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Stream & join(Stream &s, Iter iter, Iter end, std::string const &delimiter)
Definition join.h:10
T str(T... args)
void run() override
Runs the suite.
Definition join_test.cpp:12
T to_string(T... args)