/*
- * 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;
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();
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);
}
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(