ClangDocTest.cpp
7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//===-- clang-doc/ClangDocTest.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ClangDocTest.h"
#include "Representation.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "gtest/gtest.h"
namespace clang {
namespace doc {
NamespaceInfo *InfoAsNamespace(Info *I) {
assert(I->IT == InfoType::IT_namespace);
return static_cast<NamespaceInfo *>(I);
}
RecordInfo *InfoAsRecord(Info *I) {
assert(I->IT == InfoType::IT_record);
return static_cast<RecordInfo *>(I);
}
FunctionInfo *InfoAsFunction(Info *I) {
assert(I->IT == InfoType::IT_function);
return static_cast<FunctionInfo *>(I);
}
EnumInfo *InfoAsEnum(Info *I) {
assert(I->IT == InfoType::IT_enum);
return static_cast<EnumInfo *>(I);
}
void CheckCommentInfo(CommentInfo &Expected, CommentInfo &Actual) {
EXPECT_EQ(Expected.Kind, Actual.Kind);
EXPECT_EQ(Expected.Text, Actual.Text);
EXPECT_EQ(Expected.Name, Actual.Name);
EXPECT_EQ(Expected.Direction, Actual.Direction);
EXPECT_EQ(Expected.ParamName, Actual.ParamName);
EXPECT_EQ(Expected.CloseName, Actual.CloseName);
EXPECT_EQ(Expected.SelfClosing, Actual.SelfClosing);
EXPECT_EQ(Expected.Explicit, Actual.Explicit);
ASSERT_EQ(Expected.AttrKeys.size(), Actual.AttrKeys.size());
for (size_t Idx = 0; Idx < Actual.AttrKeys.size(); ++Idx)
EXPECT_EQ(Expected.AttrKeys[Idx], Actual.AttrKeys[Idx]);
ASSERT_EQ(Expected.AttrValues.size(), Actual.AttrValues.size());
for (size_t Idx = 0; Idx < Actual.AttrValues.size(); ++Idx)
EXPECT_EQ(Expected.AttrValues[Idx], Actual.AttrValues[Idx]);
ASSERT_EQ(Expected.Args.size(), Actual.Args.size());
for (size_t Idx = 0; Idx < Actual.Args.size(); ++Idx)
EXPECT_EQ(Expected.Args[Idx], Actual.Args[Idx]);
ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
for (size_t Idx = 0; Idx < Actual.Children.size(); ++Idx)
CheckCommentInfo(*Expected.Children[Idx], *Actual.Children[Idx]);
}
void CheckReference(Reference &Expected, Reference &Actual) {
EXPECT_EQ(Expected.Name, Actual.Name);
EXPECT_EQ(Expected.RefType, Actual.RefType);
EXPECT_EQ(Expected.Path, Actual.Path);
}
void CheckTypeInfo(TypeInfo *Expected, TypeInfo *Actual) {
CheckReference(Expected->Type, Actual->Type);
}
void CheckFieldTypeInfo(FieldTypeInfo *Expected, FieldTypeInfo *Actual) {
CheckTypeInfo(Expected, Actual);
EXPECT_EQ(Expected->Name, Actual->Name);
}
void CheckMemberTypeInfo(MemberTypeInfo *Expected, MemberTypeInfo *Actual) {
CheckFieldTypeInfo(Expected, Actual);
EXPECT_EQ(Expected->Access, Actual->Access);
}
void CheckBaseInfo(Info *Expected, Info *Actual) {
EXPECT_EQ(size_t(20), Actual->USR.size());
EXPECT_EQ(Expected->Name, Actual->Name);
EXPECT_EQ(Expected->Path, Actual->Path);
ASSERT_EQ(Expected->Namespace.size(), Actual->Namespace.size());
for (size_t Idx = 0; Idx < Actual->Namespace.size(); ++Idx)
CheckReference(Expected->Namespace[Idx], Actual->Namespace[Idx]);
ASSERT_EQ(Expected->Description.size(), Actual->Description.size());
for (size_t Idx = 0; Idx < Actual->Description.size(); ++Idx)
CheckCommentInfo(Expected->Description[Idx], Actual->Description[Idx]);
}
void CheckSymbolInfo(SymbolInfo *Expected, SymbolInfo *Actual) {
CheckBaseInfo(Expected, Actual);
EXPECT_EQ(Expected->DefLoc.hasValue(), Actual->DefLoc.hasValue());
if (Expected->DefLoc.hasValue() && Actual->DefLoc.hasValue()) {
EXPECT_EQ(Expected->DefLoc->LineNumber, Actual->DefLoc->LineNumber);
EXPECT_EQ(Expected->DefLoc->Filename, Actual->DefLoc->Filename);
}
ASSERT_EQ(Expected->Loc.size(), Actual->Loc.size());
for (size_t Idx = 0; Idx < Actual->Loc.size(); ++Idx)
EXPECT_EQ(Expected->Loc[Idx], Actual->Loc[Idx]);
}
void CheckFunctionInfo(FunctionInfo *Expected, FunctionInfo *Actual) {
CheckSymbolInfo(Expected, Actual);
EXPECT_EQ(Expected->IsMethod, Actual->IsMethod);
CheckReference(Expected->Parent, Actual->Parent);
CheckTypeInfo(&Expected->ReturnType, &Actual->ReturnType);
ASSERT_EQ(Expected->Params.size(), Actual->Params.size());
for (size_t Idx = 0; Idx < Actual->Params.size(); ++Idx)
EXPECT_EQ(Expected->Params[Idx], Actual->Params[Idx]);
EXPECT_EQ(Expected->Access, Actual->Access);
}
void CheckEnumInfo(EnumInfo *Expected, EnumInfo *Actual) {
CheckSymbolInfo(Expected, Actual);
EXPECT_EQ(Expected->Scoped, Actual->Scoped);
ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
}
void CheckNamespaceInfo(NamespaceInfo *Expected, NamespaceInfo *Actual) {
CheckBaseInfo(Expected, Actual);
ASSERT_EQ(Expected->ChildNamespaces.size(), Actual->ChildNamespaces.size());
for (size_t Idx = 0; Idx < Actual->ChildNamespaces.size(); ++Idx)
CheckReference(Expected->ChildNamespaces[Idx],
Actual->ChildNamespaces[Idx]);
ASSERT_EQ(Expected->ChildRecords.size(), Actual->ChildRecords.size());
for (size_t Idx = 0; Idx < Actual->ChildRecords.size(); ++Idx)
CheckReference(Expected->ChildRecords[Idx], Actual->ChildRecords[Idx]);
ASSERT_EQ(Expected->ChildFunctions.size(), Actual->ChildFunctions.size());
for (size_t Idx = 0; Idx < Actual->ChildFunctions.size(); ++Idx)
CheckFunctionInfo(&Expected->ChildFunctions[Idx],
&Actual->ChildFunctions[Idx]);
ASSERT_EQ(Expected->ChildEnums.size(), Actual->ChildEnums.size());
for (size_t Idx = 0; Idx < Actual->ChildEnums.size(); ++Idx)
CheckEnumInfo(&Expected->ChildEnums[Idx], &Actual->ChildEnums[Idx]);
}
void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual) {
CheckSymbolInfo(Expected, Actual);
EXPECT_EQ(Expected->TagType, Actual->TagType);
EXPECT_EQ(Expected->IsTypeDef, Actual->IsTypeDef);
ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
ASSERT_EQ(Expected->Parents.size(), Actual->Parents.size());
for (size_t Idx = 0; Idx < Actual->Parents.size(); ++Idx)
CheckReference(Expected->Parents[Idx], Actual->Parents[Idx]);
ASSERT_EQ(Expected->VirtualParents.size(), Actual->VirtualParents.size());
for (size_t Idx = 0; Idx < Actual->VirtualParents.size(); ++Idx)
CheckReference(Expected->VirtualParents[Idx], Actual->VirtualParents[Idx]);
ASSERT_EQ(Expected->Bases.size(), Actual->Bases.size());
for (size_t Idx = 0; Idx < Actual->Bases.size(); ++Idx)
CheckBaseRecordInfo(&Expected->Bases[Idx], &Actual->Bases[Idx]);
ASSERT_EQ(Expected->ChildRecords.size(), Actual->ChildRecords.size());
for (size_t Idx = 0; Idx < Actual->ChildRecords.size(); ++Idx)
CheckReference(Expected->ChildRecords[Idx], Actual->ChildRecords[Idx]);
ASSERT_EQ(Expected->ChildFunctions.size(), Actual->ChildFunctions.size());
for (size_t Idx = 0; Idx < Actual->ChildFunctions.size(); ++Idx)
CheckFunctionInfo(&Expected->ChildFunctions[Idx],
&Actual->ChildFunctions[Idx]);
ASSERT_EQ(Expected->ChildEnums.size(), Actual->ChildEnums.size());
for (size_t Idx = 0; Idx < Actual->ChildEnums.size(); ++Idx)
CheckEnumInfo(&Expected->ChildEnums[Idx], &Actual->ChildEnums[Idx]);
}
void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual) {
CheckRecordInfo(Expected, Actual);
EXPECT_EQ(Expected->IsVirtual, Actual->IsVirtual);
EXPECT_EQ(Expected->Access, Actual->Access);
EXPECT_EQ(Expected->IsParent, Actual->IsParent);
}
void CheckIndex(Index &Expected, Index &Actual) {
CheckReference(Expected, Actual);
ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
for (size_t Idx = 0; Idx < Actual.Children.size(); ++Idx)
CheckIndex(Expected.Children[Idx], Actual.Children[Idx]);
}
} // namespace doc
} // namespace clang