xrpld
Toggle main menu visibility
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
const
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
// NOLINTNEXTLINE(readability-trailing-comma) fix-it drops comma after `{}`
39
test
(
CollectionAndDelimiter
(
std::array<int, 0>
{},
","
),
""
);
40
{
41
// C-style array
42
char
letters[4]{
'w'
,
'a'
,
's'
,
'd'
};
43
test
(
CollectionAndDelimiter
(letters,
std::to_string
(0)),
"w0a0s0d"
);
44
}
45
{
46
// Auto sized C-style array
47
std::string
words[]{
"one"
,
"two"
,
"three"
,
"four"
};
48
test
(
CollectionAndDelimiter
(words,
"\n"
),
"one\ntwo\nthree\nfour"
);
49
}
50
{
51
// One item C-style array edge case
52
std::string
words[]{
"thing"
};
53
test
(
CollectionAndDelimiter
(words,
"\n"
),
"thing"
);
54
}
55
// Initializer list
56
test
(
CollectionAndDelimiter
(
std::initializer_list<size_t>
{19, 25},
"+"
),
"19+25"
);
57
// vector
58
test
(
CollectionAndDelimiter
(
std::vector<int>
{0, 42},
std::to_string
(99)),
"09942"
);
59
// vector with one item edge case
60
test
(
CollectionAndDelimiter
(
std::vector<std::string>
{
"master"
},
"xxx"
),
"master"
);
61
// vector with one non-trivial streamable item edge case
62
test
(
63
CollectionAndDelimiter
(
std::vector<UInt256>
{
UInt256
{1}},
"xxx"
),
64
"0000000000000000000000000000000000000000000000000000000000000001"
);
65
// empty vector edge case
66
test
(
CollectionAndDelimiter
(
std::vector<UInt256>
{},
","
),
""
);
67
// C-style string
68
test
(
CollectionAndDelimiter
(
"string"
,
" "
),
"s t r i n g"
);
69
// Empty C-style string edge case
70
test
(
CollectionAndDelimiter
(
""
,
"*"
),
""
);
71
// Single char C-style string edge case
72
test
(
CollectionAndDelimiter
(
"x"
,
"*"
),
"x"
);
73
// std::string
74
test
(
CollectionAndDelimiter
(
std::string
{
"string"
},
"-"
),
"s-t-r-i-n-g"
);
75
// Empty std::string edge case
76
test
(
CollectionAndDelimiter
(
std::string
{
""
},
"*"
),
""
);
77
// Single char std::string edge case
78
test
(
CollectionAndDelimiter
(
std::string
{
"y"
},
"*"
),
"y"
);
79
}
80
81
}
// 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, from_raw_size_mismatch)
Definition
base_uint.cpp:73
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:581
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.17.0