1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file LICENSE.rst or https://cmake.org/licensing for details. */
#include <sstream>
#include <string>
#include <utility>
#include <cmDocumentationFormatter.h>
#include "testCommon.h"
namespace {
using TestCases = std::initializer_list<std::pair<std::string, std::string>>;
bool testPrintFormattedNoIndent()
{
TestCases const 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" },
{ "Just one a very long word: "
"01234567890123456789012345678901234567890123456789012345"
"678901234567890123456789",
"Just one a very long "
"word:\n01234567890123456789012345678901234567890123456789012345"
"678901234567890123456789\n" },
{ " Pre-formatted paragraph with the very long word stays the same: "
"0123456789012345678901234567890123456789012345678901234567890123456789",
" 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",
"Extra spaces are removed. However,\n\n not in a pre-formatted\n "
"paragraph\n" },
{ "This is the text paragraph longer than a pre-defined wrapping position "
"of the `cmDocumentationFormatter` class. And it's gonna be wrapped "
"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" },
{ "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;
for (auto& test : testCases) {
std::ostringstream out;
formatter.PrintFormatted(out, test.first);
auto actual = out.str();
ASSERT_EQUAL(actual, test.second);
}
return true;
}
bool testPrintFormattedIndent2()
{
TestCases const testCases = {
{ "", "" },
// BEGIN NOTE Empty lines are not indented.
{ "\n\n", "\n\n\n\n" },
{ "\n \n\n", "\n\n \n\n\n\n" },
// END NOTE
{ "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",
" Short text\n\n on\n\n multiple\n\n lines\n\n" },
{ "Just one a very long word: "
"01234567890123456789012345678901234567890123456789012345"
"678901234567890123456789",
" Just one a very long "
"word:\n 01234567890123456789012345678901234567890123456789012345"
"678901234567890123456789\n" },
{ " Pre-formatted paragraph with the very long word stays the same: "
"0123456789012345678901234567890123456789012345678901234567890123456789",
" Pre-formatted paragraph with the very long word stays the same: "
"0123456789012345678901234567890123456789012345678901234567890123456789"
"\n" },
{ "Extra spaces are removed. However, \n not in a "
"pre-formatted\n "
"paragraph",
" Extra spaces are removed. However,\n\n not in a "
"pre-formatted\n "
"paragraph\n" },
{ "This is the text paragraph longer than a pre-defined wrapping position "
"of the `cmDocumentationFormatter` class. And it's gonna be wrapped "
"over multiple lines!",
" 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" },
{ "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;
formatter.SetIndent(2);
for (auto& test : testCases) {
std::ostringstream out;
formatter.PrintFormatted(out, test.first);
auto actual = out.str();
ASSERT_EQUAL(actual, test.second);
}
return true;
}
bool testPrintFormattedIndent10()
{
TestCases const testCases = {
{ "", "" },
{ "One line no EOL text", " One line no EOL text\n" },
{ "This is the text paragraph longer than a pre-defined wrapping position "
"of the `cmDocumentationFormatter` class. And it's gonna be wrapped "
"over multiple lines!",
" This is the text paragraph longer than a pre-defined "
"wrapping\n"
" position of the `cmDocumentationFormatter` class. "
"And it's gonna\n"
" be wrapped over multiple lines!\n" }
};
cmDocumentationFormatter formatter;
formatter.SetIndent(10);
for (auto& test : testCases) {
std::ostringstream out;
formatter.PrintFormatted(out, test.first);
auto actual = out.str();
ASSERT_EQUAL(actual, test.second);
}
return true;
}
}
int testDocumentationFormatter(int /*unused*/, char* /*unused*/[])
{
return runTests({ testPrintFormattedNoIndent, testPrintFormattedIndent2,
testPrintFormattedIndent10 },
false);
}
|