xrpld
Loading...
Searching...
No Matches
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
14namespace xrpl::test {
15
16struct JoinTest : public ::testing::Test
17{
18};
19
21{
22 auto test = [](auto collectionAndDelimiter, std::string expected) {
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
37 // Empty C++ array edge case
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
56 // vector
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(
63 "0000000000000000000000000000000000000000000000000000000000000001");
64 // empty vector edge case
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
76 // Single char std::string edge case
78}
79
80} // namespace xrpl::test
TEST_F(BaseUintDeathTest, fromRaw_size_mismatch)
Stream & join(Stream &s, Iter iter, Iter end, std::string_view delimiter)
Definition join.h:12
BaseUInt< 256 > uint256
Definition base_uint.h:580
T str(T... args)
T to_string(T... args)