Apply clang-format to folly/**/*Range*.*
[folly.git] / folly / test / RangeTest.cpp
index d9658a702c81dee0daef5be4140d17ec8cbf0da3..3538969c4756c40c5bcd92ca7992d67ba3455a67 100644 (file)
@@ -50,8 +50,8 @@ TEST(StringPiece, All) {
 
   // we expect the compiler to optimize things so that there's only one copy
   // of the string literal "foo", even though we've got it in multiple places
-  EXPECT_EQ(foo, foo2);  // remember, this uses ==, not strcmp, so it's a ptr
-                         // comparison rather than lexical
+  EXPECT_EQ(foo, foo2); // remember, this uses ==, not strcmp, so it's a ptr
+                        // comparison rather than lexical
 
   // the string object creates copies though, so the c_str of these should be
   // distinct
@@ -61,17 +61,17 @@ TEST(StringPiece, All) {
   StringPiece s(foo);
   EXPECT_EQ(s.size(), 3);
 
-  EXPECT_EQ(s.start(), foo);              // ptr comparison
-  EXPECT_NE(s.start(), fooStr.c_str());   // ptr comparison
-  EXPECT_NE(s.start(), foo2Str.c_str());  // ptr comparison
+  EXPECT_EQ(s.start(), foo); // ptr comparison
+  EXPECT_NE(s.start(), fooStr.c_str()); // ptr comparison
+  EXPECT_NE(s.start(), foo2Str.c_str()); // ptr comparison
 
-  EXPECT_EQ(s.toString(), foo);              // lexical comparison
-  EXPECT_EQ(s.toString(), fooStr.c_str());   // lexical comparison
-  EXPECT_EQ(s.toString(), foo2Str.c_str());  // lexical comparison
+  EXPECT_EQ(s.toString(), foo); // lexical comparison
+  EXPECT_EQ(s.toString(), fooStr.c_str()); // lexical comparison
+  EXPECT_EQ(s.toString(), foo2Str.c_str()); // lexical comparison
 
-  EXPECT_EQ(s, foo);                      // lexical comparison
-  EXPECT_EQ(s, fooStr);                   // lexical comparison
-  EXPECT_EQ(s, foo2Str);                  // lexical comparison
+  EXPECT_EQ(s, foo); // lexical comparison
+  EXPECT_EQ(s, fooStr); // lexical comparison
+  EXPECT_EQ(s, foo2Str); // lexical comparison
   EXPECT_EQ(foo, s);
 
   // check using StringPiece to reference substrings
@@ -96,7 +96,7 @@ TEST(StringPiece, All) {
   EXPECT_EQ(s.find("ba", 4), 6);
   EXPECT_EQ(s.find("notfound"), StringPiece::npos);
   EXPECT_EQ(s.find("notfound", 1), StringPiece::npos);
-  EXPECT_EQ(s.find("bar", 4), StringPiece::npos);  // starting position too far
+  EXPECT_EQ(s.find("bar", 4), StringPiece::npos); // starting position too far
   // starting pos that is obviously past the end -- This works for std::string
   EXPECT_EQ(s.toString().find("notfound", 55), StringPiece::npos);
   EXPECT_EQ(s.find("z", s.size()), StringPiece::npos);
@@ -112,7 +112,7 @@ TEST(StringPiece, All) {
   EXPECT_EQ(s.find('o', 2), 2);
   EXPECT_EQ(s.find('y'), StringPiece::npos);
   EXPECT_EQ(s.find('y', 1), StringPiece::npos);
-  EXPECT_EQ(s.find('o', 4), StringPiece::npos);  // starting position too far
+  EXPECT_EQ(s.find('o', 4), StringPiece::npos); // starting position too far
   EXPECT_TRUE(s.contains('z'));
   // starting pos that is obviously past the end -- This works for std::string
   EXPECT_EQ(s.toString().find('y', 55), StringPiece::npos);
@@ -265,10 +265,10 @@ TEST(StringPiece, EightBitComparisons) {
 TEST(StringPiece, ToByteRange) {
   StringPiece a("hello");
   ByteRange b(a);
-  EXPECT_EQ(static_cast<const void*>(a.begin()),
-            static_cast<const void*>(b.begin()));
-  EXPECT_EQ(static_cast<const void*>(a.end()),
-            static_cast<const void*>(b.end()));
+  EXPECT_EQ(
+      static_cast<const void*>(a.begin()), static_cast<const void*>(b.begin()));
+  EXPECT_EQ(
+      static_cast<const void*>(a.end()), static_cast<const void*>(b.end()));
 
   // and convert back again
   StringPiece c(b);
@@ -625,72 +625,72 @@ TEST(StringPiece, split_step_with_process_char_delimiter) {
   EXPECT_EQ(s, p);
 
   EXPECT_EQ(1, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 5), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("this", x);
-    return 1;
-  })));
+              EXPECT_EQ(std::next(s, 5), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("this", x);
+              return 1;
+            })));
 
   EXPECT_EQ(2, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 8), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("is", x);
