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?
180 R"(**\brief** another brief?
186 R"(**\brief** another brief?
190More description documentation)",
195<b>this is a bold text</b>
196normal text<i>this is an italic text</i>
197<code>this is a code block</code>)",
198 R"(<b>this is a bold text</b>
199normal text<i>this is an italic text</i>
200<code>this is a code block</code>)",
201 R"(<b>this is a bold text</b>
202normal text<i>this is an italic text</i>
203<code>this is a code block</code>)",
204 "<b>this is a bold text</b> normal text<i>this is an italic text</i> "
205 "<code>this is a code block</code>",
207 {
"brief\n\n@note This is a note",
238 {"brief\n\n@warning This is a warning",
248@warning This is a warning
269 {R"(@note this is not treated as brief
271@brief this is the brief
275this is not treated as brief
279this is not treated as brief
283this is not treated as brief
295 for (
const auto &C : Cases) {
296 markup::Document Doc;
299 SymbolDoc.detailedDocToMarkup(Doc);
301 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
302 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
303 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
307TEST(SymbolDocumentation, RetvalCommand) {
309 CommentOptions CommentOpts;
312 llvm::StringRef Documentation;
313 llvm::StringRef ExpectedRenderEscapedMarkdown;
314 llvm::StringRef ExpectedRenderMarkdown;
315 llvm::StringRef ExpectedRenderPlainText;
317 {
"@retval",
"",
"",
""},
318 {R
"(@retval MyReturnVal
319@retval MyOtherReturnVal)",
321- `MyOtherReturnVal`)",
323- `MyOtherReturnVal`)",
325- MyOtherReturnVal)"},
326 {R"(@retval MyReturnVal if foo
327@retval MyOtherReturnVal if bar)",
328 R"(- `MyReturnVal` - if foo
329- `MyOtherReturnVal` - if bar)",
330 R"(- `MyReturnVal` - if foo
331- `MyOtherReturnVal` - if bar)",
332 R"(- MyReturnVal - if foo
333- MyOtherReturnVal - if bar)"},
335 for (
const auto &C : Cases) {
336 markup::Document Doc;
339 SymbolDoc.retvalsToMarkup(Doc);
341 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
342 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
343 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
347TEST(SymbolDocumentation, DoxygenCodeBlocks) {
348 CommentOptions CommentOpts;
351 llvm::StringRef Documentation;
352 llvm::StringRef ExpectedRenderEscapedMarkdown;
353 llvm::StringRef ExpectedRenderMarkdown;
354 llvm::StringRef ExpectedRenderPlainText;
357int code() { return 0; }
360int code_lang() { return 0; }
363int code_lang_plus() { return 0; }
374int code() { return 0; }
378int code_lang() { return 0; }
382int code_lang_plus() { return 0; }
395int code() { return 0; }
399int code_lang() { return 0; }
403int code_lang_plus() { return 0; }
415 R"(int code() { return 0; }
417int code_lang() { return 0; }
419int code_lang_plus() { return 0; }
427 for (
const auto &C : Cases) {
428 markup::Document Doc;
429 SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts);
431 SymbolDoc.detailedDocToMarkup(Doc);
433 EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText);
434 EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown);
435 EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown);
439TEST(SymbolDocumentation, MarkdownCodeBlocks) {
440 CommentOptions CommentOpts;
443 llvm::StringRef Documentation;
444 llvm::StringRef ExpectedRenderEscapedMarkdown;
445 llvm::StringRef ExpectedRenderMarkdown;
446 llvm::StringRef ExpectedRenderPlainText;
449int backticks() { return 0; }
452int backticks_lang() { return 0; }
455int backticks_lang_plus() { return 0; }
458int tilde() { return 0; }
460~~~~~~~~~~~~~~~~~~~~~~~~
461int tilde_many() { return 0; }
462~~~~~~~~~~~~~~~~~~~~~~~~
463~~~~~~~~~~~~~~~~~~~~~~~~{.c++}
464int tilde_many_lang() { return 0; }
465~~~~~~~~~~~~~~~~~~~~~~~~
480int backticks() { return 0; }
484int backticks_lang() { return 0; }
488int backticks_lang_plus() { return 0; }
492int tilde() { return 0; }
496int tilde_many() { return 0; }
500int tilde_many_lang() { return 0; }
518int backticks() { return 0; }
522int backticks_lang() { return 0; }
526int backticks_lang_plus() { return 0; }
530int tilde() { return 0; }
534int tilde_many() { return 0; }
538int tilde_many_lang() { return 0; }
555 R"(int backticks() { return 0; }
557int backticks_lang() { return 0; }
559int backticks_lang_plus() { return 0; }
561int tilde() { return 0; }
563int tilde_many() { return 0; }
565int tilde_many_lang() { return 0; }
576// this code block is missing end backticks
580// this code block is missing end backticks
583// this code block is missing end backticks
585 R"(// this code block is missing end backticks)"},
587 for (
const auto &C : Cases) {
588 markup::Document Doc;
591 SymbolDoc.detailedDocToMarkup(Doc);
593 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
594 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
595 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
599TEST(SymbolDocumentation, MarkdownCodeBlocksSeparation) {
600 CommentOptions CommentOpts;
603 llvm::StringRef Documentation;
604 llvm::StringRef ExpectedRenderEscapedMarkdown;
605 llvm::StringRef ExpectedRenderMarkdown;
606 llvm::StringRef ExpectedRenderPlainText;
608 {R
"(@note Show that code blocks are correctly separated
614int function() { return 0; }
617Show that code blocks are correctly separated
624int function() { return 0; }
627Show that code blocks are correctly separated
634int function() { return 0; }
637Show that code blocks are correctly separated
643int function() { return 0; })"},
644 {R
"(@note Show that code blocks are correctly separated
650int function() { return 0; }
653Show that code blocks are correctly separated
660int function() { return 0; }
663Show that code blocks are correctly separated
670int function() { return 0; }
673Show that code blocks are correctly separated
679int function() { return 0; })"},
681 for (
const auto &C : Cases) {
682 markup::Document Doc;
685 SymbolDoc.detailedDocToMarkup(Doc);
687 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
688 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
689 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
693TEST(SymbolDocumentation, MarkdownCodeSpans) {
694 CommentOptions CommentOpts;
697 llvm::StringRef Documentation;
698 llvm::StringRef ExpectedRenderEscapedMarkdown;
699 llvm::StringRef ExpectedRenderMarkdown;
700 llvm::StringRef ExpectedRenderPlainText;
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"(`this is a code span with @p and \c inside`)",
705 R"(`this is a code span with @p and \c inside`)"},
706 {R"(<escaped> `<not-escaped>`)", R"(<escaped> \`<not-escaped>\`)",
707 R"(<escaped> `<not-escaped>`)", R"(<escaped> `<not-escaped>`)"},
708 {R"(<escaped> \`<escaped> doxygen commands not parsed @p, \c, @note, \warning \`)",
709 R"(<escaped> \\\`<escaped> doxygen commands not parsed @p, \\c, @note, \\warning \\\`)",
710 R"(<escaped> \`<escaped> doxygen commands not parsed @p, \c, @note, \warning \`)",
711 R"(<escaped> \`<escaped> doxygen commands not parsed @p, \c, @note, \warning \`)"},
724 for (
const auto &C : Cases) {
725 markup::Document Doc;
728 SymbolDoc.briefToMarkup(Doc.addParagraph());
730 EXPECT_EQ(Doc.asPlainText(),
C.ExpectedRenderPlainText);
731 EXPECT_EQ(Doc.asMarkdown(),
C.ExpectedRenderMarkdown);
732 EXPECT_EQ(Doc.asEscapedMarkdown(),
C.ExpectedRenderEscapedMarkdown);
736TEST(SymbolDocumentation, ParameterDocToString) {
737 CommentOptions CommentOpts;
740 llvm::StringRef Documentation;
741 llvm::StringRef ExpectedOutputString;
742 llvm::StringRef ParameterName;
744 {
"This documentation does not contain parameter docs",
"",
"a"},
745 {
"@param a this is a parameter",
"",
"not_exists"},
746 {
"@param a this is a parameter",
" this is a parameter",
"a"},
747 {R
"(@param a parameter doc with an \p inline command)",
748 R"( parameter doc with an \p inline command)", "a"},
749 {R
"(@param a parameter doc with an \unknown command)",
750 R"( parameter doc with an \unknown command)", "a"},
751 {
"@param a parameter doc with an @unknown command",
752 " parameter doc with an @unknown command",
"a"},
753 {R
"(@param a parameter doc with
755 R"( parameter doc with
758 {R
"(@param a parameter doc with an
759@unknown command starting a new line)",
760 R"( parameter doc with an
761@unknown command starting a new line)",
763 {R
"(@param a parameter doc with a
764@note command which is a new block command and therefore ends the parameter doc paragraph)",
765 R"( parameter doc with a
769@param a parameter doc
771New paragraph with unrelated docs)",
772 " parameter doc",
"a"},
774 for (
const auto &C : Cases) {
776 llvm::raw_string_ostream OS(Result);
779 SymbolDoc.parameterDocToString(
C.ParameterName, OS);
781 EXPECT_EQ(Result,
C.ExpectedOutputString);
785TEST(SymbolDocumentation, TemplateParameterDocToString) {
786 CommentOptions CommentOpts;
789 llvm::StringRef Documentation;
790 llvm::StringRef ExpectedOutputString;
791 llvm::StringRef TemplateParameterName;
793 {
"This documentation does not contain parameter docs",
"",
"a"},
794 {
"@tparam a this is a template type parameter",
"",
"not_exists"},
795 {
"@tparam a this is a template type parameter",
796 " this is a template type parameter",
"a"},
797 {R
"(@tparam a template type parameter doc with an \p inline command)",
798 R"( template type parameter doc with an \p inline command)", "a"},
799 {R
"(@tparam a template type parameter doc with an \unknown command)",
800 R"( template type parameter doc with an \unknown command)", "a"},
801 {
"@tparam a template type parameter doc with an @unknown command",
802 " template type parameter doc with an @unknown command",
"a"},
803 {R
"(@tparam a template type parameter doc with
805 R"( template type parameter doc with
808 {R
"(@tparam a template type parameter doc with an
809@unknown command starting a new line)",
810 R"( template type parameter doc with an
811@unknown command starting a new line)",
813 {R
"(@tparam a template type parameter doc with a
814@note command which is a new block command and therefore ends the template type parameter doc paragraph)",
815 R"( template type parameter doc with a
819@tparam a template type parameter doc
821New paragraph with unrelated docs)",
822 " template type parameter doc",
"a"},
824 for (
const auto &C : Cases) {
826 llvm::raw_string_ostream OS(Result);
829 SymbolDoc.templateTypeParmDocToString(
C.TemplateParameterName, OS);
831 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++ -*-===//