xrpld
Loading...
Searching...
No Matches
tests
libxrpl
basics
join.cpp
1
#include <xrpl/basics/join.h>
2
3
#include <xrpl/basics/base_uint.h>
4
5
#include <gtest/gtest.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
JoinTest
:
public
::testing::Test
17
{
18
};
19
20
TEST_F
(
JoinTest
,
join
)
21
{
22
auto
test
= [](
auto
collectionAndDelimiter,
std::string
expected) {
23
std::stringstream
ss;
24
// Put something else in the buffer before and after to ensure that
25
// the << operator returns the stream correctly.
26
ss <<
"("
<< collectionAndDelimiter <<
")"
;
27
auto
const
str = ss.
str
();
28
EXPECT_EQ(str.substr(1, str.length() - 2), expected);
29
EXPECT_EQ(str.front(),
'('
);
30
EXPECT_EQ(str.back(),
')'
);
31
};
32
33
// C++ array
34
test
(
CollectionAndDelimiter
(
std::array<int, 4>
{2, -1, 5, 10},
"/"
),
"2/-1/5/10"
);
35
// One item C++ array edge case
36
test
(
CollectionAndDelimiter
(
std::array<std::string, 1>
{
"test"
},
" & "
),
"test"
);
37
// Empty C++ array edge case
38
test
(
CollectionAndDelimiter
(
std::array<int, 0>
{},
","
),
""
);
39
{
40
// C-style array
41
char
letters[4]{
'w'
,
'a'
,
's'
,
'd'
};
42
test
(
CollectionAndDelimiter
(letters,
std::to_string
(0)),
"w0a0s0d"
);
43
}
44
{
45
// Auto sized C-style array
46
std::string
words[]{
"one"
,
"two"
,
"three"
,
"four"
};
47
test
(
CollectionAndDelimiter
(words,
"\n"
),
"one\ntwo\nthree\nfour"
);
48
}
49
{
50
// One item C-style array edge case
51
std::string
words[]{
"thing"
};
52
test
(
CollectionAndDelimiter
(words,
"\n"
),
"thing"
);
53
}
54
// Initializer list
55
test
(
CollectionAndDelimiter
(
std::initializer_list<size_t>
{19, 25},
"+"
),
"19+25"
);
56
// vector
57
test
(
CollectionAndDelimiter
(
std::vector<int>
{0, 42},
std::to_string
(99)),
"09942"
);
58
// vector with one item edge case
59
test
(
CollectionAndDelimiter
(
std::vector<std::string>
{
"master"
},
"xxx"
),
"master"
);
60
// vector with one non-trivial streamable item edge case
61
test
(
62
CollectionAndDelimiter
(
std::vector<uint256>
{
uint256
{1}},
"xxx"
),
63
"0000000000000000000000000000000000000000000000000000000000000001"
);
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
80
}
// namespace xrpl::test
array
std::string
std::stringstream
xrpl::CollectionAndDelimiter
Definition
join.h:24
cstddef
initializer_list
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::TEST_F
TEST_F(BaseUintDeathTest, fromRaw_size_mismatch)
Definition
base_uint.cpp:131
xrpl::join
Stream & join(Stream &s, Iter iter, Iter end, std::string_view delimiter)
Definition
join.h:12
xrpl::uint256
BaseUInt< 256 > uint256
Definition
base_uint.h:580
sstream
std::stringstream::str
T str(T... args)
string
xrpl::test::JoinTest
Definition
join.cpp:17
std::to_string
T to_string(T... args)
vector
Generated by
1.16.1