xrpld
Loading...
Searching...
No Matches
test
basics
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
14
namespace
xrpl::test
{
15
16
struct
join_test
:
beast::unit_test::Suite
17
{
18
void
19
run
()
override
20
{
21
auto
test
= [
this
](
auto
collectionanddelimiter,
std::string
expected) {
22
std::stringstream
ss;
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
35
test
(
CollectionAndDelimiter
(
std::array<std::string, 1>
{
"test"
},
" & "
),
"test"
);
36
// Empty C++ array edge case
37
test
(
CollectionAndDelimiter
(
std::array<int, 0>
{},
","
),
""
);
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
54
test
(
CollectionAndDelimiter
(
std::initializer_list<size_t>
{19, 25},
"+"
),
"19+25"
);
55
// vector
56
test
(
CollectionAndDelimiter
(
std::vector<int>
{0, 42},
std::to_string
(99)),
"09942"
);
57
{
58
// vector with one item edge case
59
using namespace
jtx
;
60
test
(
61
CollectionAndDelimiter
(
std::vector<Account>
{
Account::kMaster
},
"xxx"
),
62
Account::kMaster
.human());
63
}
64
// empty vector edge case
65
test
(
CollectionAndDelimiter
(
std::vector<uint256>
{},
","
),
""
);
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
75
test
(
CollectionAndDelimiter
(
std::string
{
""
},
"*"
),
""
);
76
// Single char std::string edge case
77
test
(
CollectionAndDelimiter
(
std::string
{
"y"
},
"*"
),
"y"
);
78
}
79
};
// namespace test
80
81
BEAST_DEFINE_TESTSUITE
(
join
, basics,
xrpl
);
82
83
}
// namespace xrpl::test
array
std::string
std::stringstream
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:50
xrpl::CollectionAndDelimiter
Definition
join.h:22
xrpl::test::Account::kMaster
static Account const kMaster
The master account that holds all XRP in genesis.
Definition
/libxrpl/helpers/Account.h:29
cstddef
initializer_list
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test
Definition
STLedgerEntry.h:9
xrpl::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::join
Stream & join(Stream &s, Iter iter, Iter end, std::string_view delimiter)
Definition
join.h:10
sstream
std::stringstream::str
T str(T... args)
string
xrpl::test::join_test
Definition
join_test.cpp:17
xrpl::test::join_test::run
void run() override
Runs the suite.
Definition
join_test.cpp:19
std::to_string
T to_string(T... args)
vector
Generated by
1.16.1