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