1//===-- clang-doc/GeneratorTest.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//===----------------------------------------------------------------------===//
8
9#include "ClangDocTest.h"
10#include "Generators.h"
11#include "Representation.h"
12#include "Serialize.h"
13#include "gtest/gtest.h"
14
15namespace clang {
16namespace doc {
17
18TEST(GeneratorTest, emitIndex) {
19 Index Idx;
20 auto InfoA = std::make_unique<Info>();
21 InfoA->Name = "A";
22 InfoA->USR = serialize::hashUSR(USR: "1");
23 Generator::addInfoToIndex(Idx, Info: InfoA.get());
24 auto InfoC = std::make_unique<Info>();
25 InfoC->Name = "C";
26 InfoC->USR = serialize::hashUSR(USR: "3");
27 Reference RefB = Reference(SymbolID(), "B");
28 RefB.USR = serialize::hashUSR(USR: "2");
29 InfoC->Namespace = {std::move(RefB)};
30 Generator::addInfoToIndex(Idx, Info: InfoC.get());
31 auto InfoD = std::make_unique<Info>();
32 InfoD->Name = "D";
33 InfoD->USR = serialize::hashUSR(USR: "4");
34 auto InfoF = std::make_unique<Info>();
35 InfoF->Name = "F";
36 InfoF->USR = serialize::hashUSR(USR: "6");
37 Reference RefD = Reference(SymbolID(), "D");
38 RefD.USR = serialize::hashUSR(USR: "4");
39 Reference RefE = Reference(SymbolID(), "E");
40 RefE.USR = serialize::hashUSR(USR: "5");
41 InfoF->Namespace = {std::move(RefE), std::move(RefD)};
42 Generator::addInfoToIndex(Idx, Info: InfoF.get());
43 auto InfoG = std::make_unique<Info>(args: InfoType::IT_namespace);
44 Generator::addInfoToIndex(Idx, Info: InfoG.get());
45
46 Index ExpectedIdx;
47 Index IndexA;
48 IndexA.Name = "A";
49 ExpectedIdx.Children.emplace_back(args: std::move(IndexA));
50 Index IndexB;
51 IndexB.Name = "B";
52 Index IndexC;
53 IndexC.Name = "C";
54 IndexB.Children.emplace_back(args: std::move(IndexC));
55 ExpectedIdx.Children.emplace_back(args: std::move(IndexB));
56 Index IndexD;
57 IndexD.Name = "D";
58 Index IndexE;
59 IndexE.Name = "E";
60 Index IndexF;
61 IndexF.Name = "F";
62 IndexE.Children.emplace_back(args: std::move(IndexF));
63 IndexD.Children.emplace_back(args: std::move(IndexE));
64 ExpectedIdx.Children.emplace_back(args: std::move(IndexD));
65 Index IndexG;
66 IndexG.Name = "GlobalNamespace";
67 IndexG.RefType = InfoType::IT_namespace;
68 ExpectedIdx.Children.emplace_back(args: std::move(IndexG));
69
70 CheckIndex(Expected&: ExpectedIdx, Actual&: Idx);
71}
72
73TEST(GeneratorTest, sortIndex) {
74 Index Idx;
75 Idx.Children.emplace_back(args: "b");
76 Idx.Children.emplace_back(args: "aA");
77 Idx.Children.emplace_back(args: "aa");
78 Idx.Children.emplace_back(args: "A");
79 Idx.Children.emplace_back(args: "a");
80 Idx.sort();
81
82 Index ExpectedIdx;
83 ExpectedIdx.Children.emplace_back(args: "a");
84 ExpectedIdx.Children.emplace_back(args: "A");
85 ExpectedIdx.Children.emplace_back(args: "aa");
86 ExpectedIdx.Children.emplace_back(args: "aA");
87 ExpectedIdx.Children.emplace_back(args: "b");
88
89 CheckIndex(Expected&: ExpectedIdx, Actual&: Idx);
90}
91
92} // namespace doc
93} // namespace clang
94

source code of clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp