1 #include "clang/AST/UnresolvedSet.h"
2 #include "clang/AST/Decl.h"
3 #include "gtest/gtest.h"
7 class UnresolvedSetTest
: public ::testing::Test
{
9 // For this test we don't care about the contents of the NamedDecl,
10 // so just use a dummy struct of appropriate size and alignment.
11 struct alignas(NamedDecl
) DummyDecl
{
12 char contents
[sizeof(NamedDecl
)];
14 DummyDecl d0
, d1
, d2
, d3
;
15 NamedDecl
*n0
, *n1
, *n2
, *n3
;
18 void SetUp() override
{
19 n0
= reinterpret_cast<NamedDecl
*>(&d0
);
20 n1
= reinterpret_cast<NamedDecl
*>(&d1
);
21 n2
= reinterpret_cast<NamedDecl
*>(&d2
);
22 n3
= reinterpret_cast<NamedDecl
*>(&d3
);
30 TEST_F(UnresolvedSetTest
, Size
) { EXPECT_EQ(set
.size(), 4u); }
32 TEST_F(UnresolvedSetTest
, ArrayOperator
) {
33 EXPECT_EQ(set
[0].getDecl(), n0
);
34 EXPECT_EQ(set
[1].getDecl(), n1
);
35 EXPECT_EQ(set
[2].getDecl(), n2
);
36 EXPECT_EQ(set
[3].getDecl(), n3
);
39 TEST_F(UnresolvedSetTest
, EraseIntegerFromStart
) {
41 EXPECT_EQ(set
.size(), 3u);
42 EXPECT_EQ(set
[0].getDecl(), n3
);
43 EXPECT_EQ(set
[1].getDecl(), n1
);
44 EXPECT_EQ(set
[2].getDecl(), n2
);
47 EXPECT_EQ(set
.size(), 2u);
48 EXPECT_EQ(set
[0].getDecl(), n2
);
49 EXPECT_EQ(set
[1].getDecl(), n1
);
52 EXPECT_EQ(set
.size(), 1u);
53 EXPECT_EQ(set
[0].getDecl(), n1
);
56 EXPECT_EQ(set
.size(), 0u);
59 TEST_F(UnresolvedSetTest
, EraseIntegerFromEnd
) {
61 EXPECT_EQ(set
.size(), 3u);
62 EXPECT_EQ(set
[0].getDecl(), n0
);
63 EXPECT_EQ(set
[1].getDecl(), n1
);
64 EXPECT_EQ(set
[2].getDecl(), n2
);
67 EXPECT_EQ(set
.size(), 2u);
68 EXPECT_EQ(set
[0].getDecl(), n0
);
69 EXPECT_EQ(set
[1].getDecl(), n1
);
72 EXPECT_EQ(set
.size(), 1u);
73 EXPECT_EQ(set
[0].getDecl(), n0
);
76 EXPECT_EQ(set
.size(), 0u);
79 TEST_F(UnresolvedSetTest
, EraseIteratorFromStart
) {
80 set
.erase(set
.begin());
81 EXPECT_EQ(set
.size(), 3u);
82 EXPECT_EQ(set
[0].getDecl(), n3
);
83 EXPECT_EQ(set
[1].getDecl(), n1
);
84 EXPECT_EQ(set
[2].getDecl(), n2
);
86 set
.erase(set
.begin());
87 EXPECT_EQ(set
.size(), 2u);
88 EXPECT_EQ(set
[0].getDecl(), n2
);
89 EXPECT_EQ(set
[1].getDecl(), n1
);
91 set
.erase(set
.begin());
92 EXPECT_EQ(set
.size(), 1u);
93 EXPECT_EQ(set
[0].getDecl(), n1
);
95 set
.erase(set
.begin());
96 EXPECT_EQ(set
.size(), 0u);
99 TEST_F(UnresolvedSetTest
, EraseIteratorFromEnd
) {
100 set
.erase(--set
.end());
101 EXPECT_EQ(set
.size(), 3u);
102 EXPECT_EQ(set
[0].getDecl(), n0
);
103 EXPECT_EQ(set
[1].getDecl(), n1
);
104 EXPECT_EQ(set
[2].getDecl(), n2
);
106 set
.erase(--set
.end());
107 EXPECT_EQ(set
.size(), 2u);
108 EXPECT_EQ(set
[0].getDecl(), n0
);
109 EXPECT_EQ(set
[1].getDecl(), n1
);
111 set
.erase(--set
.end());
112 EXPECT_EQ(set
.size(), 1u);
113 EXPECT_EQ(set
[0].getDecl(), n0
);
115 set
.erase(--set
.end());
116 EXPECT_EQ(set
.size(), 0u);