[PATCH] D53085: [clang-doc] Add unit tests for Markdown
This revision was automatically updated to reflect the committed changes. Closed by commit rCTE344654: [clang-doc] Add unit tests for Markdown generation (authored by juliehockett, committed by ). Changed prior to commit: https://reviews.llvm.org/D53085?vs=169752=169911#toc Repository: rL LLVM https://reviews.llvm.org/D53085 Files: unittests/clang-doc/CMakeLists.txt unittests/clang-doc/MDGeneratorTest.cpp Index: unittests/clang-doc/CMakeLists.txt === --- unittests/clang-doc/CMakeLists.txt +++ unittests/clang-doc/CMakeLists.txt @@ -13,6 +13,7 @@ add_extra_unittest(ClangDocTests BitcodeTest.cpp ClangDocTest.cpp + MDGeneratorTest.cpp MergeTest.cpp SerializeTest.cpp YAMLGeneratorTest.cpp Index: unittests/clang-doc/MDGeneratorTest.cpp === --- unittests/clang-doc/MDGeneratorTest.cpp +++ unittests/clang-doc/MDGeneratorTest.cpp @@ -0,0 +1,361 @@ +//===-- clang-doc/MDGeneratorTest.cpp -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "ClangDocTest.h" +#include "Generators.h" +#include "Representation.h" +#include "gtest/gtest.h" + +namespace clang { +namespace doc { + +std::unique_ptr getMDGenerator() { + auto G = doc::findGeneratorByName("md"); + if (!G) +return nullptr; + return std::move(G.get()); +} + +TEST(MDGeneratorTest, emitNamespaceMD) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace", + InfoType::IT_namespace); + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# namespace Namespace + + + +## Namespaces + +ChildNamespace + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitRecordMD) { + RecordInfo I; + I.Name = "r"; + 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("int", "X", AccessSpecifier::AS_private); + I.TagType = TagTypeKind::TTK_Class; + I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); + I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); + + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# class r + +*Defined at line 10 of test.cpp* + +Inherits from F, G + + + +## Members + +private int X + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitFunctionMD) { + 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"}); + + I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + I.Params.emplace_back("int", "P"); + I.IsMethod = true; + I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(### f + +*void f(int P)* + +*Defined at line 10 of test.cpp* + +)raw"; + + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitEnumMD) { + 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;
[PATCH] D53085: [clang-doc] Add unit tests for Markdown
This revision was automatically updated to reflect the committed changes. Closed by commit rL344654: [clang-doc] Add unit tests for Markdown generation (authored by juliehockett, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D53085?vs=169752=169912#toc Repository: rL LLVM https://reviews.llvm.org/D53085 Files: clang-tools-extra/trunk/unittests/clang-doc/CMakeLists.txt clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp Index: clang-tools-extra/trunk/unittests/clang-doc/CMakeLists.txt === --- clang-tools-extra/trunk/unittests/clang-doc/CMakeLists.txt +++ clang-tools-extra/trunk/unittests/clang-doc/CMakeLists.txt @@ -13,6 +13,7 @@ add_extra_unittest(ClangDocTests BitcodeTest.cpp ClangDocTest.cpp + MDGeneratorTest.cpp MergeTest.cpp SerializeTest.cpp YAMLGeneratorTest.cpp Index: clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp === --- clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp +++ clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp @@ -0,0 +1,361 @@ +//===-- clang-doc/MDGeneratorTest.cpp -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "ClangDocTest.h" +#include "Generators.h" +#include "Representation.h" +#include "gtest/gtest.h" + +namespace clang { +namespace doc { + +std::unique_ptr getMDGenerator() { + auto G = doc::findGeneratorByName("md"); + if (!G) +return nullptr; + return std::move(G.get()); +} + +TEST(MDGeneratorTest, emitNamespaceMD) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace", + InfoType::IT_namespace); + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# namespace Namespace + + + +## Namespaces + +ChildNamespace + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitRecordMD) { + RecordInfo I; + I.Name = "r"; + 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("int", "X", AccessSpecifier::AS_private); + I.TagType = TagTypeKind::TTK_Class; + I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); + I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); + + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# class r + +*Defined at line 10 of test.cpp* + +Inherits from F, G + + + +## Members + +private int X + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitFunctionMD) { + 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"}); + + I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + I.Params.emplace_back("int", "P"); + I.IsMethod = true; + I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(### f + +*void f(int P)* + +*Defined at line 10 of test.cpp* + +)raw"; + + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitEnumMD) { + EnumInfo I; + I.Name = "e"; +
[PATCH] D53085: [clang-doc] Add unit tests for Markdown
juliehockett updated this revision to Diff 169752. juliehockett marked an inline comment as done. https://reviews.llvm.org/D53085 Files: clang-tools-extra/unittests/clang-doc/CMakeLists.txt clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp === --- /dev/null +++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp @@ -0,0 +1,361 @@ +//===-- clang-doc/MDGeneratorTest.cpp -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "ClangDocTest.h" +#include "Generators.h" +#include "Representation.h" +#include "gtest/gtest.h" + +namespace clang { +namespace doc { + +std::unique_ptr getMDGenerator() { + auto G = doc::findGeneratorByName("md"); + if (!G) +return nullptr; + return std::move(G.get()); +} + +TEST(MDGeneratorTest, emitNamespaceMD) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace", + InfoType::IT_namespace); + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# namespace Namespace + + + +## Namespaces + +ChildNamespace + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitRecordMD) { + RecordInfo I; + I.Name = "r"; + 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("int", "X", AccessSpecifier::AS_private); + I.TagType = TagTypeKind::TTK_Class; + I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); + I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); + + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# class r + +*Defined at line 10 of test.cpp* + +Inherits from F, G + + + +## Members + +private int X + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitFunctionMD) { + 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")); + + I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + I.Params.emplace_back("int", "P"); + I.IsMethod = true; + I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(### f + +*void f(int P)* + +*Defined at line 10 of test.cpp* + +)raw"; + + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitEnumMD) { + 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 = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(| enum class e | + +-- + +| X | + + +*Defined at line 10 of test.cpp* + +)raw"; + + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitCommentMD) { + FunctionInfo I; + I.Name = "f"; + I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp")); + I.ReturnType = TypeInfo(EmptySID, "void",
[PATCH] D53085: [clang-doc] Add unit tests for Markdown
phosek added inline comments. Comment at: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp:362 +} // namespace clang \ No newline at end of file Nit: this is relevant. https://reviews.llvm.org/D53085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53085: [clang-doc] Add unit tests for Markdown
juliehockett updated this revision to Diff 169221. juliehockett added a comment. Switching to raw strings. https://reviews.llvm.org/D53085 Files: clang-tools-extra/unittests/clang-doc/CMakeLists.txt clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp === --- /dev/null +++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp @@ -0,0 +1,361 @@ +//===-- clang-doc/MDGeneratorTest.cpp -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "ClangDocTest.h" +#include "Generators.h" +#include "Representation.h" +#include "gtest/gtest.h" + +namespace clang { +namespace doc { + +std::unique_ptr getMDGenerator() { + auto G = doc::findGeneratorByName("md"); + if (!G) +return nullptr; + return std::move(G.get()); +} + +TEST(MDGeneratorTest, emitNamespaceMD) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace", + InfoType::IT_namespace); + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# namespace Namespace + + + +## Namespaces + +ChildNamespace + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitRecordMD) { + RecordInfo I; + I.Name = "r"; + 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("int", "X", AccessSpecifier::AS_private); + I.TagType = TagTypeKind::TTK_Class; + I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); + I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); + + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(# class r + +*Defined at line 10 of test.cpp* + +Inherits from F, G + + + +## Members + +private int X + + + +## Records + +ChildStruct + + + +## Functions + +### OneFunction + +* OneFunction()* + + + +## Enums + +| enum OneEnum | + +-- + + + + + +)raw"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitFunctionMD) { + 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")); + + I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default); + I.Params.emplace_back("int", "P"); + I.IsMethod = true; + I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record); + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(### f + +*void f(int P)* + +*Defined at line 10 of test.cpp* + +)raw"; + + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitEnumMD) { + 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 = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = R"raw(| enum class e | + +-- + +| X | + + +*Defined at line 10 of test.cpp* + +)raw"; + + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitCommentMD) { + FunctionInfo I; + I.Name = "f"; + I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp")); + I.ReturnType = TypeInfo(EmptySID,
[PATCH] D53085: [clang-doc] Add unit tests for Markdown
phosek added inline comments. Comment at: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp:44 + assert(!Err); + std::string Expected = "# namespace Namespace\n" + "\n" Can we use the C++11 raw string literals here and below to to avoid all the escaping? https://reviews.llvm.org/D53085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53085: [clang-doc] Add unit tests for Markdown
juliehockett created this revision. juliehockett added reviewers: leonardchan, jakehehrlich, lebedev.ri. juliehockett added a project: clang-tools-extra. Herald added a subscriber: mgorny. This is part of a move to convert clang-doc's tests to a more maintainable unit test framework, with a smaller number of integration tests to maintain and more granular failure feedback. https://reviews.llvm.org/D53085 Files: clang-tools-extra/unittests/clang-doc/CMakeLists.txt clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp === --- /dev/null +++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp @@ -0,0 +1,356 @@ +//===-- clang-doc/MDGeneratorTest.cpp -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "ClangDocTest.h" +#include "Generators.h" +#include "Representation.h" +#include "gtest/gtest.h" + +namespace clang { +namespace doc { + +std::unique_ptr getMDGenerator() { + auto G = doc::findGeneratorByName("md"); + if (!G) +return nullptr; + return std::move(G.get()); +} + +TEST(MDGeneratorTest, emitNamespaceMD) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace", + InfoType::IT_namespace); + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = "# namespace Namespace\n" + "\n" + "\n" + "\n" + "## Namespaces\n" + "\n" + "ChildNamespace\n" + "\n" + "\n" + "\n" + "## Records\n" + "\n" + "ChildStruct\n" + "\n" + "\n" + "\n" + "## Functions\n" + "\n" + "### OneFunction\n" + "\n" + "* OneFunction()*\n" + "\n" + "\n" + "\n" + "## Enums\n" + "\n" + "| enum OneEnum |\n" + "\n" + "--\n" + "\n" + "\n" + "\n" + "\n" + "\n"; + EXPECT_EQ(Expected, Actual.str()); +} + +TEST(MDGeneratorTest, emitRecordMD) { + RecordInfo I; + I.Name = "r"; + 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("int", "X", AccessSpecifier::AS_private); + I.TagType = TagTypeKind::TTK_Class; + I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record); + I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record); + + I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record); + I.ChildFunctions.emplace_back(); + I.ChildFunctions.back().Name = "OneFunction"; + I.ChildEnums.emplace_back(); + I.ChildEnums.back().Name = "OneEnum"; + + auto G = getMDGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(, Actual); + assert(!Err); + std::string Expected = "# class r\n" + "\n" + "*Defined at line 10 of test.cpp*\n" + "\n" + "Inherits from F, G\n" + "\n" + "\n" + "\n" + "## Members\n" + "\n" + "private int X\n" + "\n" + "\n" + "\n" + "## Records\n" + "\n" + "ChildStruct\n" + "\n" + "\n" + "\n" +