-    return 2;
-  })));
+              EXPECT_EQ(std::next(s, 8), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("is", x);
+              return 2;
+            })));
 
   EXPECT_EQ(3, (p.split_step('u', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 10), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("j", x);
-    return 3;
-  })));
+              EXPECT_EQ(std::next(s, 10), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("j", x);
+              return 3;
+            })));
 
   EXPECT_EQ(4, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 13), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("st", x);
-    return 4;
-  })));
+              EXPECT_EQ(std::next(s, 13), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("st", x);
+              return 4;
+            })));
 
   EXPECT_EQ(5, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 14), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("", x);
-    return 5;
-  })));
+              EXPECT_EQ(std::next(s, 14), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("", x);
+              return 5;
+            })));
 
   EXPECT_EQ(6, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 16), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("a", x);
-    return 6;
-  })));
+              EXPECT_EQ(std::next(s, 16), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("a", x);
+              return 6;
+            })));
 
   EXPECT_EQ(7, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 21), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("test", x);
-    return 7;
-  })));
+              EXPECT_EQ(std::next(s, 21), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("test", x);
+              return 7;
+            })));
 
   EXPECT_EQ(8, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(e, p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("string", x);
-    return 8;
-  })));
+              EXPECT_EQ(e, p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("string", x);
+              return 8;
+            })));
 
   EXPECT_EQ(9, (p.split_step(' ', [&](folly::StringPiece x) {
-    EXPECT_EQ(e, p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("", x);
-    return 9;
-  })));
+              EXPECT_EQ(e, p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("", x);
+              return 9;
+            })));
 
-  EXPECT_TRUE((std::is_same<
-    void,
-    decltype(p.split_step(' ', split_step_with_process_noop))
-  >::value));
+  EXPECT_TRUE(
+      (std::is_same<
+          void,
+          decltype(p.split_step(' ', split_step_with_process_noop))>::value));
 
   EXPECT_NO_THROW(p.split_step(' ', split_step_with_process_noop));
 }
@@ -708,79 +708,79 @@ TEST(StringPiece, split_step_with_process_range_delimiter) {
   EXPECT_EQ(s, p);
 
   EXPECT_EQ(1, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 6), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("this", x);
-    return 1;
-  })));
+              EXPECT_EQ(std::next(s, 6), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("this", x);
+              return 1;
+            })));
 
   EXPECT_EQ(2, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 10), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("is", x);
-    return 2;
-  })));
+              EXPECT_EQ(std::next(s, 10), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("is", x);
+              return 2;
+            })));
 
   EXPECT_EQ(3, (p.split_step("u", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 12), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("j", x);
-    return 3;
-  })));
+              EXPECT_EQ(std::next(s, 12), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("j", x);
+              return 3;
+            })));
 
   EXPECT_EQ(4, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 16), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("st", x);
-    return 4;
-  })));
+              EXPECT_EQ(std::next(s, 16), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("st", x);
+              return 4;
+            })));
 
   EXPECT_EQ(5, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 18), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("", x);
-    return 5;
-  })));
+              EXPECT_EQ(std::next(s, 18), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("", x);
+              return 5;
+            })));
 
   EXPECT_EQ(6, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 21), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("a", x);
-    return 6;
-  })));
+              EXPECT_EQ(std::next(s, 21), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("a", x);
+              return 6;
+            })));
 
   EXPECT_EQ(7, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(std::next(s, 28), p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ(" test", x);
-    return 7;
-  })));
+              EXPECT_EQ(std::next(s, 28), p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ(" test", x);
+              return 7;
+            })));
 
   EXPECT_EQ(8, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(e, p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("string", x);
-    return 8;
-  })));
+              EXPECT_EQ(e, p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("string", x);
+              return 8;
+            })));
 
   EXPECT_EQ(9, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(e, p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("", x);
-    return 9;
-  })));
+              EXPECT_EQ(e, p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("", x);
+              return 9;
+            })));
 
   EXPECT_EQ(10, (p.split_step("  ", [&](folly::StringPiece x) {
-    EXPECT_EQ(e, p.begin());
-    EXPECT_EQ(e, p.end());
-    EXPECT_EQ("", x);
-    return 10;
-  })));
+              EXPECT_EQ(e, p.begin());
+              EXPECT_EQ(e, p.end());
+              EXPECT_EQ("", x);
+              return 10;
+            })));
 
-  EXPECT_TRUE((std::is_same<
-    void,
-    decltype(p.split_step(' ', split_step_with_process_noop))
-  >::value));
+  EXPECT_TRUE(
+      (std::is_same<
+          void,
+          decltype(p.split_step(' ', split_step_with_process_noop))>::value));
 
   EXPECT_NO_THROW(p.split_step(' ', split_step_with_process_noop));
 }
