From: Matthias Braun Date: Mon, 23 Jan 2017 19:06:54 +0000 (+0000) Subject: Add unittests for empty bitvectors. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46a1e8bc14a056c566ca554038c85a919dfac9c3;p=llvm Add unittests for empty bitvectors. Addendum to r292575 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292817 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/ADT/BitVectorTest.cpp b/unittests/ADT/BitVectorTest.cpp index 78fd5ce6567..76e796be9eb 100644 --- a/unittests/ADT/BitVectorTest.cpp +++ b/unittests/ADT/BitVectorTest.cpp @@ -425,5 +425,42 @@ TYPED_TEST(BitVectorTest, MoveAssignment) { EXPECT_EQ(C, B); } +template +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