From ef88ec41f3264fb62ad1b540e104ab477b0abd01 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 2 Nov 2024 07:14:10 +0400 Subject: [PATCH] testDocumentationFormatter: Add some more test cases --- Tests/CMakeLib/testDocumentationFormatter.cxx | 58 ++++++++++++++++--- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/Tests/CMakeLib/testDocumentationFormatter.cxx b/Tests/CMakeLib/testDocumentationFormatter.cxx index 6f59b1d190..71d4e1eb45 100644 --- a/Tests/CMakeLib/testDocumentationFormatter.cxx +++ b/Tests/CMakeLib/testDocumentationFormatter.cxx @@ -10,14 +10,17 @@ #include "testCommon.h" namespace { -using TestCases = - const std::initializer_list>; +using TestCases = std::initializer_list>; 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;