Apply clang-format to folly/ssl/
[folly.git] / folly / test / UtilityTest.cpp
index 337ade5a95fbba60e8df94856de8da6c34e59f39..5507b96f8855c193f08667b3a89b0c62bb2491cb 100644 (file)
  * limitations under the License.
  */
 
-#include <folly/Utility.h>
+#include <type_traits>
 
-#include <gtest/gtest.h>
+#include <folly/Utility.h>
+#include <folly/portability/GTest.h>
 
 namespace {
 
@@ -59,3 +60,53 @@ TEST_F(UtilityTest, copy_noexcept_spec) {
   EXPECT_FALSE(noexcept(folly::copy(thr)));
   EXPECT_TRUE(noexcept(folly::copy(std::move(thr)))); // note: does not copy
 }
+
+TEST_F(UtilityTest, as_const) {
+  struct S {
+    bool member() {
+      return false;
+    }
+    bool member() const {
+      return true;
+    }
+  };
+  S s;
+  EXPECT_FALSE(s.member());
+  EXPECT_TRUE(folly::as_const(s).member());
+  EXPECT_EQ(&s, &folly::as_const(s));
+  EXPECT_TRUE(noexcept(folly::as_const(s)));
+}
+
+TEST(FollyIntegerSequence, core) {
+  constexpr auto seq = folly::integer_sequence<int, 0, 3, 2>();
+  static_assert(seq.size() == 3, "");
+  EXPECT_EQ(3, seq.size());
+
+  auto seq2 = folly::index_sequence<0, 4, 3>();
+  EXPECT_EQ(3, seq2.size());
+
+  constexpr auto seq3 = folly::make_index_sequence<3>();
+  static_assert(seq3.size() == 3, "");
+  EXPECT_EQ(3, seq3.size());
+}
+
+TEST_F(UtilityTest, MoveOnly) {
+  class FooBar : folly::MoveOnly {
+    int a;
+  };
+
+  static_assert(
+      !std::is_copy_constructible<FooBar>::value,
+      "Should not be copy constructible");
+
+  // Test that move actually works.
+  FooBar foobar;
+  FooBar foobar2(std::move(foobar));
+  (void)foobar2;
+
+  // Test that inheriting from MoveOnly doesn't prevent the move
+  // constructor from being noexcept.
+  static_assert(
+      std::is_nothrow_move_constructible<FooBar>::value,
+      "Should have noexcept move constructor");
+}