Add byLine tests for empty cases
authorTom Jackson <tjackson@fb.com>
Mon, 5 Oct 2015 22:09:57 +0000 (15:09 -0700)
committerfacebook-github-bot-9 <folly-bot@fb.com>
Mon, 5 Oct 2015 22:20:16 +0000 (15:20 -0700)
Summary: It works fine, this proves it.

Reviewed By: @yfeldblum, @​jkron

Differential Revision: D2509771

fb-gh-sync-id: 28805a1e1db433d3d9a44b9d33f81e30333e44ab

folly/gen/test/FileTest.cpp

index 6ee0ffe3cfd6106d29fc1b1fbf716b950d6e8975..cc4a1532a68a238e4c590919c6458f7b686f848b 100644 (file)
@@ -30,20 +30,30 @@ using std::vector;
 
 TEST(FileGen, ByLine) {
   auto collect = eachTo<std::string>() | as<vector>();
 
 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"
       "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> { };
 }
 
 class FileGenBufferedTest : public ::testing::TestWithParam<int> { };