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
xrpl
{
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(
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
30
test(
CollectionAndDelimiter
(
std::array<int, 0>
{},
","
),
""
);
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;
53
test(
CollectionAndDelimiter
(
std::vector<Account>
{
Account::master
},
"xxx"
),
Account::master
.human());
54
}
55
// empty vector edge case
56
test(
CollectionAndDelimiter
(
std::vector<uint256>
{},
","
),
""
);
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
72
BEAST_DEFINE_TESTSUITE(
join
, basics,
xrpl
);
73
74
}
// namespace test
75
}
// namespace xrpl
std::array
std::string
std::stringstream
beast::unit_test::suite
A testsuite class.
Definition
suite.h:52
xrpl::CollectionAndDelimiter
Definition
join.h:22
xrpl::test::jtx::Account::master
static Account const master
The master account.
Definition
Account.h:29
std::initializer_list
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:6
xrpl::join
Stream & join(Stream &s, Iter iter, Iter end, std::string const &delimiter)
Definition
join.h:10
std::stringstream::str
T str(T... args)
xrpl::test::join_test
Definition
join_test.cpp:10
xrpl::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