@@ -798,10 +798,7 @@ TEST(StringPiece, split_step_with_process_char_delimiter_additional_args) {
   EXPECT_EQ(e, p.end());
   EXPECT_EQ(s, p);
 
-  auto const functor = [](
-    folly::StringPiece s,
-    folly::StringPiece expected
-  ) {
+  auto const functor = [](folly::StringPiece s, folly::StringPiece expected) {
     EXPECT_EQ(expected, s);
     return expected;
   };
@@ -836,10 +833,7 @@ TEST(StringPiece, split_step_with_process_range_delimiter_additional_args) {
   EXPECT_EQ(e, p.end());
   EXPECT_EQ(s, p);
 
-  auto const functor = [](
-    folly::StringPiece s,
-    folly::StringPiece expected
-  ) {
+  auto const functor = [](folly::StringPiece s, folly::StringPiece expected) {
     EXPECT_EQ(expected, s);
     return expected;
   };
@@ -863,8 +857,12 @@ TEST(StringPiece, split_step_with_process_range_delimiter_additional_args) {
 
 TEST(StringPiece, NoInvalidImplicitConversions) {
   struct IsString {
-    bool operator()(folly::Range<int*>) { return false; }
-    bool operator()(folly::StringPiece) { return true; }
+    bool operator()(folly::Range<int*>) {
+      return false;
+    }
+    bool operator()(folly::StringPiece) {
+      return true;
+    }
   };
 
   std::string s = "hello";
@@ -912,9 +910,8 @@ struct ByteSetNeedleFinder {
   }
 };
 
-typedef ::testing::Types<SseNeedleFinder,
-                         NoSseNeedleFinder,
-                         ByteSetNeedleFinder> NeedleFinders;
+using NeedleFinders =
+    ::testing::Types<SseNeedleFinder, NoSseNeedleFinder, ByteSetNeedleFinder>;
 TYPED_TEST_CASE(NeedleFinderTest, NeedleFinders);
 
 TYPED_TEST(NeedleFinderTest, Null) {
@@ -1047,13 +1044,13 @@ TYPED_TEST(NeedleFinderTest, NoSegFault) {
         //        string(s1.data(), s1.size()).c_str(), s1.size(),
         //        string(s2.data(), s2.size()).c_str(), s2.size());
         auto r1 = this->find_first_byte_of(s1, s2);
-        auto f1 = std::find_first_of(s1.begin(), s1.end(),
-                                     s2.begin(), s2.end());
+        auto f1 =
+            std::find_first_of(s1.begin(), s1.end(), s2.begin(), s2.end());
         auto e1 = (f1 == s1.end()) ? StringPiece::npos : f1 - s1.begin();
         EXPECT_EQ(r1, e1);
         auto r2 = this->find_first_byte_of(s2, s1);
-        auto f2 = std::find_first_of(s2.begin(), s2.end(),
-                                     s1.begin(), s1.end());
+        auto f2 =
+            std::find_first_of(s2.begin(), s2.end(), s1.begin(), s1.end());
         auto e2 = (f2 == s2.end()) ? StringPiece::npos : f2 - s2.begin();
         EXPECT_EQ(r2, e2);
         freeProtectedBuf(buf1);
@@ -1121,7 +1118,7 @@ TEST(RangeFunc, Array) {
 }
 
 TEST(RangeFunc, CArray) {
-  int x[] {1, 2, 3, 4};
+  int x[]{1, 2, 3, 4};
   testRangeFunc(x, 4);
 }
 
@@ -1181,9 +1178,10 @@ TEST(RangeFunc, ConstexprCollection) {
   EXPECT_EQ(2, numCollRangeSize);
 }
 
-std::string get_rand_str(size_t size,
-                         std::uniform_int_distribution<>& dist,
-                         std::mt19937& gen) {
+std::string get_rand_str(
+    size_t size,
+    std::uniform_int_distribution<>& dist,
+    std::mt19937& gen) {
   std::string ret(size, '\0');
   for (size_t i = 0; i < size; ++i) {
     ret[i] = static_cast<char>(dist(gen));
@@ -1210,7 +1208,7 @@ TEST(ReplaceAt, exhaustiveTest) {
   std::mt19937 gen(rd());
   std::uniform_int_distribution<> dist('a', 'z');
 
-  for (int i=0; i < 100; ++i) {
+  for (int i = 0; i < 100; ++i) {
     for (size_t j = 1; j <= msp.size(); ++j) {
       auto replacement = get_rand_str(j, dist, gen);
       for (size_t pos = 0; pos < msp.size() - j; ++pos) {
@@ -1266,7 +1264,7 @@ TEST(ReplaceAll, randomTest) {
   std::mt19937 gen(rd());
   std::uniform_int_distribution<> dist('A', 'Z');
 
-  for (int i=0; i < 100; ++i) {
+  for (int i = 0; i < 100; ++i) {
     for (size_t j = 1; j <= orig.size(); ++j) {
       auto replacement = get_rand_str(j, dist, gen);
       for (size_t pos = 0; pos < msp.size() - j; ++pos) {
@@ -1285,7 +1283,7 @@ TEST(ReplaceAll, BadArg) {
   auto fst = "longer";
   auto snd = "small";
   char input[] = "meh meh meh";
-  auto all =  MutableStringPiece(input);
+  auto all = MutableStringPiece(input);
 
   try {
     all.replaceAll(fst, snd);