2018-10-17 07:07:16 +08:00
|
|
|
//===-- clang-doc/YAMLGeneratorTest.cpp
|
|
|
|
//------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-10-17 07:07:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangDocTest.h"
|
|
|
|
#include "Generators.h"
|
|
|
|
#include "Representation.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace doc {
|
|
|
|
|
|
|
|
std::unique_ptr<Generator> getYAMLGenerator() {
|
|
|
|
auto G = doc::findGeneratorByName("yaml");
|
|
|
|
if (!G)
|
|
|
|
return nullptr;
|
|
|
|
return std::move(G.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YAMLGeneratorTest, emitNamespaceYAML) {
|
|
|
|
NamespaceInfo I;
|
|
|
|
I.Name = "Namespace";
|
2019-07-13 02:32:00 +08:00
|
|
|
I.Path = "path/to/A";
|
2018-10-17 07:07:16 +08:00
|
|
|
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
|
|
|
|
|
|
|
|
I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
|
2019-08-13 02:42:46 +08:00
|
|
|
InfoType::IT_namespace, "path/to/A/Namespace");
|
|
|
|
I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
|
|
|
|
"path/to/A/Namespace");
|
2018-10-17 07:07:16 +08:00
|
|
|
I.ChildFunctions.emplace_back();
|
|
|
|
I.ChildFunctions.back().Name = "OneFunction";
|
2019-08-16 07:04:27 +08:00
|
|
|
I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
|
2018-10-17 07:07:16 +08:00
|
|
|
I.ChildEnums.emplace_back();
|
|
|
|
I.ChildEnums.back().Name = "OneEnum";
|
|
|
|
|
|
|
|
auto G = getYAMLGenerator();
|
|
|
|
assert(G);
|
|
|
|
std::string Buffer;
|
|
|
|
llvm::raw_string_ostream Actual(Buffer);
|
2019-07-26 06:46:40 +08:00
|
|
|
auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
|
2018-10-17 07:07:16 +08:00
|
|
|
assert(!Err);
|
|
|
|
std::string Expected =
|
|
|
|
R"raw(---
|
|
|
|
USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'Namespace'
|
2019-07-13 02:32:00 +08:00
|
|
|
Path: 'path/to/A'
|
2019-07-12 14:01:37 +08:00
|
|
|
Namespace:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Namespace
|
|
|
|
Name: 'A'
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildNamespaces:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Namespace
|
|
|
|
Name: 'ChildNamespace'
|
2019-08-13 02:42:46 +08:00
|
|
|
Path: 'path/to/A/Namespace'
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildRecords:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Record
|
|
|
|
Name: 'ChildStruct'
|
2019-08-13 02:42:46 +08:00
|
|
|
Path: 'path/to/A/Namespace'
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildFunctions:
|
2018-10-17 07:07:16 +08:00
|
|
|
- USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'OneFunction'
|
2018-11-15 03:39:59 +08:00
|
|
|
ReturnType: {}
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildEnums:
|
2018-10-17 07:07:16 +08:00
|
|
|
- USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'OneEnum'
|
|
|
|
...
|
|
|
|
)raw";
|
|
|
|
EXPECT_EQ(Expected, Actual.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YAMLGeneratorTest, emitRecordYAML) {
|
|
|
|
RecordInfo I;
|
|
|
|
I.Name = "r";
|
2019-08-13 02:42:46 +08:00
|
|
|
I.Path = "path/to/A";
|
2018-10-17 07:07:16 +08:00
|
|
|
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
|
|
|
|
|
|
|
|
I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
|
2019-07-13 02:32:00 +08:00
|
|
|
I.Members.emplace_back("int", "path/to/int", "X",
|
|
|
|
AccessSpecifier::AS_private);
|
2018-10-17 07:07:16 +08:00
|
|
|
I.TagType = TagTypeKind::TTK_Class;
|
2019-08-16 08:10:49 +08:00
|
|
|
I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
|
|
|
|
AccessSpecifier::AS_public, true);
|
|
|
|
I.Bases.back().ChildFunctions.emplace_back();
|
|
|
|
I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
|
|
|
|
I.Bases.back().Members.emplace_back("int", "path/to/int", "N",
|
|
|
|
AccessSpecifier::AS_private);
|
2019-08-06 08:11:34 +08:00
|
|
|
// F is in the global namespace
|
|
|
|
I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
|
2019-07-13 02:32:00 +08:00
|
|
|
I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
|
|
|
|
"path/to/G");
|
2018-10-17 07:07:16 +08:00
|
|
|
|
2019-08-13 02:42:46 +08:00
|
|
|
I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
|
|
|
|
"path/to/A/r");
|
2018-10-17 07:07:16 +08:00
|
|
|
I.ChildFunctions.emplace_back();
|
|
|
|
I.ChildFunctions.back().Name = "OneFunction";
|
|
|
|
I.ChildEnums.emplace_back();
|
|
|
|
I.ChildEnums.back().Name = "OneEnum";
|
|
|
|
|
|
|
|
auto G = getYAMLGenerator();
|
|
|
|
assert(G);
|
|
|
|
std::string Buffer;
|
|
|
|
llvm::raw_string_ostream Actual(Buffer);
|
2019-07-26 06:46:40 +08:00
|
|
|
auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
|
2018-10-17 07:07:16 +08:00
|
|
|
assert(!Err);
|
|
|
|
std::string Expected =
|
|
|
|
R"raw(---
|
|
|
|
USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'r'
|
2019-08-13 02:42:46 +08:00
|
|
|
Path: 'path/to/A'
|
2019-07-12 14:01:37 +08:00
|
|
|
Namespace:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Namespace
|
|
|
|
Name: 'A'
|
2019-07-12 14:01:37 +08:00
|
|
|
DefLocation:
|
2018-10-17 07:07:16 +08:00
|
|
|
LineNumber: 10
|
|
|
|
Filename: 'test.cpp'
|
2019-07-12 14:01:37 +08:00
|
|
|
Location:
|
2018-10-17 07:07:16 +08:00
|
|
|
- LineNumber: 12
|
|
|
|
Filename: 'test.cpp'
|
|
|
|
TagType: Class
|
2019-07-12 14:01:37 +08:00
|
|
|
Members:
|
|
|
|
- Type:
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'int'
|
2019-07-13 02:32:00 +08:00
|
|
|
Path: 'path/to/int'
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'X'
|
|
|
|
Access: Private
|
2019-08-16 08:10:49 +08:00
|
|
|
Bases:
|
|
|
|
- USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'F'
|
|
|
|
Path: 'path/to/F'
|
|
|
|
Members:
|
|
|
|
- Type:
|
|
|
|
Name: 'int'
|
|
|
|
Path: 'path/to/int'
|
|
|
|
Name: 'N'
|
|
|
|
Access: Private
|
|
|
|
ChildFunctions:
|
|
|
|
- USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'InheritedFunctionOne'
|
|
|
|
ReturnType: {}
|
|
|
|
Access: Public
|
|
|
|
IsVirtual: true
|
|
|
|
Access: Public
|
|
|
|
IsParent: true
|
2019-07-12 14:01:37 +08:00
|
|
|
Parents:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Record
|
|
|
|
Name: 'F'
|
2019-08-06 08:11:34 +08:00
|
|
|
IsInGlobalNamespace: true
|
2019-07-12 14:01:37 +08:00
|
|
|
VirtualParents:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Record
|
|
|
|
Name: 'G'
|
2019-07-13 02:32:00 +08:00
|
|
|
Path: 'path/to/G'
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildRecords:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Record
|
|
|
|
Name: 'ChildStruct'
|
2019-08-13 02:42:46 +08:00
|
|
|
Path: 'path/to/A/r'
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildFunctions:
|
2018-10-17 07:07:16 +08:00
|
|
|
- USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'OneFunction'
|
2018-11-15 03:39:59 +08:00
|
|
|
ReturnType: {}
|
2019-08-16 07:04:27 +08:00
|
|
|
Access: Public
|
2019-07-12 14:01:37 +08:00
|
|
|
ChildEnums:
|
2018-10-17 07:07:16 +08:00
|
|
|
- USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'OneEnum'
|
|
|
|
...
|
|
|
|
)raw";
|
|
|
|
EXPECT_EQ(Expected, Actual.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YAMLGeneratorTest, emitFunctionYAML) {
|
|
|
|
FunctionInfo I;
|
|
|
|
I.Name = "f";
|
|
|
|
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
|
|
|
|
|
|
|
|
I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
|
2019-08-16 07:04:27 +08:00
|
|
|
I.Access = AccessSpecifier::AS_none;
|
|
|
|
|
2019-07-13 02:32:00 +08:00
|
|
|
I.ReturnType =
|
|
|
|
TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void");
|
|
|
|
I.Params.emplace_back("int", "path/to/int", "P");
|
2018-10-17 07:07:16 +08:00
|
|
|
I.IsMethod = true;
|
|
|
|
I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
|
|
|
|
|
|
|
|
auto G = getYAMLGenerator();
|
|
|
|
assert(G);
|
|
|
|
std::string Buffer;
|
|
|
|
llvm::raw_string_ostream Actual(Buffer);
|
2019-07-26 06:46:40 +08:00
|
|
|
auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
|
2018-10-17 07:07:16 +08:00
|
|
|
assert(!Err);
|
|
|
|
std::string Expected =
|
|
|
|
R"raw(---
|
|
|
|
USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'f'
|
2019-07-12 14:01:37 +08:00
|
|
|
Namespace:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Namespace
|
|
|
|
Name: 'A'
|
2019-07-12 14:01:37 +08:00
|
|
|
DefLocation:
|
2018-10-17 07:07:16 +08:00
|
|
|
LineNumber: 10
|
|
|
|
Filename: 'test.cpp'
|
2019-07-12 14:01:37 +08:00
|
|
|
Location:
|
2018-10-17 07:07:16 +08:00
|
|
|
- LineNumber: 12
|
|
|
|
Filename: 'test.cpp'
|
|
|
|
IsMethod: true
|
2019-07-12 14:01:37 +08:00
|
|
|
Parent:
|
2018-10-17 07:07:16 +08:00
|
|
|
Type: Record
|
|
|
|
Name: 'Parent'
|
2019-07-12 14:01:37 +08:00
|
|
|
Params:
|
|
|
|
- Type:
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'int'
|
2019-07-13 02:32:00 +08:00
|
|
|
Path: 'path/to/int'
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'P'
|
2019-07-12 14:01:37 +08:00
|
|
|
ReturnType:
|
|
|
|
Type:
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'void'
|
2019-07-13 02:32:00 +08:00
|
|
|
Path: 'path/to/void'
|
2018-10-17 07:07:16 +08:00
|
|
|
...
|
|
|
|
)raw";
|
|
|
|
EXPECT_EQ(Expected, Actual.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YAMLGeneratorTest, emitEnumYAML) {
|
|
|
|
EnumInfo I;
|
|
|
|
I.Name = "e";
|
|
|
|
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
|
|
|
|
|
|
|
|
I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
|
|
|
|
I.Members.emplace_back("X");
|
|
|
|
I.Scoped = true;
|
|
|
|
|
|
|
|
auto G = getYAMLGenerator();
|
|
|
|
assert(G);
|
|
|
|
std::string Buffer;
|
|
|
|
llvm::raw_string_ostream Actual(Buffer);
|
2019-07-26 06:46:40 +08:00
|
|
|
auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
|
2018-10-17 07:07:16 +08:00
|
|
|
assert(!Err);
|
|
|
|
std::string Expected =
|
|
|
|
R"raw(---
|
|
|
|
USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'e'
|
2019-07-12 14:01:37 +08:00
|
|
|
Namespace:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Type: Namespace
|
|
|
|
Name: 'A'
|
2019-07-12 14:01:37 +08:00
|
|
|
DefLocation:
|
2018-10-17 07:07:16 +08:00
|
|
|
LineNumber: 10
|
|
|
|
Filename: 'test.cpp'
|
2019-07-12 14:01:37 +08:00
|
|
|
Location:
|
2018-10-17 07:07:16 +08:00
|
|
|
- LineNumber: 12
|
|
|
|
Filename: 'test.cpp'
|
|
|
|
Scoped: true
|
2019-07-12 14:01:37 +08:00
|
|
|
Members:
|
2018-10-17 07:07:16 +08:00
|
|
|
- 'X'
|
|
|
|
...
|
|
|
|
)raw";
|
|
|
|
EXPECT_EQ(Expected, Actual.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(YAMLGeneratorTest, emitCommentYAML) {
|
|
|
|
FunctionInfo I;
|
|
|
|
I.Name = "f";
|
|
|
|
I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
|
|
|
|
I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
|
|
|
|
I.Params.emplace_back("int", "I");
|
|
|
|
I.Params.emplace_back("int", "J");
|
2019-08-16 07:04:27 +08:00
|
|
|
I.Access = AccessSpecifier::AS_none;
|
2018-10-17 07:07:16 +08:00
|
|
|
|
|
|
|
CommentInfo Top;
|
|
|
|
Top.Kind = "FullComment";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *BlankLine = Top.Children.back().get();
|
|
|
|
BlankLine->Kind = "ParagraphComment";
|
2019-08-15 07:52:23 +08:00
|
|
|
BlankLine->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
BlankLine->Children.back()->Kind = "TextComment";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *Brief = Top.Children.back().get();
|
|
|
|
Brief->Kind = "ParagraphComment";
|
2019-08-15 07:52:23 +08:00
|
|
|
Brief->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
Brief->Children.back()->Kind = "TextComment";
|
|
|
|
Brief->Children.back()->Name = "ParagraphComment";
|
|
|
|
Brief->Children.back()->Text = " Brief description.";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *Extended = Top.Children.back().get();
|
|
|
|
Extended->Kind = "ParagraphComment";
|
2019-08-15 07:52:23 +08:00
|
|
|
Extended->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
Extended->Children.back()->Kind = "TextComment";
|
|
|
|
Extended->Children.back()->Text = " Extended description that";
|
2019-08-15 07:52:23 +08:00
|
|
|
Extended->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
Extended->Children.back()->Kind = "TextComment";
|
|
|
|
Extended->Children.back()->Text = " continues onto the next line.";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *HTML = Top.Children.back().get();
|
|
|
|
HTML->Kind = "ParagraphComment";
|
2019-08-15 07:52:23 +08:00
|
|
|
HTML->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
HTML->Children.back()->Kind = "TextComment";
|
2019-08-15 07:52:23 +08:00
|
|
|
HTML->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
HTML->Children.back()->Kind = "HTMLStartTagComment";
|
|
|
|
HTML->Children.back()->Name = "ul";
|
|
|
|
HTML->Children.back()->AttrKeys.emplace_back("class");
|
|
|
|
HTML->Children.back()->AttrValues.emplace_back("test");
|
2019-08-15 07:52:23 +08:00
|
|
|
HTML->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
HTML->Children.back()->Kind = "HTMLStartTagComment";
|
|
|
|
HTML->Children.back()->Name = "li";
|
2019-08-15 07:52:23 +08:00
|
|
|
HTML->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
HTML->Children.back()->Kind = "TextComment";
|
|
|
|
HTML->Children.back()->Text = " Testing.";
|
2019-08-15 07:52:23 +08:00
|
|
|
HTML->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
HTML->Children.back()->Kind = "HTMLEndTagComment";
|
|
|
|
HTML->Children.back()->Name = "ul";
|
|
|
|
HTML->Children.back()->SelfClosing = true;
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *Verbatim = Top.Children.back().get();
|
|
|
|
Verbatim->Kind = "VerbatimBlockComment";
|
|
|
|
Verbatim->Name = "verbatim";
|
|
|
|
Verbatim->CloseName = "endverbatim";
|
2019-08-15 07:52:23 +08:00
|
|
|
Verbatim->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
Verbatim->Children.back()->Kind = "VerbatimBlockLineComment";
|
|
|
|
Verbatim->Children.back()->Text = " The description continues.";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *ParamOut = Top.Children.back().get();
|
|
|
|
ParamOut->Kind = "ParamCommandComment";
|
|
|
|
ParamOut->Direction = "[out]";
|
|
|
|
ParamOut->ParamName = "I";
|
|
|
|
ParamOut->Explicit = true;
|
2019-08-15 07:52:23 +08:00
|
|
|
ParamOut->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
ParamOut->Children.back()->Kind = "ParagraphComment";
|
|
|
|
ParamOut->Children.back()->Children.emplace_back(
|
2019-08-15 07:52:23 +08:00
|
|
|
std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
ParamOut->Children.back()->Children.back()->Kind = "TextComment";
|
|
|
|
ParamOut->Children.back()->Children.emplace_back(
|
2019-08-15 07:52:23 +08:00
|
|
|
std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
ParamOut->Children.back()->Children.back()->Kind = "TextComment";
|
|
|
|
ParamOut->Children.back()->Children.back()->Text = " is a parameter.";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *ParamIn = Top.Children.back().get();
|
|
|
|
ParamIn->Kind = "ParamCommandComment";
|
|
|
|
ParamIn->Direction = "[in]";
|
|
|
|
ParamIn->ParamName = "J";
|
2019-08-15 07:52:23 +08:00
|
|
|
ParamIn->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
ParamIn->Children.back()->Kind = "ParagraphComment";
|
|
|
|
ParamIn->Children.back()->Children.emplace_back(
|
2019-08-15 07:52:23 +08:00
|
|
|
std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
ParamIn->Children.back()->Children.back()->Kind = "TextComment";
|
|
|
|
ParamIn->Children.back()->Children.back()->Text = " is a parameter.";
|
|
|
|
ParamIn->Children.back()->Children.emplace_back(
|
2019-08-15 07:52:23 +08:00
|
|
|
std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
ParamIn->Children.back()->Children.back()->Kind = "TextComment";
|
|
|
|
|
2019-08-15 07:52:23 +08:00
|
|
|
Top.Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
CommentInfo *Return = Top.Children.back().get();
|
|
|
|
Return->Kind = "BlockCommandComment";
|
|
|
|
Return->Name = "return";
|
|
|
|
Return->Explicit = true;
|
2019-08-15 07:52:23 +08:00
|
|
|
Return->Children.emplace_back(std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
Return->Children.back()->Kind = "ParagraphComment";
|
|
|
|
Return->Children.back()->Children.emplace_back(
|
2019-08-15 07:52:23 +08:00
|
|
|
std::make_unique<CommentInfo>());
|
2018-10-17 07:07:16 +08:00
|
|
|
Return->Children.back()->Children.back()->Kind = "TextComment";
|
|
|
|
Return->Children.back()->Children.back()->Text = "void";
|
|
|
|
|
|
|
|
I.Description.emplace_back(std::move(Top));
|
|
|
|
|
|
|
|
auto G = getYAMLGenerator();
|
|
|
|
assert(G);
|
|
|
|
std::string Buffer;
|
|
|
|
llvm::raw_string_ostream Actual(Buffer);
|
2019-07-26 06:46:40 +08:00
|
|
|
auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
|
2018-10-17 07:07:16 +08:00
|
|
|
assert(!Err);
|
|
|
|
std::string Expected =
|
|
|
|
R"raw(---
|
|
|
|
USR: '0000000000000000000000000000000000000000'
|
|
|
|
Name: 'f'
|
2019-07-12 14:01:37 +08:00
|
|
|
Description:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'FullComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: ' Brief description.'
|
|
|
|
Name: 'ParagraphComment'
|
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: ' Extended description that'
|
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: ' continues onto the next line.'
|
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
- Kind: 'HTMLStartTagComment'
|
|
|
|
Name: 'ul'
|
2019-07-12 14:01:37 +08:00
|
|
|
AttrKeys:
|
2018-10-17 07:07:16 +08:00
|
|
|
- 'class'
|
2019-07-12 14:01:37 +08:00
|
|
|
AttrValues:
|
2018-10-17 07:07:16 +08:00
|
|
|
- 'test'
|
|
|
|
- Kind: 'HTMLStartTagComment'
|
|
|
|
Name: 'li'
|
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: ' Testing.'
|
|
|
|
- Kind: 'HTMLEndTagComment'
|
|
|
|
Name: 'ul'
|
|
|
|
SelfClosing: true
|
|
|
|
- Kind: 'VerbatimBlockComment'
|
|
|
|
Name: 'verbatim'
|
|
|
|
CloseName: 'endverbatim'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'VerbatimBlockLineComment'
|
|
|
|
Text: ' The description continues.'
|
|
|
|
- Kind: 'ParamCommandComment'
|
|
|
|
Direction: '[out]'
|
|
|
|
ParamName: 'I'
|
|
|
|
Explicit: true
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: ' is a parameter.'
|
|
|
|
- Kind: 'ParamCommandComment'
|
|
|
|
Direction: '[in]'
|
|
|
|
ParamName: 'J'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: ' is a parameter.'
|
|
|
|
- Kind: 'TextComment'
|
|
|
|
- Kind: 'BlockCommandComment'
|
|
|
|
Name: 'return'
|
|
|
|
Explicit: true
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'ParagraphComment'
|
2019-07-12 14:01:37 +08:00
|
|
|
Children:
|
2018-10-17 07:07:16 +08:00
|
|
|
- Kind: 'TextComment'
|
|
|
|
Text: 'void'
|
2019-07-12 14:01:37 +08:00
|
|
|
DefLocation:
|
2018-10-17 07:07:16 +08:00
|
|
|
LineNumber: 10
|
|
|
|
Filename: 'test.cpp'
|
2019-07-12 14:01:37 +08:00
|
|
|
Params:
|
|
|
|
- Type:
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'int'
|
|
|
|
Name: 'I'
|
2019-07-12 14:01:37 +08:00
|
|
|
- Type:
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'int'
|
|
|
|
Name: 'J'
|
2019-07-12 14:01:37 +08:00
|
|
|
ReturnType:
|
|
|
|
Type:
|
2018-10-17 07:07:16 +08:00
|
|
|
Name: 'void'
|
|
|
|
...
|
|
|
|
)raw";
|
|
|
|
|
|
|
|
EXPECT_EQ(Expected, Actual.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace doc
|
|
|
|
} // namespace clang
|