Codemod: use #include angle brackets in folly and thrift
[folly.git] / folly / test / FBVectorTest.cpp
index 98212e188c345e68c9302dd191d5d4ecb0893861..919063e81d379c42fe0e6147b2dfbbe111ae3d4f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 //
 // Author: andrei.alexandrescu@fb.com
 
-#include "folly/Traits.h"
-#include "folly/Random.h"
-#include "folly/FBString.h"
-#include "folly/FBVector.h"
+#include <folly/Traits.h>
+#include <folly/Random.h>
+#include <folly/FBString.h>
+#include <folly/FBVector.h>
 
 #include <gflags/gflags.h>
 
 #include <gtest/gtest.h>
 #include <list>
+#include <map>
 #include <memory>
 #include <boost/random.hpp>
 
@@ -245,6 +246,34 @@ TEST(FBVector, move_iterator) {
   EXPECT_EQ(fbvi3, base);
 }
 
+TEST(FBVector, reserve_consistency) {
+  struct S { int64_t a, b, c, d; };
+
+  fbvector<S> fb1;
+  for (size_t i = 0; i < 1000; ++i) {
+    fb1.reserve(1);
+    EXPECT_EQ(fb1.size(), 0);
+    fb1.shrink_to_fit();
+  }
+}
+
+TEST(FBVector, vector_of_maps) {
+  fbvector<std::map<std::string, std::string>> v;
+
+  v.push_back(std::map<std::string, std::string>());
+  v.push_back(std::map<std::string, std::string>());
+
+  EXPECT_EQ(2, v.size());
+
+  v[1]["hello"] = "world";
+  EXPECT_EQ(0, v[0].size());
+  EXPECT_EQ(1, v[1].size());
+
+  v[0]["foo"] = "bar";
+  EXPECT_EQ(1, v[0].size());
+  EXPECT_EQ(1, v[1].size());
+}
+
 int main(int argc, char** argv) {
   testing::InitGoogleTest(&argc, argv);
   google::ParseCommandLineFlags(&argc, &argv, true);