testDocumentationFormatter: Add some more test cases

This commit is contained in:
Alex Turbov committed 2024-11-07 20:08:37 +04:00
1 parent 8353e6ab8d
commit ef88ec41f3
1 file changed
+51 -7
+51 -7
View File
@@ -10,14 +10,17 @@
#include "testCommon.h"
namespace {
using TestCases =
const std::initializer_list<std::pair<std::string, std::string>>;
using TestCases = std::initializer_list<std::pair<std::string, std::string>>;
bool testPrintFormattedNoIndent()
{
const TestCases testCases = {
{ "", "" },
{ "\n\n", "\n\n\n\n" },
{ "\n \n\n", "\n\n \n\n\n\n" },
{ "One line no EOL text", "One line no EOL text\n" },
{ "One line with trailing spaces and no EOL ",
"One line with trailing spaces and no EOL\n" },
{ "Short text. Two sentences.", "Short text. Two sentences.\n" },
{ "Short text\non\nmultiple\nlines\n",
"Short text\n\non\n\nmultiple\n\nlines\n\n" },
@@ -32,6 +35,10 @@ bool testPrintFormattedNoIndent()
" Pre-formatted paragraph with the very long word stays the same: "
"0123456789012345678901234567890123456789012345678901234567890123456789"
"\n" },
{ " Two pre-formatted\n paragraphs w/o EOL",
" Two pre-formatted\n paragraphs w/o EOL\n" },
{ " Two pre-formatted\n paragraphs w/ EOL\n",
" Two pre-formatted\n paragraphs w/ EOL\n\n" },
{ "Extra spaces are removed. However, \n not in a "
"pre-formatted\n "
"paragraph",
@@ -42,7 +49,24 @@ bool testPrintFormattedNoIndent()
"over multiple lines!",
"This is the text paragraph longer than a pre-defined wrapping position "
"of the\n`cmDocumentationFormatter` class. And it's gonna be wrapped "
"over multiple\nlines!\n" }
"over multiple\nlines!\n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces ",
"A normal paragraph, followed by ...\n\n Pre-formatted\n paragraphs "
"with trailing whitespaces \n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces \nAnd another paragraph w/o EOL",
"A normal paragraph, followed by ...\n\n Pre-formatted\n paragraphs "
"with trailing whitespaces \n\nAnd another paragraph w/o EOL\n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces \nAnd another paragraph w/ EOL\n",
"A normal paragraph, followed by ...\n\n Pre-formatted\n paragraphs "
"with trailing whitespaces \n\nAnd another paragraph w/ EOL\n\n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces \nAnd another two\nparagraphs w/ EOL\n",
"A normal paragraph, followed by ...\n\n Pre-formatted\n paragraphs "
"with trailing whitespaces \n\nAnd another two\n\nparagraphs w/ "
"EOL\n\n" }
};
cmDocumentationFormatter formatter;
@@ -50,7 +74,8 @@ bool testPrintFormattedNoIndent()
for (auto& test : testCases) {
std::ostringstream out;
formatter.PrintFormatted(out, test.first);
ASSERT_EQUAL(out.str(), test.second);
auto actual = out.str();
ASSERT_EQUAL(actual, test.second);
}
return true;
@@ -60,6 +85,8 @@ bool testPrintFormattedIndent2()
{
const TestCases testCases = {
{ "", "" },
{ "\n\n", " \n\n\n\n" },
{ "\n \n\n", " \n\n \n\n \n\n" },
{ "One line no EOL text", " One line no EOL text\n" },
{ "Short text. Two sentences.", " Short text. Two sentences.\n" },
{ "Short text\non\nmultiple\nlines\n",
@@ -87,7 +114,22 @@ bool testPrintFormattedIndent2()
" This is the text paragraph longer than a pre-defined wrapping "
"position of\n"
" the `cmDocumentationFormatter` class. And it's gonna be wrapped "
"over\n multiple lines!\n" }
"over\n multiple lines!\n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces ",
" A normal paragraph, followed by ...\n\n Pre-formatted\n "
"paragraphs "
"with trailing whitespaces \n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces \nAnd another paragraph w/o EOL",
" A normal paragraph, followed by ...\n\n Pre-formatted\n "
"paragraphs with trailing whitespaces \n\n And another paragraph "
"w/o EOL\n" },
{ "A normal paragraph, followed by ... \n Pre-formatted\n paragraphs "
"with trailing whitespaces \nAnd another paragraph w/ EOL\n",
" A normal paragraph, followed by ...\n\n Pre-formatted\n "
"paragraphs with trailing whitespaces \n\n And another paragraph "
"w/ EOL\n\n" }
};
cmDocumentationFormatter formatter;
@@ -96,7 +138,8 @@ bool testPrintFormattedIndent2()
for (auto& test : testCases) {
std::ostringstream out;
formatter.PrintFormatted(out, test.first);
ASSERT_EQUAL(out.str(), test.second);
auto actual = out.str();
ASSERT_EQUAL(actual, test.second);
}
return true;
@@ -123,7 +166,8 @@ bool testPrintFormattedIndent10()
for (auto& test : testCases) {
std::ostringstream out;
formatter.PrintFormatted(out, test.first);
ASSERT_EQUAL(out.str(), test.second);
auto actual = out.str();
ASSERT_EQUAL(actual, test.second);
}
return true;