2017
[folly.git] / folly / gen / test / StringTest.cpp
index 3f28aa9a7d17af34052286e1cb557fa7d69e8bd0..82239479a2a662c992821c727fe68e2f8cd93144 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 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.
  */
 
 #include <glog/logging.h>
-#include <gtest/gtest.h>
+
 #include <iosfwd>
 #include <map>
 #include <vector>
 
 #include <folly/gen/String.h>
+#include <folly/portability/GTest.h>
 
 using namespace folly::gen;
 using namespace folly;
@@ -348,8 +349,16 @@ TEST(StringGen, Unsplit) {
   EXPECT_EQ("1, 2, 3", seq(1, 3) | unsplit(", "));
 }
 
-int main(int argc, char *argv[]) {
-  testing::InitGoogleTest(&argc, argv);
-  gflags::ParseCommandLineFlags(&argc, &argv, true);
-  return RUN_ALL_TESTS();
+TEST(StringGen, Batch) {
+  std::vector<std::string> chunks{
+      "on", "e\nt", "w", "o", "\nthr", "ee\nfo", "ur\n",
+  };
+  std::vector<std::string> lines{
+      "one", "two", "three", "four",
+  };
+  EXPECT_EQ(4, from(chunks) | resplit('\n') | count);
+  EXPECT_EQ(4, from(chunks) | resplit('\n') | batch(2) | rconcat | count);
+  EXPECT_EQ(4, from(chunks) | resplit('\n') | batch(3) | rconcat | count);
+  EXPECT_EQ(lines, from(chunks) | resplit('\n') | eachTo<std::string>() |
+                       batch(3) | rconcat | as<vector>());
 }