Move folly/Array.h
[folly.git] / folly / gen / test / FileTest.cpp
index a32714e096fa2f8061a02b2d799d2d7c6e0a2706..300459dde03d8251a275db2e143b25c55aa5f561 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <gtest/gtest.h>
 #include <string>
 #include <vector>
 
 #include <folly/File.h>
 #include <folly/Range.h>
+#include <folly/container/Array.h>
 #include <folly/experimental/TestUtil.h>
 #include <folly/gen/Base.h>
 #include <folly/gen/File.h>
+#include <folly/portability/GTest.h>
 
 using namespace folly::gen;
 using namespace folly;
@@ -50,13 +51,40 @@ TEST(FileGen, 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;
+    auto found = byLine(file.path().string().c_str()) | collect;
 
     EXPECT_EQ(expected, found) << "For Input: '" << lines << "'";
   }
 }
 
-class FileGenBufferedTest : public ::testing::TestWithParam<int> { };
+TEST(FileGen, ByLineFull) {
+  auto cases = std::vector<std::string> {
+       stripLeftMargin(R"(
+         Hello world
+         This is the second line
+
+
+         a few empty lines above
+         incomplete last line)"),
+
+         "complete last line\n",
+
+         "\n",
+
+         ""};
+
+  for (auto& lines : cases) {
+    test::TemporaryFile file("ByLineFull");
+    EXPECT_EQ(lines.size(), write(file.fd(), lines.data(), lines.size()));
+
+    auto found =
+        byLineFull(file.path().string().c_str()) | unsplit<std::string>("");
+
+    EXPECT_EQ(lines, found);
+  }
+}
+
+class FileGenBufferedTest : public ::testing::TestWithParam<int> {};
 
 TEST_P(FileGenBufferedTest, FileWriter) {
   size_t bufferSize = GetParam();
@@ -74,7 +102,7 @@ TEST_P(FileGenBufferedTest, FileWriter) {
   auto expected = src | resplit('\n') | collect;
 
   src | eachAs<StringPiece>() | toFile(File(file.fd()), bufferSize);
-  auto found = byLine(file.path().c_str()) | collect;
+  auto found = byLine(file.path().string().c_str()) | collect;
 
   EXPECT_TRUE(expected == found);
 }
@@ -86,7 +114,7 @@ TEST(FileGenBufferedTest, FileWriterSimple) {
   auto squares = seq(1, 100) | map([](int x) { return x * x; });
   squares | map(toLine) | eachAs<StringPiece>() | toFile(File(file.fd()));
   EXPECT_EQ(squares | sum,
-            byLine(File(file.path().c_str())) | eachTo<int>() | sum);
+            byLine(File(file.path().string().c_str())) | eachTo<int>() | sum);
 }
 
 INSTANTIATE_TEST_CASE_P(