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 ripple {
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(
28 "2/-1/5/10");
29 // One item C++ array edge case
30 test(
32 "test");
33 // Empty C++ array edge case
35 {
36 // C-style array
37 char letters[4]{'w', 'a', 's', 'd'};
38 test(CollectionAndDelimiter(letters, std::to_string(0)), "w0a0s0d");
39 }
40 {
41 // Auto sized C-style array
42 std::string words[]{"one", "two", "three", "four"};
43 test(CollectionAndDelimiter(words, "\n"), "one\ntwo\nthree\nfour");
44 }
45 {
46 // One item C-style array edge case
47 std::string words[]{"thing"};
48 test(CollectionAndDelimiter(words, "\n"), "thing");
49 }
50 // Initializer list
51 test(
53 "19+25");
54 // vector
55 test(
57 "09942");
58 {
59 // vector with one item edge case
60 using namespace jtx;
61 test(
64 Account::master.human());
65 }
66 // empty vector edge case
68 // C-style string
69 test(CollectionAndDelimiter("string", " "), "s t r i n g");
70 // Empty C-style string edge case
71 test(CollectionAndDelimiter("", "*"), "");
72 // Single char C-style string edge case
73 test(CollectionAndDelimiter("x", "*"), "x");
74 // std::string
75 test(CollectionAndDelimiter(std::string{"string"}, "-"), "s-t-r-i-n-g");
76 // Empty std::string edge case
77 test(CollectionAndDelimiter(std::string{""}, "*"), "");
78 // Single char std::string edge case
79 test(CollectionAndDelimiter(std::string{"y"}, "*"), "y");
80 }
81}; // namespace test
82
83BEAST_DEFINE_TESTSUITE(join, basics, ripple);
84
85} // namespace test
86} // namespace ripple
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)