18fc72fcbSJulie Hockett //===-- clang-doc/MergeTest.cpp -------------------------------------------===//
28fc72fcbSJulie Hockett //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
68fc72fcbSJulie Hockett //
78fc72fcbSJulie Hockett //===----------------------------------------------------------------------===//
88fc72fcbSJulie Hockett
98fc72fcbSJulie Hockett #include "ClangDocTest.h"
108fc72fcbSJulie Hockett #include "Representation.h"
118fc72fcbSJulie Hockett #include "gtest/gtest.h"
128fc72fcbSJulie Hockett
138fc72fcbSJulie Hockett namespace clang {
148fc72fcbSJulie Hockett namespace doc {
158fc72fcbSJulie Hockett
TEST(MergeTest,mergeNamespaceInfos)168fc72fcbSJulie Hockett TEST(MergeTest, mergeNamespaceInfos) {
178fc72fcbSJulie Hockett NamespaceInfo One;
188fc72fcbSJulie Hockett One.Name = "Namespace";
198fc72fcbSJulie Hockett One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
208fc72fcbSJulie Hockett
2121fb70c6SBrett Wilson One.Children.Namespaces.emplace_back(NonEmptySID, "ChildNamespace",
228fc72fcbSJulie Hockett InfoType::IT_namespace);
2321fb70c6SBrett Wilson One.Children.Records.emplace_back(NonEmptySID, "ChildStruct",
248fc72fcbSJulie Hockett InfoType::IT_record);
2521fb70c6SBrett Wilson One.Children.Functions.emplace_back();
2621fb70c6SBrett Wilson One.Children.Functions.back().Name = "OneFunction";
2721fb70c6SBrett Wilson One.Children.Functions.back().USR = NonEmptySID;
2821fb70c6SBrett Wilson One.Children.Enums.emplace_back();
2921fb70c6SBrett Wilson One.Children.Enums.back().Name = "OneEnum";
3021fb70c6SBrett Wilson One.Children.Enums.back().USR = NonEmptySID;
318fc72fcbSJulie Hockett
328fc72fcbSJulie Hockett NamespaceInfo Two;
338fc72fcbSJulie Hockett Two.Name = "Namespace";
348fc72fcbSJulie Hockett Two.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
358fc72fcbSJulie Hockett
3621fb70c6SBrett Wilson Two.Children.Namespaces.emplace_back(EmptySID, "OtherChildNamespace",
378fc72fcbSJulie Hockett InfoType::IT_namespace);
3821fb70c6SBrett Wilson Two.Children.Records.emplace_back(EmptySID, "OtherChildStruct",
398fc72fcbSJulie Hockett InfoType::IT_record);
4021fb70c6SBrett Wilson Two.Children.Functions.emplace_back();
4121fb70c6SBrett Wilson Two.Children.Functions.back().Name = "TwoFunction";
4221fb70c6SBrett Wilson Two.Children.Enums.emplace_back();
4321fb70c6SBrett Wilson Two.Children.Enums.back().Name = "TwoEnum";
448fc72fcbSJulie Hockett
458fc72fcbSJulie Hockett std::vector<std::unique_ptr<Info>> Infos;
461c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<NamespaceInfo>(std::move(One)));
471c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<NamespaceInfo>(std::move(Two)));
488fc72fcbSJulie Hockett
491c705d9cSJonas Devlieghere auto Expected = std::make_unique<NamespaceInfo>();
508fc72fcbSJulie Hockett Expected->Name = "Namespace";
518fc72fcbSJulie Hockett Expected->Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
528fc72fcbSJulie Hockett
5321fb70c6SBrett Wilson Expected->Children.Namespaces.emplace_back(NonEmptySID, "ChildNamespace",
548fc72fcbSJulie Hockett InfoType::IT_namespace);
5521fb70c6SBrett Wilson Expected->Children.Records.emplace_back(NonEmptySID, "ChildStruct",
568fc72fcbSJulie Hockett InfoType::IT_record);
5721fb70c6SBrett Wilson Expected->Children.Namespaces.emplace_back(EmptySID, "OtherChildNamespace",
588fc72fcbSJulie Hockett InfoType::IT_namespace);
5921fb70c6SBrett Wilson Expected->Children.Records.emplace_back(EmptySID, "OtherChildStruct",
608fc72fcbSJulie Hockett InfoType::IT_record);
6121fb70c6SBrett Wilson Expected->Children.Functions.emplace_back();
6221fb70c6SBrett Wilson Expected->Children.Functions.back().Name = "OneFunction";
6321fb70c6SBrett Wilson Expected->Children.Functions.back().USR = NonEmptySID;
6421fb70c6SBrett Wilson Expected->Children.Functions.emplace_back();
6521fb70c6SBrett Wilson Expected->Children.Functions.back().Name = "TwoFunction";
6621fb70c6SBrett Wilson Expected->Children.Enums.emplace_back();
6721fb70c6SBrett Wilson Expected->Children.Enums.back().Name = "OneEnum";
6821fb70c6SBrett Wilson Expected->Children.Enums.back().USR = NonEmptySID;
6921fb70c6SBrett Wilson Expected->Children.Enums.emplace_back();
7021fb70c6SBrett Wilson Expected->Children.Enums.back().Name = "TwoEnum";
718fc72fcbSJulie Hockett
728fc72fcbSJulie Hockett auto Actual = mergeInfos(Infos);
738fc72fcbSJulie Hockett assert(Actual);
748fc72fcbSJulie Hockett CheckNamespaceInfo(InfoAsNamespace(Expected.get()),
758fc72fcbSJulie Hockett InfoAsNamespace(Actual.get().get()));
768fc72fcbSJulie Hockett }
778fc72fcbSJulie Hockett
TEST(MergeTest,mergeRecordInfos)788fc72fcbSJulie Hockett TEST(MergeTest, mergeRecordInfos) {
798fc72fcbSJulie Hockett RecordInfo One;
808fc72fcbSJulie Hockett One.Name = "r";
8168266828SBrett Wilson One.IsTypeDef = true;
828fc72fcbSJulie Hockett One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
838fc72fcbSJulie Hockett
848fc72fcbSJulie Hockett One.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
858fc72fcbSJulie Hockett
860afc6085SBrett Wilson One.Members.emplace_back(TypeInfo("int"), "X", AccessSpecifier::AS_private);
87*edd690b0SVlad Serebrennikov One.TagType = TagTypeKind::Class;
888fc72fcbSJulie Hockett One.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
898fc72fcbSJulie Hockett One.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
908fc72fcbSJulie Hockett
91ba3d595fSDiego Astiazaran One.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
92ba3d595fSDiego Astiazaran AccessSpecifier::AS_protected, true);
9321fb70c6SBrett Wilson One.Children.Records.emplace_back(NonEmptySID, "SharedChildStruct",
948fc72fcbSJulie Hockett InfoType::IT_record);
9521fb70c6SBrett Wilson One.Children.Functions.emplace_back();
9621fb70c6SBrett Wilson One.Children.Functions.back().Name = "OneFunction";
9721fb70c6SBrett Wilson One.Children.Functions.back().USR = NonEmptySID;
9821fb70c6SBrett Wilson One.Children.Enums.emplace_back();
9921fb70c6SBrett Wilson One.Children.Enums.back().Name = "OneEnum";
10021fb70c6SBrett Wilson One.Children.Enums.back().USR = NonEmptySID;
1018fc72fcbSJulie Hockett
1028fc72fcbSJulie Hockett RecordInfo Two;
1038fc72fcbSJulie Hockett Two.Name = "r";
1048fc72fcbSJulie Hockett Two.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
1058fc72fcbSJulie Hockett
1068fc72fcbSJulie Hockett Two.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
1078fc72fcbSJulie Hockett
108*edd690b0SVlad Serebrennikov Two.TagType = TagTypeKind::Class;
1098fc72fcbSJulie Hockett
11021fb70c6SBrett Wilson Two.Children.Records.emplace_back(NonEmptySID, "SharedChildStruct",
111e27f778aSDiego Astiazaran InfoType::IT_record, "path");
11221fb70c6SBrett Wilson Two.Children.Functions.emplace_back();
11321fb70c6SBrett Wilson Two.Children.Functions.back().Name = "TwoFunction";
11421fb70c6SBrett Wilson Two.Children.Enums.emplace_back();
11521fb70c6SBrett Wilson Two.Children.Enums.back().Name = "TwoEnum";
1168fc72fcbSJulie Hockett
1178fc72fcbSJulie Hockett std::vector<std::unique_ptr<Info>> Infos;
1181c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<RecordInfo>(std::move(One)));
1191c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<RecordInfo>(std::move(Two)));
1208fc72fcbSJulie Hockett
1211c705d9cSJonas Devlieghere auto Expected = std::make_unique<RecordInfo>();
1228fc72fcbSJulie Hockett Expected->Name = "r";
12368266828SBrett Wilson Expected->IsTypeDef = true;
1248fc72fcbSJulie Hockett Expected->Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
1258fc72fcbSJulie Hockett
1268fc72fcbSJulie Hockett Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
1278fc72fcbSJulie Hockett Expected->Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
1288fc72fcbSJulie Hockett
1290afc6085SBrett Wilson Expected->Members.emplace_back(TypeInfo("int"), "X",
1300afc6085SBrett Wilson AccessSpecifier::AS_private);
131*edd690b0SVlad Serebrennikov Expected->TagType = TagTypeKind::Class;
1328fc72fcbSJulie Hockett Expected->Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
1338fc72fcbSJulie Hockett Expected->VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
134ba3d595fSDiego Astiazaran Expected->Bases.emplace_back(EmptySID, "F", "path/to/F", true,
135ba3d595fSDiego Astiazaran AccessSpecifier::AS_protected, true);
1368fc72fcbSJulie Hockett
13721fb70c6SBrett Wilson Expected->Children.Records.emplace_back(NonEmptySID, "SharedChildStruct",
138e27f778aSDiego Astiazaran InfoType::IT_record, "path");
13921fb70c6SBrett Wilson Expected->Children.Functions.emplace_back();
14021fb70c6SBrett Wilson Expected->Children.Functions.back().Name = "OneFunction";
14121fb70c6SBrett Wilson Expected->Children.Functions.back().USR = NonEmptySID;
14221fb70c6SBrett Wilson Expected->Children.Functions.emplace_back();
14321fb70c6SBrett Wilson Expected->Children.Functions.back().Name = "TwoFunction";
14421fb70c6SBrett Wilson Expected->Children.Enums.emplace_back();
14521fb70c6SBrett Wilson Expected->Children.Enums.back().Name = "OneEnum";
14621fb70c6SBrett Wilson Expected->Children.Enums.back().USR = NonEmptySID;
14721fb70c6SBrett Wilson Expected->Children.Enums.emplace_back();
14821fb70c6SBrett Wilson Expected->Children.Enums.back().Name = "TwoEnum";
1498fc72fcbSJulie Hockett
1508fc72fcbSJulie Hockett auto Actual = mergeInfos(Infos);
1518fc72fcbSJulie Hockett assert(Actual);
1528fc72fcbSJulie Hockett CheckRecordInfo(InfoAsRecord(Expected.get()),
1538fc72fcbSJulie Hockett InfoAsRecord(Actual.get().get()));
1548fc72fcbSJulie Hockett }
1558fc72fcbSJulie Hockett
TEST(MergeTest,mergeFunctionInfos)1568fc72fcbSJulie Hockett TEST(MergeTest, mergeFunctionInfos) {
1578fc72fcbSJulie Hockett FunctionInfo One;
1588fc72fcbSJulie Hockett One.Name = "f";
1598fc72fcbSJulie Hockett One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
1608fc72fcbSJulie Hockett
1618fc72fcbSJulie Hockett One.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
1628fc72fcbSJulie Hockett One.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
1638fc72fcbSJulie Hockett
1648fc72fcbSJulie Hockett One.IsMethod = true;
1658fc72fcbSJulie Hockett One.Parent = Reference(EmptySID, "Parent", InfoType::IT_namespace);
1668fc72fcbSJulie Hockett
16793a290fdSJulie Hockett One.Description.emplace_back();
16893a290fdSJulie Hockett auto OneFullComment = &One.Description.back();
16993a290fdSJulie Hockett OneFullComment->Kind = "FullComment";
1701c705d9cSJonas Devlieghere auto OneParagraphComment = std::make_unique<CommentInfo>();
17193a290fdSJulie Hockett OneParagraphComment->Kind = "ParagraphComment";
1721c705d9cSJonas Devlieghere auto OneTextComment = std::make_unique<CommentInfo>();
17393a290fdSJulie Hockett OneTextComment->Kind = "TextComment";
17493a290fdSJulie Hockett OneTextComment->Text = "This is a text comment.";
17593a290fdSJulie Hockett OneParagraphComment->Children.push_back(std::move(OneTextComment));
17693a290fdSJulie Hockett OneFullComment->Children.push_back(std::move(OneParagraphComment));
17793a290fdSJulie Hockett
1788fc72fcbSJulie Hockett FunctionInfo Two;
1798fc72fcbSJulie Hockett Two.Name = "f";
1808fc72fcbSJulie Hockett Two.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
1818fc72fcbSJulie Hockett
18293a290fdSJulie Hockett Two.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
1838fc72fcbSJulie Hockett
1840afc6085SBrett Wilson Two.ReturnType = TypeInfo("void");
1850afc6085SBrett Wilson Two.Params.emplace_back(TypeInfo("int"), "P");
1868fc72fcbSJulie Hockett
18793a290fdSJulie Hockett Two.Description.emplace_back();
18893a290fdSJulie Hockett auto TwoFullComment = &Two.Description.back();
18993a290fdSJulie Hockett TwoFullComment->Kind = "FullComment";
1901c705d9cSJonas Devlieghere auto TwoParagraphComment = std::make_unique<CommentInfo>();
19193a290fdSJulie Hockett TwoParagraphComment->Kind = "ParagraphComment";
1921c705d9cSJonas Devlieghere auto TwoTextComment = std::make_unique<CommentInfo>();
19393a290fdSJulie Hockett TwoTextComment->Kind = "TextComment";
19493a290fdSJulie Hockett TwoTextComment->Text = "This is a text comment.";
19593a290fdSJulie Hockett TwoParagraphComment->Children.push_back(std::move(TwoTextComment));
19693a290fdSJulie Hockett TwoFullComment->Children.push_back(std::move(TwoParagraphComment));
19793a290fdSJulie Hockett
1988fc72fcbSJulie Hockett std::vector<std::unique_ptr<Info>> Infos;
1991c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<FunctionInfo>(std::move(One)));
2001c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<FunctionInfo>(std::move(Two)));
2018fc72fcbSJulie Hockett
2021c705d9cSJonas Devlieghere auto Expected = std::make_unique<FunctionInfo>();
2038fc72fcbSJulie Hockett Expected->Name = "f";
2048fc72fcbSJulie Hockett Expected->Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
2058fc72fcbSJulie Hockett
2068fc72fcbSJulie Hockett Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
2078fc72fcbSJulie Hockett Expected->Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
2088fc72fcbSJulie Hockett
2090afc6085SBrett Wilson Expected->ReturnType = TypeInfo("void");
2100afc6085SBrett Wilson Expected->Params.emplace_back(TypeInfo("int"), "P");
2118fc72fcbSJulie Hockett Expected->IsMethod = true;
2128fc72fcbSJulie Hockett Expected->Parent = Reference(EmptySID, "Parent", InfoType::IT_namespace);
2138fc72fcbSJulie Hockett
21493a290fdSJulie Hockett Expected->Description.emplace_back();
21593a290fdSJulie Hockett auto ExpectedFullComment = &Expected->Description.back();
21693a290fdSJulie Hockett ExpectedFullComment->Kind = "FullComment";
2171c705d9cSJonas Devlieghere auto ExpectedParagraphComment = std::make_unique<CommentInfo>();
21893a290fdSJulie Hockett ExpectedParagraphComment->Kind = "ParagraphComment";
2191c705d9cSJonas Devlieghere auto ExpectedTextComment = std::make_unique<CommentInfo>();
22093a290fdSJulie Hockett ExpectedTextComment->Kind = "TextComment";
22193a290fdSJulie Hockett ExpectedTextComment->Text = "This is a text comment.";
22293a290fdSJulie Hockett ExpectedParagraphComment->Children.push_back(std::move(ExpectedTextComment));
22393a290fdSJulie Hockett ExpectedFullComment->Children.push_back(std::move(ExpectedParagraphComment));
22493a290fdSJulie Hockett
2258fc72fcbSJulie Hockett auto Actual = mergeInfos(Infos);
2268fc72fcbSJulie Hockett assert(Actual);
2278fc72fcbSJulie Hockett CheckFunctionInfo(InfoAsFunction(Expected.get()),
2288fc72fcbSJulie Hockett InfoAsFunction(Actual.get().get()));
2298fc72fcbSJulie Hockett }
2308fc72fcbSJulie Hockett
TEST(MergeTest,mergeEnumInfos)2318fc72fcbSJulie Hockett TEST(MergeTest, mergeEnumInfos) {
2328fc72fcbSJulie Hockett EnumInfo One;
2338fc72fcbSJulie Hockett One.Name = "e";
2348fc72fcbSJulie Hockett One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
2358fc72fcbSJulie Hockett
2368fc72fcbSJulie Hockett One.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
2378fc72fcbSJulie Hockett One.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
2388fc72fcbSJulie Hockett
2398fc72fcbSJulie Hockett One.Scoped = true;
2408fc72fcbSJulie Hockett
2418fc72fcbSJulie Hockett EnumInfo Two;
2428fc72fcbSJulie Hockett Two.Name = "e";
2438fc72fcbSJulie Hockett Two.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
2448fc72fcbSJulie Hockett
2458fc72fcbSJulie Hockett Two.Loc.emplace_back(20, llvm::SmallString<16>{"test.cpp"});
2468fc72fcbSJulie Hockett
2478fc72fcbSJulie Hockett Two.Members.emplace_back("X");
2488fc72fcbSJulie Hockett Two.Members.emplace_back("Y");
2498fc72fcbSJulie Hockett
2508fc72fcbSJulie Hockett std::vector<std::unique_ptr<Info>> Infos;
2511c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<EnumInfo>(std::move(One)));
2521c705d9cSJonas Devlieghere Infos.emplace_back(std::make_unique<EnumInfo>(std::move(Two)));
2538fc72fcbSJulie Hockett
2541c705d9cSJonas Devlieghere auto Expected = std::make_unique<EnumInfo>();
2558fc72fcbSJulie Hockett Expected->Name = "e";
2568fc72fcbSJulie Hockett Expected->Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
2578fc72fcbSJulie Hockett
2588fc72fcbSJulie Hockett Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
2598fc72fcbSJulie Hockett Expected->Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
2608fc72fcbSJulie Hockett Expected->Loc.emplace_back(20, llvm::SmallString<16>{"test.cpp"});
2618fc72fcbSJulie Hockett
2628fc72fcbSJulie Hockett Expected->Members.emplace_back("X");
2638fc72fcbSJulie Hockett Expected->Members.emplace_back("Y");
2648fc72fcbSJulie Hockett Expected->Scoped = true;
2658fc72fcbSJulie Hockett
2668fc72fcbSJulie Hockett auto Actual = mergeInfos(Infos);
2678fc72fcbSJulie Hockett assert(Actual);
2688fc72fcbSJulie Hockett CheckEnumInfo(InfoAsEnum(Expected.get()), InfoAsEnum(Actual.get().get()));
2698fc72fcbSJulie Hockett }
2708fc72fcbSJulie Hockett
2718fc72fcbSJulie Hockett } // namespace doc
2728fc72fcbSJulie Hockett } // namespace clang
273