1 //===-- clang-doc/GeneratorTest.cpp ---------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "ClangDocTest.h"
10 #include "Generators.h"
11 #include "Representation.h"
12 #include "Serialize.h"
13 #include "gtest/gtest.h"
18 TEST(GeneratorTest
, emitIndex
) {
20 auto InfoA
= std::make_unique
<Info
>();
22 InfoA
->USR
= serialize::hashUSR("1");
23 Generator::addInfoToIndex(Idx
, InfoA
.get());
24 auto InfoC
= std::make_unique
<Info
>();
26 InfoC
->USR
= serialize::hashUSR("3");
27 Reference RefB
= Reference(SymbolID(), "B");
28 RefB
.USR
= serialize::hashUSR("2");
29 InfoC
->Namespace
= {std::move(RefB
)};
30 Generator::addInfoToIndex(Idx
, InfoC
.get());
31 auto InfoD
= std::make_unique
<Info
>();
33 InfoD
->USR
= serialize::hashUSR("4");
34 auto InfoF
= std::make_unique
<Info
>();
36 InfoF
->USR
= serialize::hashUSR("6");
37 Reference RefD
= Reference(SymbolID(), "D");
38 RefD
.USR
= serialize::hashUSR("4");
39 Reference RefE
= Reference(SymbolID(), "E");
40 RefE
.USR
= serialize::hashUSR("5");
41 InfoF
->Namespace
= {std::move(RefE
), std::move(RefD
)};
42 Generator::addInfoToIndex(Idx
, InfoF
.get());
43 auto InfoG
= std::make_unique
<Info
>(InfoType::IT_namespace
);
44 Generator::addInfoToIndex(Idx
, InfoG
.get());
49 ExpectedIdx
.Children
.emplace_back(std::move(IndexA
));
54 IndexB
.Children
.emplace_back(std::move(IndexC
));
55 ExpectedIdx
.Children
.emplace_back(std::move(IndexB
));
62 IndexE
.Children
.emplace_back(std::move(IndexF
));
63 IndexD
.Children
.emplace_back(std::move(IndexE
));
64 ExpectedIdx
.Children
.emplace_back(std::move(IndexD
));
66 IndexG
.Name
= "GlobalNamespace";
67 IndexG
.RefType
= InfoType::IT_namespace
;
68 ExpectedIdx
.Children
.emplace_back(std::move(IndexG
));
70 CheckIndex(ExpectedIdx
, Idx
);
73 TEST(GeneratorTest
, sortIndex
) {
75 Idx
.Children
.emplace_back("b");
76 Idx
.Children
.emplace_back("aA");
77 Idx
.Children
.emplace_back("aa");
78 Idx
.Children
.emplace_back("A");
79 Idx
.Children
.emplace_back("a");
83 ExpectedIdx
.Children
.emplace_back("a");
84 ExpectedIdx
.Children
.emplace_back("A");
85 ExpectedIdx
.Children
.emplace_back("aa");
86 ExpectedIdx
.Children
.emplace_back("aA");
87 ExpectedIdx
.Children
.emplace_back("b");
89 CheckIndex(ExpectedIdx
, Idx
);