1#include "clang/AST/UnresolvedSet.h"
2#include "clang/AST/Decl.h"
3#include "gtest/gtest.h"
4
5using namespace clang;
6
7class UnresolvedSetTest : public ::testing::Test {
8protected:
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)];
13 };
14 DummyDecl d0, d1, d2, d3;
15 NamedDecl *n0, *n1, *n2, *n3;
16 UnresolvedSet<2> set;
17
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);
23 set.addDecl(D: n0);
24 set.addDecl(D: n1);
25 set.addDecl(D: n2);
26 set.addDecl(D: n3);
27 }
28};
29
30TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
31
32TEST_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);
37}
38
39TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
40 set.erase(I: 0);
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);
45
46 set.erase(I: 0);
47 EXPECT_EQ(set.size(), 2u);
48 EXPECT_EQ(set[0].getDecl(), n2);
49 EXPECT_EQ(set[1].getDecl(), n1);
50
51 set.erase(I: 0);
52 EXPECT_EQ(set.size(), 1u);
53 EXPECT_EQ(set[0].getDecl(), n1);
54
55 set.erase(I: 0);
56 EXPECT_EQ(set.size(), 0u);
57}
58
59TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
60 set.erase(I: 3);
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);
65
66 set.erase(I: 2);
67 EXPECT_EQ(set.size(), 2u);
68 EXPECT_EQ(set[0].getDecl(), n0);
69 EXPECT_EQ(set[1].getDecl(), n1);
70
71 set.erase(I: 1);
72 EXPECT_EQ(set.size(), 1u);
73 EXPECT_EQ(set[0].getDecl(), n0);
74
75 set.erase(I: 0);
76 EXPECT_EQ(set.size(), 0u);
77}
78
79TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
80 set.erase(I: 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);
85
86 set.erase(I: set.begin());
87 EXPECT_EQ(set.size(), 2u);
88 EXPECT_EQ(set[0].getDecl(), n2);
89 EXPECT_EQ(set[1].getDecl(), n1);
90
91 set.erase(I: set.begin());
92 EXPECT_EQ(set.size(), 1u);
93 EXPECT_EQ(set[0].getDecl(), n1);
94
95 set.erase(I: set.begin());
96 EXPECT_EQ(set.size(), 0u);
97}
98
99TEST_F(UnresolvedSetTest, EraseIteratorFromEnd) {
100 set.erase(I: --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);
105
106 set.erase(I: --set.end());
107 EXPECT_EQ(set.size(), 2u);
108 EXPECT_EQ(set[0].getDecl(), n0);
109 EXPECT_EQ(set[1].getDecl(), n1);
110
111 set.erase(I: --set.end());
112 EXPECT_EQ(set.size(), 1u);
113 EXPECT_EQ(set[0].getDecl(), n0);
114
115 set.erase(I: --set.end());
116 EXPECT_EQ(set.size(), 0u);
117}
118

source code of clang/unittests/AST/UnresolvedSetTest.cpp