Swap a newly added include of gtest.h with portability/GTest.h
[folly.git] / folly / test / EnumerateTest.cpp
index 5466ddcd1c55a9a81de208a35517e7bb7075277f..b3ed18d7a5b17b23ef5ad227282c22f4d05ff640 100644 (file)
  * limitations under the License.
  */
 
+#include <array>
 #include <string>
 #include <vector>
 
 #include <folly/Enumerate.h>
 #include <folly/Range.h>
-#include <gtest/gtest.h>
+#include <folly/portability/GTest.h>
 
 TEST(Enumerate, Basic) {
   std::vector<std::string> v = {"abc", "a", "ab"};
@@ -129,3 +130,41 @@ TEST(Enumerate, EmptyRange) {
     EXPECT_TRUE(false);
   }
 }
+
+class CStringRange {
+  const char* cstr;
+
+ public:
+  struct Sentinel {};
+
+  explicit CStringRange(const char* cstr) : cstr(cstr) {}
+
+  const char* begin() const {
+    return cstr;
+  }
+  Sentinel end() const {
+    return Sentinel{};
+  }
+};
+
+bool operator==(const char* c, CStringRange::Sentinel) {
+  return *c == 0;
+}
+
+TEST(Enumerate, Cpp17Support) {
+  std::array<char, 5> test = {"test"};
+  // Can't use range based for loop until C++17, so test manually
+  // Equivalent to:
+  // for (const auto it : folly::enumerate(CStringRange{test.data()})) { ... }
+  {
+    auto&& enumerate = folly::enumerate(CStringRange{test.data()});
+    auto begin = enumerate.begin();
+    auto end = enumerate.end();
+    for (; begin != end; ++begin) {
+      const auto it = *begin;
+
+      ASSERT_LT(it.index, test.size());
+      EXPECT_EQ(*it, test[it.index]);
+    }
+  }
+}