[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang-tools-extra / unittests / clang-doc / ClangDocTest.cpp
blob01816fb28ee6b028d34762efed3adec3fffbd144
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 void CheckCommentInfo(const std::vector<CommentInfo> &Expected,
38 const std::vector<CommentInfo> &Actual);
39 void CheckCommentInfo(const std::vector<std::unique_ptr<CommentInfo>> &Expected,
40 const std::vector<std::unique_ptr<CommentInfo>> &Actual);
42 void CheckCommentInfo(const CommentInfo &Expected, const CommentInfo &Actual) {
43 EXPECT_EQ(Expected.Kind, Actual.Kind);
44 EXPECT_EQ(Expected.Text, Actual.Text);
45 EXPECT_EQ(Expected.Name, Actual.Name);
46 EXPECT_EQ(Expected.Direction, Actual.Direction);
47 EXPECT_EQ(Expected.ParamName, Actual.ParamName);
48 EXPECT_EQ(Expected.CloseName, Actual.CloseName);
49 EXPECT_EQ(Expected.SelfClosing, Actual.SelfClosing);
50 EXPECT_EQ(Expected.Explicit, Actual.Explicit);
52 ASSERT_EQ(Expected.AttrKeys.size(), Actual.AttrKeys.size());
53 for (size_t Idx = 0; Idx < Actual.AttrKeys.size(); ++Idx)
54 EXPECT_EQ(Expected.AttrKeys[Idx], Actual.AttrKeys[Idx]);
56 ASSERT_EQ(Expected.AttrValues.size(), Actual.AttrValues.size());
57 for (size_t Idx = 0; Idx < Actual.AttrValues.size(); ++Idx)
58 EXPECT_EQ(Expected.AttrValues[Idx], Actual.AttrValues[Idx]);
60 ASSERT_EQ(Expected.Args.size(), Actual.Args.size());
61 for (size_t Idx = 0; Idx < Actual.Args.size(); ++Idx)
62 EXPECT_EQ(Expected.Args[Idx], Actual.Args[Idx]);
64 CheckCommentInfo(Expected.Children, Actual.Children);
67 void CheckCommentInfo(const std::vector<CommentInfo> &Expected,
68 const std::vector<CommentInfo> &Actual) {
69 ASSERT_EQ(Expected.size(), Actual.size());
70 for (size_t Idx = 0; Idx < Actual.size(); ++Idx)
71 CheckCommentInfo(Expected[Idx], Actual[Idx]);
74 void CheckCommentInfo(const std::vector<std::unique_ptr<CommentInfo>> &Expected,
75 const std::vector<std::unique_ptr<CommentInfo>> &Actual) {
76 ASSERT_EQ(Expected.size(), Actual.size());
77 for (size_t Idx = 0; Idx < Actual.size(); ++Idx)
78 CheckCommentInfo(*Expected[Idx], *Actual[Idx]);
81 void CheckReference(Reference &Expected, Reference &Actual) {
82 EXPECT_EQ(Expected.Name, Actual.Name);
83 EXPECT_EQ(Expected.RefType, Actual.RefType);
84 EXPECT_EQ(Expected.Path, Actual.Path);
87 void CheckTypeInfo(TypeInfo *Expected, TypeInfo *Actual) {
88 CheckReference(Expected->Type, Actual->Type);
91 void CheckFieldTypeInfo(FieldTypeInfo *Expected, FieldTypeInfo *Actual) {
92 CheckTypeInfo(Expected, Actual);
93 EXPECT_EQ(Expected->Name, Actual->Name);
96 void CheckMemberTypeInfo(MemberTypeInfo *Expected, MemberTypeInfo *Actual) {
97 CheckFieldTypeInfo(Expected, Actual);
98 EXPECT_EQ(Expected->Access, Actual->Access);
99 CheckCommentInfo(Expected->Description, Actual->Description);
102 void CheckBaseInfo(Info *Expected, Info *Actual) {
103 EXPECT_EQ(size_t(20), Actual->USR.size());
104 EXPECT_EQ(Expected->Name, Actual->Name);
105 EXPECT_EQ(Expected->Path, Actual->Path);
106 ASSERT_EQ(Expected->Namespace.size(), Actual->Namespace.size());
107 for (size_t Idx = 0; Idx < Actual->Namespace.size(); ++Idx)
108 CheckReference(Expected->Namespace[Idx], Actual->Namespace[Idx]);
109 CheckCommentInfo(Expected->Description, Actual->Description);
112 void CheckSymbolInfo(SymbolInfo *Expected, SymbolInfo *Actual) {
113 CheckBaseInfo(Expected, Actual);
114 EXPECT_EQ(Expected->DefLoc.has_value(), Actual->DefLoc.has_value());
115 if (Expected->DefLoc && Actual->DefLoc.has_value()) {
116 EXPECT_EQ(Expected->DefLoc->LineNumber, Actual->DefLoc->LineNumber);
117 EXPECT_EQ(Expected->DefLoc->Filename, Actual->DefLoc->Filename);
119 ASSERT_EQ(Expected->Loc.size(), Actual->Loc.size());
120 for (size_t Idx = 0; Idx < Actual->Loc.size(); ++Idx)
121 EXPECT_EQ(Expected->Loc[Idx], Actual->Loc[Idx]);
124 void CheckFunctionInfo(FunctionInfo *Expected, FunctionInfo *Actual) {
125 CheckSymbolInfo(Expected, Actual);
127 EXPECT_EQ(Expected->IsMethod, Actual->IsMethod);
128 CheckReference(Expected->Parent, Actual->Parent);
129 CheckTypeInfo(&Expected->ReturnType, &Actual->ReturnType);
131 ASSERT_EQ(Expected->Params.size(), Actual->Params.size());
132 for (size_t Idx = 0; Idx < Actual->Params.size(); ++Idx)
133 EXPECT_EQ(Expected->Params[Idx], Actual->Params[Idx]);
135 EXPECT_EQ(Expected->Access, Actual->Access);
138 void CheckEnumInfo(EnumInfo *Expected, EnumInfo *Actual) {
139 CheckSymbolInfo(Expected, Actual);
141 EXPECT_EQ(Expected->Scoped, Actual->Scoped);
142 ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
143 for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
144 EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
147 void CheckNamespaceInfo(NamespaceInfo *Expected, NamespaceInfo *Actual) {
148 CheckBaseInfo(Expected, Actual);
150 ASSERT_EQ(Expected->ChildNamespaces.size(), Actual->ChildNamespaces.size());
151 for (size_t Idx = 0; Idx < Actual->ChildNamespaces.size(); ++Idx)
152 CheckReference(Expected->ChildNamespaces[Idx],
153 Actual->ChildNamespaces[Idx]);
155 ASSERT_EQ(Expected->ChildRecords.size(), Actual->ChildRecords.size());
156 for (size_t Idx = 0; Idx < Actual->ChildRecords.size(); ++Idx)
157 CheckReference(Expected->ChildRecords[Idx], Actual->ChildRecords[Idx]);
159 ASSERT_EQ(Expected->ChildFunctions.size(), Actual->ChildFunctions.size());
160 for (size_t Idx = 0; Idx < Actual->ChildFunctions.size(); ++Idx)
161 CheckFunctionInfo(&Expected->ChildFunctions[Idx],
162 &Actual->ChildFunctions[Idx]);
164 ASSERT_EQ(Expected->ChildEnums.size(), Actual->ChildEnums.size());
165 for (size_t Idx = 0; Idx < Actual->ChildEnums.size(); ++Idx)
166 CheckEnumInfo(&Expected->ChildEnums[Idx], &Actual->ChildEnums[Idx]);
169 void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual) {
170 CheckSymbolInfo(Expected, Actual);
172 EXPECT_EQ(Expected->TagType, Actual->TagType);
174 EXPECT_EQ(Expected->IsTypeDef, Actual->IsTypeDef);
176 ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
177 for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
178 EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
180 ASSERT_EQ(Expected->Parents.size(), Actual->Parents.size());
181 for (size_t Idx = 0; Idx < Actual->Parents.size(); ++Idx)
182 CheckReference(Expected->Parents[Idx], Actual->Parents[Idx]);
184 ASSERT_EQ(Expected->VirtualParents.size(), Actual->VirtualParents.size());
185 for (size_t Idx = 0; Idx < Actual->VirtualParents.size(); ++Idx)
186 CheckReference(Expected->VirtualParents[Idx], Actual->VirtualParents[Idx]);
188 ASSERT_EQ(Expected->Bases.size(), Actual->Bases.size());
189 for (size_t Idx = 0; Idx < Actual->Bases.size(); ++Idx)
190 CheckBaseRecordInfo(&Expected->Bases[Idx], &Actual->Bases[Idx]);
192 ASSERT_EQ(Expected->ChildRecords.size(), Actual->ChildRecords.size());
193 for (size_t Idx = 0; Idx < Actual->ChildRecords.size(); ++Idx)
194 CheckReference(Expected->ChildRecords[Idx], Actual->ChildRecords[Idx]);
196 ASSERT_EQ(Expected->ChildFunctions.size(), Actual->ChildFunctions.size());
197 for (size_t Idx = 0; Idx < Actual->ChildFunctions.size(); ++Idx)
198 CheckFunctionInfo(&Expected->ChildFunctions[Idx],
199 &Actual->ChildFunctions[Idx]);
201 ASSERT_EQ(Expected->ChildEnums.size(), Actual->ChildEnums.size());
202 for (size_t Idx = 0; Idx < Actual->ChildEnums.size(); ++Idx)
203 CheckEnumInfo(&Expected->ChildEnums[Idx], &Actual->ChildEnums[Idx]);
206 void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual) {
207 CheckRecordInfo(Expected, Actual);
209 EXPECT_EQ(Expected->IsVirtual, Actual->IsVirtual);
210 EXPECT_EQ(Expected->Access, Actual->Access);
211 EXPECT_EQ(Expected->IsParent, Actual->IsParent);
214 void CheckIndex(Index &Expected, Index &Actual) {
215 CheckReference(Expected, Actual);
216 ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
217 for (size_t Idx = 0; Idx < Actual.Children.size(); ++Idx)
218 CheckIndex(Expected.Children[Idx], Actual.Children[Idx]);
221 } // namespace doc
222 } // namespace clang