]> granicus.if.org Git - llvm/commitdiff
Add unittests for empty bitvectors.
authorMatthias Braun <matze@braunis.de>
Mon, 23 Jan 2017 19:06:54 +0000 (19:06 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 23 Jan 2017 19:06:54 +0000 (19:06 +0000)
Addendum to r292575

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292817 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/ADT/BitVectorTest.cpp

index 78fd5ce65677cd6c941b401b09787b3fb2e5835a..76e796be9eb92d2f337aed5f28e62a2aa28485ad 100644 (file)
@@ -425,5 +425,42 @@ TYPED_TEST(BitVectorTest, MoveAssignment) {
   EXPECT_EQ(C, B);
 }
 
+template<class TypeParam>
+static void testEmpty(const TypeParam &A) {
+  EXPECT_TRUE(A.empty());
+  EXPECT_EQ((size_t)0, A.size());
+  EXPECT_EQ((size_t)0, A.count());
+  EXPECT_FALSE(A.any());
+  EXPECT_TRUE(A.all());
+  EXPECT_TRUE(A.none());
+  EXPECT_EQ(-1, A.find_first());
+  EXPECT_EQ(A, TypeParam());
+}
+
+/// Tests whether BitVector behaves well with Bits==nullptr, Capacity==0
+TYPED_TEST(BitVectorTest, EmptyVector) {
+  TypeParam A;
+  testEmpty(A);
+
+  TypeParam B;
+  B.reset();
+  testEmpty(B);
+
+  TypeParam C;
+  C.clear();
+  testEmpty(C);
+
+  TypeParam D(A);
+  testEmpty(D);
+
+  TypeParam E;
+  E = A;
+  testEmpty(E);
+
+  TypeParam F;
+  E.reset(A);
+  testEmpty(E);
+}
+
 }
 #endif