Commit a0198f14 authored by Tom Jackson's avatar Tom Jackson Committed by Sara Golemon

Fix resplit | batch

Summary: Resplit violated the contract of `apply()`; it returned `false` even though the input sequence was fully consumed.

Reviewed By: @philippv

Differential Revision: D2195889
parent b75ef0a0
...@@ -231,7 +231,7 @@ class StringResplitter : public Operator<StringResplitter> { ...@@ -231,7 +231,7 @@ class StringResplitter : public Operator<StringResplitter> {
// The stream ended with a delimiter; our contract is to swallow // The stream ended with a delimiter; our contract is to swallow
// the final empty piece. // the final empty piece.
if (s.empty()) { if (s.empty()) {
return false; return true;
} }
if (s.back() != this->delimiter_) { if (s.back() != this->delimiter_) {
return body(s); return body(s);
......
...@@ -348,6 +348,20 @@ TEST(StringGen, Unsplit) { ...@@ -348,6 +348,20 @@ TEST(StringGen, Unsplit) {
EXPECT_EQ("1, 2, 3", seq(1, 3) | unsplit(", ")); EXPECT_EQ("1, 2, 3", seq(1, 3) | unsplit(", "));
} }
TEST(StringGen, Batch) {
std::vector<std::string> chunks{
"on", "e\nt", "w", "o", "\nthr", "ee\nfo", "ur\n",
};
std::vector<std::string> lines{
"one", "two", "three", "four",
};
EXPECT_EQ(4, from(chunks) | resplit('\n') | count);
EXPECT_EQ(4, from(chunks) | resplit('\n') | batch(2) | rconcat | count);
EXPECT_EQ(4, from(chunks) | resplit('\n') | batch(3) | rconcat | count);
EXPECT_EQ(lines, from(chunks) | resplit('\n') | eachTo<std::string>() |
batch(3) | rconcat | as<vector>());
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment