[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / clang-tools-extra / unittests / clang-doc / ClangDocTest.cpp
blob6e28aff09f9d955f3edded7236bc1bd6f07a897d
1 //===-- clang-doc/ClangDocTest.cpp ----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "ClangDocTest.h"
10 #include "Representation.h"
11 #include "clang/AST/RecursiveASTVisitor.h"
12 #include "gtest/gtest.h"
14 namespace clang {
15 namespace doc {
17 NamespaceInfo *InfoAsNamespace(Info *I) {
18 assert(I->IT == InfoType::IT_namespace);
19 return static_cast<NamespaceInfo *>(I);
22 RecordInfo *InfoAsRecord(Info *I) {
23 assert(I->IT == InfoType::IT_record);
24 return static_cast<RecordInfo *>(I);
27 FunctionInfo *InfoAsFunction(Info *I) {
28 assert(I->IT == InfoType::IT_function);
29 return static_cast<FunctionInfo *>(I);
32 EnumInfo *InfoAsEnum(Info *I) {
33 assert(I->IT == InfoType::IT_enum);
34 return static_cast<EnumInfo *>(I);
37 TypedefInfo *InfoAsTypedef(Info *I) {
38 assert(I->IT == InfoType::IT_typedef);
39 return static_cast<TypedefInfo *>(I);
42 void CheckCommentInfo(const std::vector<CommentInfo> &Expected,
43 const std::vector<CommentInfo> &Actual);
44 void CheckCommentInfo(const std::vector<std::unique_ptr<CommentInfo>> &Expected,
45 const std::vector<std::unique_ptr<CommentInfo>> &Actual);
47 void CheckCommentInfo(const CommentInfo &Expected, const CommentInfo &Actual) {
48 EXPECT_EQ(Expected.Kind, Actual.Kind);
49 EXPECT_EQ(Expected.Text, Actual.Text);
50 EXPECT_EQ(Expected.Name, Actual.Name);
51 EXPECT_EQ(Expected.Direction, Actual.Direction);
52 EXPECT_EQ(Expected.ParamName, Actual.ParamName);
53 EXPECT_EQ(Expected.CloseName, Actual.CloseName);
54 EXPECT_EQ(Expected.SelfClosing, Actual.SelfClosing);
55 EXPECT_EQ(Expected.Explicit, Actual.Explicit);
57 ASSERT_EQ(Expected.AttrKeys.size(), Actual.AttrKeys.size());
58 for (size_t Idx = 0; Idx < Actual.AttrKeys.size(); ++Idx)
59 EXPECT_EQ(Expected.AttrKeys[Idx], Actual.AttrKeys[Idx]);
61 ASSERT_EQ(Expected.AttrValues.size(), Actual.AttrValues.size());
62 for (size_t Idx = 0; Idx < Actual.AttrValues.size(); ++Idx)
63 EXPECT_EQ(Expected.AttrValues[Idx], Actual.AttrValues[Idx]);
65 ASSERT_EQ(Expected.Args.size(), Actual.Args.size());
66 for (size_t Idx = 0; Idx < Actual.Args.size(); ++Idx)
67 EXPECT_EQ(Expected.Args[Idx], Actual.Args[Idx]);
69 CheckCommentInfo(Expected.Children, Actual.Children);
72 void CheckCommentInfo(const std::vector<CommentInfo> &Expected,
73 const std::vector<CommentInfo> &Actual) {
74 ASSERT_EQ(Expected.size(), Actual.size());
75 for (size_t Idx = 0; Idx < Actual.size(); ++Idx)
76 CheckCommentInfo(Expected[Idx], Actual[Idx]);
79 void CheckCommentInfo(const std::vector<std::unique_ptr<CommentInfo>> &Expected,
80 const std::vector<std::unique_ptr<CommentInfo>> &Actual) {
81 ASSERT_EQ(Expected.size(), Actual.size());
82 for (size_t Idx = 0; Idx < Actual.size(); ++Idx)
83 CheckCommentInfo(*Expected[Idx], *Actual[Idx]);
86 void CheckReference(Reference &Expected, Reference &Actual) {
87 EXPECT_EQ(Expected.Name, Actual.Name);
88 EXPECT_EQ(Expected.RefType, Actual.RefType);
89 EXPECT_EQ(Expected.Path, Actual.Path);
92 void CheckTypeInfo(TypeInfo *Expected, TypeInfo *Actual) {
93 CheckReference(Expected->Type, Actual->Type);
96 void CheckFieldTypeInfo(FieldTypeInfo *Expected, FieldTypeInfo *Actual) {
97 CheckTypeInfo(Expected, Actual);
98 EXPECT_EQ(Expected->Name, Actual->Name);
101 void CheckMemberTypeInfo(MemberTypeInfo *Expected, MemberTypeInfo *Actual) {
102 CheckFieldTypeInfo(Expected, Actual);
103 EXPECT_EQ(Expected->Access, Actual->Access);
104 CheckCommentInfo(Expected->Description, Actual->Description);
107 void CheckBaseInfo(Info *Expected, Info *Actual) {
108 EXPECT_EQ(size_t(20), Actual->USR.size());
109 EXPECT_EQ(Expected->Name, Actual->Name);
110 EXPECT_EQ(Expected->Path, Actual->Path);
111 ASSERT_EQ(Expected->Namespace.size(), Actual->Namespace.size());
112 for (size_t Idx = 0; Idx < Actual->Namespace.size(); ++Idx)
113 CheckReference(Expected->Namespace[Idx], Actual->Namespace[Idx]);
114 CheckCommentInfo(Expected->Description, Actual->Description);
117 void CheckSymbolInfo(SymbolInfo *Expected, SymbolInfo *Actual) {
118 CheckBaseInfo(Expected, Actual);
119 EXPECT_EQ(Expected->DefLoc.has_value(), Actual->DefLoc.has_value());
120 if (Expected->DefLoc && Actual->DefLoc.has_value()) {
121 EXPECT_EQ(Expected->DefLoc->LineNumber, Actual->DefLoc->LineNumber);
122 EXPECT_EQ(Expected->DefLoc->Filename, Actual->DefLoc->Filename);
124 ASSERT_EQ(Expected->Loc.size(), Actual->Loc.size());
125 for (size_t Idx = 0; Idx < Actual->Loc.size(); ++Idx)
126 EXPECT_EQ(Expected->Loc[Idx], Actual->Loc[Idx]);
129 void CheckFunctionInfo(FunctionInfo *Expected, FunctionInfo *Actual) {
130 CheckSymbolInfo(Expected, Actual);
132 EXPECT_EQ(Expected->IsMethod, Actual->IsMethod);
133 CheckReference(Expected->Parent, Actual->Parent);
134 CheckTypeInfo(&Expected->ReturnType, &Actual->ReturnType);
136 ASSERT_EQ(Expected->Params.size(), Actual->Params.size());
137 for (size_t Idx = 0; Idx < Actual->Params.size(); ++Idx)
138 EXPECT_EQ(Expected->Params[Idx], Actual->Params[Idx]);
140 EXPECT_EQ(Expected->Access, Actual->Access);
143 void CheckEnumInfo(EnumInfo *Expected, EnumInfo *Actual) {
144 CheckSymbolInfo(Expected, Actual);
146 EXPECT_EQ(Expected->Scoped, Actual->Scoped);
147 ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
148 for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
149 EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
152 void CheckTypedefInfo(TypedefInfo *Expected, TypedefInfo *Actual) {
153 CheckSymbolInfo(Expected, Actual);
154 EXPECT_EQ(Expected->IsUsing, Actual->IsUsing);
155 CheckTypeInfo(&Expected->Underlying, &Actual->Underlying);
158 void CheckNamespaceInfo(NamespaceInfo *Expected, NamespaceInfo *Actual) {
159 CheckBaseInfo(Expected, Actual);
161 ASSERT_EQ(Expected->Children.Namespaces.size(),
162 Actual->Children.Namespaces.size());
163 for (size_t Idx = 0; Idx < Actual->Children.Namespaces.size(); ++Idx)
164 CheckReference(Expected->Children.Namespaces[Idx],
165 Actual->Children.Namespaces[Idx]);
167 ASSERT_EQ(Expected->Children.Records.size(), Actual->Children.Records.size());
168 for (size_t Idx = 0; Idx < Actual->Children.Records.size(); ++Idx)
169 CheckReference(Expected->Children.Records[Idx],
170 Actual->Children.Records[Idx]);
172 ASSERT_EQ(Expected->Children.Functions.size(),
173 Actual->Children.Functions.size());
174 for (size_t Idx = 0; Idx < Actual->Children.Functions.size(); ++Idx)
175 CheckFunctionInfo(&Expected->Children.Functions[Idx],
176 &Actual->Children.Functions[Idx]);
178 ASSERT_EQ(Expected->Children.Enums.size(), Actual->Children.Enums.size());
179 for (size_t Idx = 0; Idx < Actual->Children.Enums.size(); ++Idx)
180 CheckEnumInfo(&Expected->Children.Enums[Idx], &Actual->Children.Enums[Idx]);
183 void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual) {
184 CheckSymbolInfo(Expected, Actual);
186 EXPECT_EQ(Expected->TagType, Actual->TagType);
188 EXPECT_EQ(Expected->IsTypeDef, Actual->IsTypeDef);
190 ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
191 for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
192 EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
194 ASSERT_EQ(Expected->Parents.size(), Actual->Parents.size());
195 for (size_t Idx = 0; Idx < Actual->Parents.size(); ++Idx)
196 CheckReference(Expected->Parents[Idx], Actual->Parents[Idx]);
198 ASSERT_EQ(Expected->VirtualParents.size(), Actual->VirtualParents.size());
199 for (size_t Idx = 0; Idx < Actual->VirtualParents.size(); ++Idx)
200 CheckReference(Expected->VirtualParents[Idx], Actual->VirtualParents[Idx]);
202 ASSERT_EQ(Expected->Bases.size(), Actual->Bases.size());
203 for (size_t Idx = 0; Idx < Actual->Bases.size(); ++Idx)
204 CheckBaseRecordInfo(&Expected->Bases[Idx], &Actual->Bases[Idx]);
206 ASSERT_EQ(Expected->Children.Records.size(), Actual->Children.Records.size());
207 for (size_t Idx = 0; Idx < Actual->Children.Records.size(); ++Idx)
208 CheckReference(Expected->Children.Records[Idx],
209 Actual->Children.Records[Idx]);
211 ASSERT_EQ(Expected->Children.Functions.size(),
212 Actual->Children.Functions.size());
213 for (size_t Idx = 0; Idx < Actual->Children.Functions.size(); ++Idx)
214 CheckFunctionInfo(&Expected->Children.Functions[Idx],
215 &Actual->Children.Functions[Idx]);
217 ASSERT_EQ(Expected->Children.Enums.size(), Actual->Children.Enums.size());
218 for (size_t Idx = 0; Idx < Actual->Children.Enums.size(); ++Idx)
219 CheckEnumInfo(&Expected->Children.Enums[Idx], &Actual->Children.Enums[Idx]);
222 void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual) {
223 CheckRecordInfo(Expected, Actual);
225 EXPECT_EQ(Expected->IsVirtual, Actual->IsVirtual);
226 EXPECT_EQ(Expected->Access, Actual->Access);
227 EXPECT_EQ(Expected->IsParent, Actual->IsParent);
230 void CheckIndex(Index &Expected, Index &Actual) {
231 CheckReference(Expected, Actual);
232 ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
233 for (size_t Idx = 0; Idx < Actual.Children.size(); ++Idx)
234 CheckIndex(Expected.Children[Idx], Actual.Children[Idx]);
237 } // namespace doc
238 } // namespace clang