26 using namespace folly;
32 using std::unique_ptr;
35 using vec = vector<string>;
37 static auto collect = eachTo<std::string>() | as<vector>();
39 TEST(StringGen, EmptySplit) {
42 auto expected =
vec{};
49 auto expected =
vec{
""};
55 auto expected =
vec{
"",
""};
61 auto expected =
vec{
""};
68 auto input =
"hello,, world, goodbye, meow";
69 auto expected =
vec{
"hello",
"",
" world",
" goodbye",
" meow"};
74 auto input =
"hello,, world, goodbye, meow";
75 auto expected =
vec{
"hello",
"",
" world"};
80 auto input =
"hello,, world, goodbye, meow";
81 auto expected =
vec{
"hello",
"",
" world",
" goodbye",
" meow"};
86 auto input =
"hello,, world, goodbye, meow";
87 auto expected =
vec{
"hello,",
"world",
"goodbye",
"meow"};
92 TEST(StringGen, SplitByNewLine) {
94 auto input =
"hello\n\n world\r\n goodbye\r me\n\row";
95 auto expected =
vec{
"hello",
"",
" world",
" goodbye",
" me",
"",
"ow"};
100 TEST(StringGen, EmptyResplit) {
102 auto input =
vec{
""};
103 auto expected =
vec{};
109 auto input =
vec{
","};
110 auto expected =
vec{
""};
115 auto input =
vec{
",,"};
116 auto expected =
vec{
"",
""};
123 auto input =
vec{
"hello,, world, goodbye, meow"};
124 auto expected =
vec{
"hello",
"",
" world",
" goodbye",
" meow"};
129 auto input =
vec{
"hel",
"lo,",
", world",
", goodbye, m",
"eow"};
130 auto expected =
vec{
"hello",
"",
" world",
" goodbye",
" meow"};
135 TEST(StringGen, ResplitKeepDelimiter) {
137 auto input =
vec{
"hello,, world, goodbye, meow"};
138 auto expected =
vec{
"hello,",
",",
" world,",
" goodbye,",
" meow"};
143 auto input =
vec{
"hel",
"lo,",
", world",
", goodbye, m",
"eow"};
144 auto expected =
vec{
"hello,",
",",
" world,",
" goodbye,",
" meow"};
151 auto lines =
"2:1.414:yo 3:1.732:hi";
155 | eachToTuple<int, double, std::string>(
':')
158 vector<tuple<int, double, std::string>> expected{
169 | eachToTuple<int>(
',')
172 vector<tuple<int>> expected{
180 auto lines =
"1:cat 2:dog";
184 | eachToTuple<int, StringPiece>(
':')
187 vector<tuple<int, StringPiece>> expected{
195 auto lines =
"2:tjackson:4 3::5";
199 | eachToTuple<int, fbstring, int>(
':')
202 vector<tuple<int, fbstring, int>> expected{
210 auto lines =
"1:2 3:4:5";
214 | eachToTuple<int, int>(
':')
221 auto lines =
"1:2:3 4:5";
225 | eachToTuple<int, int, int>(
':')
235 auto lines =
"2:1.414 3:1.732";
239 | eachToPair<int, double>(
':')
240 |
as<std::map<int, double>>();
242 std::map<int, double> expected{
250 auto lines =
"ab=>cd ef=>gh";
254 | eachToPair<string, string>(
"=>")
255 |
as<std::map<string, string>>();
257 std::map<string, string> expected{
269 vector<string> outs) {
270 vector<std::string> pieces;
274 pieces.push_back(
string(s.
begin(), s.
end()));
278 for (
const auto& in : ins) {
284 for (
size_t i = 0;
i < outs.size(); ++
i) {
289 if (ins.size() > 1) {
294 TEST(StringGen, ResplitMaxLength) {
297 {
"hel",
"lo,",
", world",
", goodbye, m",
"ew"},
',', 5,
298 {
"hello",
",",
",",
" worl",
"d,",
" good",
"bye,",
" mew"});
301 {
"hel",
"lo,",
", world",
", goodbye, m",
"eow"},
',', 5,
302 {
"hello",
",",
",",
" worl",
"d,",
" good",
"bye,",
" meow",
""});
304 {
"||",
"",
"",
"",
"|a|b",
"cdefghijklmn",
"|opqrst",
305 "uvwx|y|||",
"z",
"0123456789",
"|",
""},
'|', 2,
306 {
"|",
"|",
"|",
"a|",
"bc",
"de",
"fg",
"hi",
"jk",
"lm",
"n|",
"op",
307 "qr",
"st",
"uv",
"wx",
"|",
"y|",
"|",
"|",
"z0",
"12",
"34",
"56",
312 template <
typename F>
315 fn(
"hello,world,goodbye");
330 auto expected = folly::to<folly::fbstring>(
"asdf",
s.empty() ?
"" :
",",
s);
355 std::vector<std::string>
chunks{
356 "on",
"e\nt",
"w",
"o",
"\nthr",
"ee\nfo",
"ur\n"};
357 std::vector<std::string>
lines{
"one",
"two",
"three",
"four"};
366 | eachTo<std::string>()
373 TEST(StringGen, UncurryTuple) {
375 auto rows =
split(file,
'\n') | eachToTuple<int, int, int>(
'\t');
383 auto rows =
split(file,
'\n') | eachToPair<int, int>(
'\t');
std::vector< uint8_t > buffer(kBufferSize+16)
S resplit(char delimiter, bool keepDelimiter=false)
void runUnsplitSuite(F fn)
#define EXPECT_THROW(statement, expected_exception)
auto uncurry(F &&f) -> detail::apply_tuple::Uncurry< typename std::decay< F >::type >
constexpr detail::Count count
From from(Container &source)
#define EXPECT_EQ(val1, val2)
Gen seq(Value first, Value last)
detail::Batch batch(size_t batchSize)
—— Concurrent Priority Queue Implementation ——
constexpr detail::Sum sum
void checkResplitMaxLength(vector< string > ins, char delim, uint64_t maxLength, vector< string > outs)
constexpr detail::RangeConcat rconcat
S split(const StringPiece source, char delimiter)
Map map(Predicate pred=Predicate())
S lines(StringPiece source)
constexpr Iter end() const
constexpr Iter begin() const
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)
StreamSplitter< Callback > streamSplitter(char delimiter, Callback &&pieceCb, uint64_t capacity=0)
detail::Take take(Number count)
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
Unsplit unsplit(const Delimiter &delimiter)