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 const 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
38 // NOLINTNEXTLINE(readability-trailing-comma) fix-it drops comma after `{}`
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
57 // vector
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(
64 "0000000000000000000000000000000000000000000000000000000000000001");
65 // empty vector edge case
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
77 // Single char std::string edge case
79}
80
81} // namespace xrpl::test
TEST_F(BaseUintDeathTest, from_raw_size_mismatch)
Definition base_uint.cpp:73
Stream & join(Stream &s, Iter iter, Iter end, std::string_view delimiter)
Definition join.h:12
BaseUInt< 256 > UInt256
Definition base_uint.h:581
T str(T... args)
T to_string(T... args)