brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · e7f68b4 Raw
94 lines · cpp
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-exception6//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("1");23  Generator::addInfoToIndex(Idx, InfoA.get());24  auto InfoC = std::make_unique<Info>();25  InfoC->Name = "C";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>();32  InfoD->Name = "D";33  InfoD->USR = serialize::hashUSR("4");34  auto InfoF = std::make_unique<Info>();35  InfoF->Name = "F";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());45 46  Index ExpectedIdx;47  Index IndexA;48  IndexA.Name = "A";49  ExpectedIdx.Children.emplace_back(std::move(IndexA));50  Index IndexB;51  IndexB.Name = "B";52  Index IndexC;53  IndexC.Name = "C";54  IndexB.Children.emplace_back(std::move(IndexC));55  ExpectedIdx.Children.emplace_back(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(std::move(IndexF));63  IndexD.Children.emplace_back(std::move(IndexE));64  ExpectedIdx.Children.emplace_back(std::move(IndexD));65  Index IndexG;66  IndexG.Name = "GlobalNamespace";67  IndexG.RefType = InfoType::IT_namespace;68  ExpectedIdx.Children.emplace_back(std::move(IndexG));69 70  CheckIndex(ExpectedIdx, Idx);71}72 73TEST(GeneratorTest, sortIndex) {74  Index Idx;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");80  Idx.sort();81 82  Index ExpectedIdx;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");88 89  CheckIndex(ExpectedIdx, Idx);90}91 92} // namespace doc93} // namespace clang94