61234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"@param shortName 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"@param aVeryLongName1234567890123456789012345678901234567890 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"\n" +
CODE_UNDERLINE + "Type Parameters:" + CODE_RESET + "\n" +
"T - 51234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"E - 61234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"\n" +
CODE_UNDERLINE + "Parameters:" + CODE_RESET + "\n" +
"shortName - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234\n" +
"aVeryLongName1234567890123456789012345678901234567890 - \n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"@throws ShortExcp 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"@throws aVeryLongException1234567890123456789012345678901234567890 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"\n" +
CODE_UNDERLINE + "Thrown Exceptions:" + CODE_RESET + "\n" +
"ShortExcp - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234\n" +
"aVeryLongException1234567890123456789012345678901234567890 - \n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"@return 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"\n" +
CODE_UNDERLINE + "Returns:" + CODE_RESET + "\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 \n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//handling of ,
:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234
1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234
1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"
\n" +
"for (String data : content) {\n" +
" System.err.println(data);\n" +
"}\n" +
"
\n");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234\n" +
"1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234\n" +
" for (String data : content) {\n" +
" System.err.println(data);\n" +
" }\n" +
" \n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//list handling:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"
followup" +
"" +
"- Term1
" +
"- A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234
" +
"- Term2" +
"
- B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
"
- Term3" +
"
- C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
"
" +
"" +
"- TermUnfinished" +
"
followup");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
" * A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234\n" +
" * B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234\n" +
" * C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234\n" +
" 1. D 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234\n" +
" 2. E 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234\n" +
" * F 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234\n" +
" 1. G 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" * H 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234\n" +
" * I 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234\n" +
"followup\n" +
CODE_HIGHLIGHT + "Term1" + CODE_RESET + "\n" +
" A 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
CODE_HIGHLIGHT + "Term2" + CODE_RESET + "\n" +
" B 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
CODE_HIGHLIGHT + "Term3" + CODE_RESET + "\n" +
" C 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
CODE_HIGHLIGHT + "TermUnfinished" + CODE_RESET + "\n" +
"followup\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//sections:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"text 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234
" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"text 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"\n" +
CODE_UNDERLINE + "1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234" + CODE_RESET + "\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
"1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//table:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"" +
"" +
"A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"
" +
"" +
"A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | \n" +
"B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" | C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" |
" +
"A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"
" +
"" +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 | " +
"
");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"----------------------------------------------------------------\n" +
"| " + CODE_HIGHLIGHT + "A 1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "B 1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "C 1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
"| " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " |\n" +
"----------------------------------------------------------------\n" +
"| A 1234 1234 1234 | B 1234 1234 1234 | C 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 | 1234 1234 | 1234 1234 |\n" +
"----------------------------------------------------------------\n" +
"| A 1234 1234 1234 | B 1234 1234 1234 | C 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 | 1234 1234 | 1234 1234 |\n" +
"----------------------------------------------------------------\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
"| 1234 1234 | 1234 1234 |\n" +
"-------------------------------------------\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//no escape sequences:
actual = new JavadocFormatter(66, false).formatJavadoc("test",
"@param shortName 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
"@param aVeryLongName1234567890123456789012345678901234567890 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
expected = "test\n" +
"\n" +
"Parameters:\n" +
"shortName - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234\n" +
"aVeryLongName1234567890123456789012345678901234567890 - \n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//null javadoc:
actual = new JavadocFormatter(66, true).formatJavadoc("test", null);
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//stray tags:
for (String tag : new String[] {"li", "ol", "h3", "table", "tr", "td", "dl", "dt", "dd"}) {
for (boolean closing : new boolean[] {false, true}) {
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"<" + (closing ? "/" : "") + tag + ">text");
if (!actual.contains("text")) {
throw new AssertionError("Incorrect output: " + actual);
}
}
}
//entities:
actual = new JavadocFormatter(66, false).formatJavadoc("test",
"α < A B > &broken; \n");
expected = "test\n" +
"\u03b1 < A B > &broken; \n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//img:
actual = new JavadocFormatter(66, true).formatJavadoc("test",
"1234 1234");
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
"1234 text 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
//unknown HTML tag:
actual = new JavadocFormatter(66, false).formatJavadoc("test",
"1234 1234 1234");
expected = "test\n" +
"1234 1234 1234\n";
if (!Objects.equals(actual, expected)) {
throw new AssertionError("Incorrect output: " + actual);
}
}
public void testSpaceAtEndOfLine() {
String header = "Class> Class.forName(Module module, String name)";
String javadoc = """
@throws SecurityException
""";
new JavadocFormatter(60, true).formatJavadoc(header, javadoc);
}
}