From a81dc61a6625b20950278330cfdda6adacc91cbf Mon Sep 17 00:00:00 2001 From: Tom Jackson Date: Mon, 5 Oct 2015 15:09:57 -0700 Subject: [PATCH] Add byLine tests for empty cases MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Summary: It works fine, this proves it. Reviewed By: @yfeldblum, @​jkron Differential Revision: D2509771 fb-gh-sync-id: 28805a1e1db433d3d9a44b9d33f81e30333e44ab --- folly/gen/test/FileTest.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/folly/gen/test/FileTest.cpp b/folly/gen/test/FileTest.cpp index 6ee0ffe3..cc4a1532 100644 --- a/folly/gen/test/FileTest.cpp +++ b/folly/gen/test/FileTest.cpp @@ -30,20 +30,30 @@ using std::vector; TEST(FileGen, ByLine) { auto collect = eachTo() | as(); - 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 { }; -- 2.34.1