11#include "clang/Basic/CommentOptions.h"
12#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/raw_ostream.h"
14#include "gtest/gtest.h"
19TEST(SymbolDocumentation, DetailedDocToMarkup) {
21 CommentOptions CommentOpts;
24 llvm::StringRef Documentation;
25 llvm::StringRef ExpectedRenderEscapedMarkdown;
26 llvm::StringRef ExpectedRenderMarkdown;
27 llvm::StringRef ExpectedRenderPlainText;
36 "brief\n\nfoo\nbar\n",
42 "brief\n\nfoo\n\nbar\n",
48 "brief\n\nfoo \\p bar baz",
54 "brief\n\nfoo \\e bar baz",
60 "brief\n\nfoo \\b bar baz",
61 "foo \\*\\*bar\\*\\* baz",
66 "brief\n\nfoo \\ref bar baz",
67 "foo \\*\\*\\\\ref\\*\\* `bar` baz",
68 "foo **\\ref** `bar` baz",
69 "foo **\\ref** bar baz",
72 "brief\n\nfoo @ref bar baz",
73 "foo \\*\\*@ref\\*\\* `bar` baz",
74 "foo **@ref** `bar` baz",
75 "foo **@ref** bar baz",
78 "\\brief this is a \\n\nbrief description",
84 "brief\n\n\\throw exception foo",
85 "\\*\\*\\\\throw\\*\\* `exception` foo",
86 "**\\throw** `exception` foo",
87 "**\\throw** exception foo",
90 R
"(\brief this is a brief description
112 "brief\n\n\\defgroup mygroup this is a group\nthis is not a group "
114 "\\*\\*@defgroup\\*\\* `mygroup this is a group`\n\nthis is not a "
117 "**@defgroup** `mygroup this is a group`\n\nthis is not a group "
119 "**@defgroup** `mygroup this is a group`\n\nthis is not a group "
127verbatim block containing
134verbatim block containing
138\*\*@endverbatim\*\*)",
143verbatim block containing
151verbatim block containing
157 "brief\n\n@param foo this is a parameter\n@param bar this is another "
166@param foo this is a parameter
170\details these are details
174 R"(\*\*\\brief\*\* another brief?
178More description documentation)",
179 R"(**\brief** another brief?
185 R"(**\brief** another brief?
189More description documentation)",
194<b>this is a bold text</b>
195normal text<i>this is an italic text</i>
196<code>this is a code block</code>)",
197 R"(<b>this is a bold text</b> normal text<i>this is an italic text</i>
198<code>this is a code block</code>)",
199 R"(<b>this is a bold text</b>
200normal text<i>this is an italic text</i>
201<code>this is a code block</code>)",
202 "<b>this is a bold text</b> normal text<i>this is an italic text</i> "
203 "<code>this is a code block</code>",
205 {
"brief\n\n@note This is a note",
236 {"brief\n\n@warning This is a warning",
246@warning This is a warning
267 {R"(@note this is not treated as brief
269@brief this is the brief
273this is not treated as brief
277this is not treated as brief
281this is not treated as brief
293 for (
const auto &C : Cases) {
294 markup::Document Doc;
297 SymbolDoc.detailedDocToMarkup(Doc);
299 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
300 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
301 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
305TEST(SymbolDocumentation, RetvalCommand) {
307 CommentOptions CommentOpts;
310 llvm::StringRef Documentation;
311 llvm::StringRef ExpectedRenderEscapedMarkdown;
312 llvm::StringRef ExpectedRenderMarkdown;
313 llvm::StringRef ExpectedRenderPlainText;
315 {
"@retval",
"",
"",
""},
316 {R
"(@retval MyReturnVal
317@retval MyOtherReturnVal)",
319- `MyOtherReturnVal`)",
321- `MyOtherReturnVal`)",
323- MyOtherReturnVal)"},
324 {R"(@retval MyReturnVal if foo
325@retval MyOtherReturnVal if bar)",
326 R"(- `MyReturnVal` - if foo
327- `MyOtherReturnVal` - if bar)",
328 R"(- `MyReturnVal` - if foo
329- `MyOtherReturnVal` - if bar)",
330 R"(- MyReturnVal - if foo
331- MyOtherReturnVal - if bar)"},
333 for (
const auto &C : Cases) {
334 markup::Document Doc;
337 SymbolDoc.retvalsToMarkup(Doc);
339 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
340 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
341 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
345TEST(SymbolDocumentation, DoxygenCodeBlocks) {
346 CommentOptions CommentOpts;
349 llvm::StringRef Documentation;
350 llvm::StringRef ExpectedRenderEscapedMarkdown;
351 llvm::StringRef ExpectedRenderMarkdown;
352 llvm::StringRef ExpectedRenderPlainText;
355int code() { return 0; }
358int code_lang() { return 0; }
361int code_lang_plus() { return 0; }
372int code() { return 0; }
376int code_lang() { return 0; }
380int code_lang_plus() { return 0; }
393int code() { return 0; }
397int code_lang() { return 0; }
401int code_lang_plus() { return 0; }
413 R"(int code() { return 0; }
415int code_lang() { return 0; }
417int code_lang_plus() { return 0; }
425 for (
const auto &C : Cases) {
426 markup::Document Doc;
427 SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts);
429 SymbolDoc.detailedDocToMarkup(Doc);
431 EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText);
432 EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown);
433 EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown);
437TEST(SymbolDocumentation, MarkdownCodeBlocks) {
438 CommentOptions CommentOpts;
441 llvm::StringRef Documentation;
442 llvm::StringRef ExpectedRenderEscapedMarkdown;
443 llvm::StringRef ExpectedRenderMarkdown;
444 llvm::StringRef ExpectedRenderPlainText;
447int backticks() { return 0; }
450int backticks_lang() { return 0; }
453int backticks_lang_plus() { return 0; }
456int tilde() { return 0; }
458~~~~~~~~~~~~~~~~~~~~~~~~
459int tilde_many() { return 0; }
460~~~~~~~~~~~~~~~~~~~~~~~~
461~~~~~~~~~~~~~~~~~~~~~~~~{.c++}
462int tilde_many_lang() { return 0; }
463~~~~~~~~~~~~~~~~~~~~~~~~
478int backticks() { return 0; }
482int backticks_lang() { return 0; }
486int backticks_lang_plus() { return 0; }
490int tilde() { return 0; }
494int tilde_many() { return 0; }
498int tilde_many_lang() { return 0; }
516int backticks() { return 0; }
520int backticks_lang() { return 0; }
524int backticks_lang_plus() { return 0; }
528int tilde() { return 0; }
532int tilde_many() { return 0; }
536int tilde_many_lang() { return 0; }
553 R"(int backticks() { return 0; }
555int backticks_lang() { return 0; }
557int backticks_lang_plus() { return 0; }
559int tilde() { return 0; }
561int tilde_many() { return 0; }
563int tilde_many_lang() { return 0; }
574// this code block is missing end backticks
578// this code block is missing end backticks
581// this code block is missing end backticks
583 R"(// this code block is missing end backticks)"},
585 for (
const auto &C : Cases) {
586 markup::Document Doc;
589 SymbolDoc.detailedDocToMarkup(Doc);
591 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
592 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
593 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
597TEST(SymbolDocumentation, MarkdownCodeBlocksSeparation) {
598 CommentOptions CommentOpts;
601 llvm::StringRef Documentation;
602 llvm::StringRef ExpectedRenderEscapedMarkdown;
603 llvm::StringRef ExpectedRenderMarkdown;
604 llvm::StringRef ExpectedRenderPlainText;
606 {R
"(@note Show that code blocks are correctly separated
612int function() { return 0; }
615Show that code blocks are correctly separated
622int function() { return 0; }
625Show that code blocks are correctly separated
632int function() { return 0; }
635Show that code blocks are correctly separated
641int function() { return 0; })"},
642 {R
"(@note Show that code blocks are correctly separated
648int function() { return 0; }
651Show that code blocks are correctly separated
658int function() { return 0; }
661Show that code blocks are correctly separated
668int function() { return 0; }
671Show that code blocks are correctly separated
677int function() { return 0; })"},
679 for (
const auto &C : Cases) {
680 markup::Document Doc;
683 SymbolDoc.detailedDocToMarkup(Doc);
685 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
686 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
687 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
691TEST(SymbolDocumentation, MarkdownCodeSpans) {
692 CommentOptions CommentOpts;
695 llvm::StringRef Documentation;
696 llvm::StringRef ExpectedRenderEscapedMarkdown;
697 llvm::StringRef ExpectedRenderMarkdown;
698 llvm::StringRef ExpectedRenderPlainText;
700 {R
"(`this is a code span with @p and \c inside`)",
701 R"(\`this is a code span with @p and \\c inside\`)",
702 R"(`this is a code span with @p and \c inside`)",
703 R"(`this is a code span with @p and \c inside`)"},
704 {R"(<escaped> `<not-escaped>`)", R"(<escaped> \`<not-escaped>\`)",
705 R"(<escaped> `<not-escaped>`)", R"(<escaped> `<not-escaped>`)"},
706 {R"(<escaped> \`<escaped> doxygen commands not parsed @p, \c, @note, \warning \`)",
707 R"(<escaped> \\\`<escaped> doxygen commands not parsed @p, \\c, @note, \\warning \\\`)",
708 R"(<escaped> \`<escaped> doxygen commands not parsed @p, \c, @note, \warning \`)",
709 R"(<escaped> \`<escaped> doxygen commands not parsed @p, \c, @note, \warning \`)"},
721 for (
const auto &C : Cases) {
722 markup::Document Doc;
725 SymbolDoc.briefToMarkup(Doc.addParagraph());
727 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
728 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
729 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
733TEST(SymbolDocumentation, ParameterDocToString) {
734 CommentOptions CommentOpts;
737 llvm::StringRef Documentation;
738 llvm::StringRef ExpectedOutputString;
739 llvm::StringRef ParameterName;
741 {
"This documentation does not contain parameter docs",
"",
"a"},
742 {
"@param a this is a parameter",
"",
"not_exists"},
743 {
"@param a this is a parameter",
" this is a parameter",
"a"},
744 {R
"(@param a parameter doc with an \p inline command)",
745 R"( parameter doc with an \p inline command)", "a"},
746 {R
"(@param a parameter doc with an \unknown command)",
747 R"( parameter doc with an \unknown command)", "a"},
748 {
"@param a parameter doc with an @unknown command",
749 " parameter doc with an @unknown command",
"a"},
750 {R
"(@param a parameter doc with
752 R"( parameter doc with
755 {R
"(@param a parameter doc with an
756@unknown command starting a new line)",
757 R"( parameter doc with an
758@unknown command starting a new line)",
760 {R
"(@param a parameter doc with a
761@note command which is a new block command and therefore ends the parameter doc paragraph)",
762 R"( parameter doc with a
766@param a parameter doc
768New paragraph with unrelated docs)",
769 " parameter doc",
"a"},
771 for (
const auto &C : Cases) {
773 llvm::raw_string_ostream OS(Result);
776 SymbolDoc.parameterDocToString(
C.ParameterName, OS);
778 EXPECT_EQ(Result,
C.ExpectedOutputString);
782TEST(SymbolDocumentation, TemplateParameterDocToString) {
783 CommentOptions CommentOpts;
786 llvm::StringRef Documentation;
787 llvm::StringRef ExpectedOutputString;
788 llvm::StringRef TemplateParameterName;
790 {
"This documentation does not contain parameter docs",
"",
"a"},
791 {
"@tparam a this is a template type parameter",
"",
"not_exists"},
792 {
"@tparam a this is a template type parameter",
793 " this is a template type parameter",
"a"},
794 {R
"(@tparam a template type parameter doc with an \p inline command)",
795 R"( template type parameter doc with an \p inline command)", "a"},
796 {R
"(@tparam a template type parameter doc with an \unknown command)",
797 R"( template type parameter doc with an \unknown command)", "a"},
798 {
"@tparam a template type parameter doc with an @unknown command",
799 " template type parameter doc with an @unknown command",
"a"},
800 {R
"(@tparam a template type parameter doc with
802 R"( template type parameter doc with
805 {R
"(@tparam a template type parameter doc with an
806@unknown command starting a new line)",
807 R"( template type parameter doc with an
808@unknown command starting a new line)",
810 {R
"(@tparam a template type parameter doc with a
811@note command which is a new block command and therefore ends the template type parameter doc paragraph)",
812 R"( template type parameter doc with a
816@tparam a template type parameter doc
818New paragraph with unrelated docs)",
819 " template type parameter doc",
"a"},
821 for (
const auto &C : Cases) {
823 llvm::raw_string_ostream OS(Result);
826 SymbolDoc.templateTypeParmDocToString(
C.TemplateParameterName, OS);
828 EXPECT_EQ(Result,
C.ExpectedOutputString);
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
TEST(BackgroundQueueTest, Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//