rippled
Loading...
Searching...
No Matches
test
basics
join_test.cpp
1
#include <test/jtx/Account.h>
2
3
#include <xrpl/basics/join.h>
4
#include <xrpl/beast/unit_test.h>
5
6
namespace
ripple
{
7
namespace
test {
8
9
struct
join_test
:
beast::unit_test::suite
10
{
11
void
12
run
()
override
13
{
14
auto
test = [
this
](
auto
collectionanddelimiter,
std::string
expected) {
15
std::stringstream
ss;
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(
27
CollectionAndDelimiter
(
std::array<int, 4>
{2, -1, 5, 10},
"/"
),
28
"2/-1/5/10"
);
29
// One item C++ array edge case
30
test(
31
CollectionAndDelimiter
(
std::array<std::string, 1>
{
"test"
},
" & "
),
32
"test"
);
33
// Empty C++ array edge case
34
test(
CollectionAndDelimiter
(
std::array<int, 0>
{},
","
),
""
);
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(
52
CollectionAndDelimiter
(
std::initializer_list<size_t>
{19, 25},
"+"
),
53
"19+25"
);
54
// vector
55
test(
56
CollectionAndDelimiter
(
std::vector<int>
{0, 42},
std::to_string
(99)),
57
"09942"
);
58
{
59
// vector with one item edge case
60
using namespace
jtx;
61
test(
62
CollectionAndDelimiter
(
63
std::vector<Account>
{
Account::master
},
"xxx"
),
64
Account::master
.human());
65
}
66
// empty vector edge case
67
test(
CollectionAndDelimiter
(
std::vector<uint256>
{},
","
),
""
);
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
83
BEAST_DEFINE_TESTSUITE(
join
, basics,
ripple
);
84
85
}
// namespace test
86
}
// namespace ripple
std::array
std::string
std::stringstream
beast::unit_test::suite
A testsuite class.
Definition
suite.h:52
ripple::CollectionAndDelimiter
Definition
join.h:22
ripple::test::jtx::Account::master
static Account const master
The master account.
Definition
Account.h:29
std::initializer_list
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:6
ripple::join
Stream & join(Stream &s, Iter iter, Iter end, std::string const &delimiter)
Definition
join.h:10
std::stringstream::str
T str(T... args)
ripple::test::join_test
Definition
join_test.cpp:10
ripple::test::join_test::run
void run() override
Runs the suite.
Definition
join_test.cpp:12
std::to_string
T to_string(T... args)
std::vector
Generated by
1.9.8