TEST(FileGen, ByLine) {
auto collect = eachTo<std::string>() | as<vector>();
- test::TemporaryFile file("ByLine");
- static const std::string lines(
+ const std::string cases[] = {
"Hello world\n"
"This is the second line\n"
"\n"
"\n"
"a few empty lines above\n"
- "incomplete last line");
- EXPECT_EQ(lines.size(), write(file.fd(), lines.data(), lines.size()));
+ "incomplete last line",
- auto expected = from({lines}) | resplit('\n') | collect;
- auto found = byLine(file.path().c_str()) | collect;
+ "complete last line\n",
- EXPECT_TRUE(expected == found);
+ "\n",
+
+ "",
+ };
+
+ for (auto& lines : cases) {
+ test::TemporaryFile file("ByLine");
+ EXPECT_EQ(lines.size(), write(file.fd(), lines.data(), lines.size()));
+
+ auto expected = from({lines}) | resplit('\n') | collect;
+ auto found = byLine(file.path().c_str()) | collect;
+
+ EXPECT_EQ(expected, found) << "For Input: '" << lines << "'";
+ }
}
class FileGenBufferedTest : public ::testing::TestWithParam<int> { };