Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/internal/shellsupport/doc/JavadocFormatterTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8131019 8169561 8261450
27
* @summary Test JavadocFormatter
28
* @library /tools/lib
29
* @modules jdk.compiler/jdk.internal.shellsupport.doc
30
* @run testng JavadocFormatterTest
31
*/
32
33
import java.util.Objects;
34
35
import jdk.internal.shellsupport.doc.JavadocFormatter;
36
import org.testng.annotations.Test;
37
38
@Test
39
public class JavadocFormatterTest {
40
41
private static final String CODE_RESET = "\033[0m";
42
private static final String CODE_HIGHLIGHT = "\033[1m";
43
private static final String CODE_UNDERLINE = "\033[4m";
44
45
public void testReflow() {
46
String actual;
47
String expected;
48
49
actual = new JavadocFormatter(25, true).formatJavadoc(
50
"test",
51
"1234 1234\n1234\n1234 12345 123456789012345678901234567890 1234 1234\n1234 {@code 1234} 1234 1234\n1234 1234 123456 123456\n<b>123456</b>\n123456 123456 {@link String string} 1");
52
53
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
54
"1234 1234 1234 1234 12345\n" +
55
"123456789012345678901234567890\n" +
56
"1234 1234 1234 1234 1234\n" +
57
"1234 1234 1234 123456\n" +
58
"123456 123456 123456\n" +
59
"123456 string 1\n";
60
61
if (!Objects.equals(actual, expected)) {
62
throw new AssertionError("Incorrect output: " + actual);
63
}
64
65
actual = new JavadocFormatter(66, true).formatJavadoc("test",
66
"@param <T> 51234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
67
"@param <E> 61234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
68
"@param shortName 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
69
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
70
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
71
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
72
"@param aVeryLongName1234567890123456789012345678901234567890 " +
73
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
74
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
75
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
76
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
77
78
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
79
"\n" +
80
CODE_UNDERLINE + "Type Parameters:" + CODE_RESET + "\n" +
81
"T - 51234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
82
"E - 61234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
83
"\n" +
84
CODE_UNDERLINE + "Parameters:" + CODE_RESET + "\n" +
85
"shortName - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
86
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
87
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
88
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
89
" 1234 1234 1234 1234\n" +
90
"aVeryLongName1234567890123456789012345678901234567890 - \n" +
91
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
92
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
93
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
94
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
95
96
if (!Objects.equals(actual, expected)) {
97
throw new AssertionError("Incorrect output: " + actual);
98
}
99
100
actual = new JavadocFormatter(66, true).formatJavadoc("test",
101
"@throws ShortExcp 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
102
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
103
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
104
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
105
"@throws aVeryLongException1234567890123456789012345678901234567890 " +
106
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
107
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
108
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
109
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
110
111
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
112
"\n" +
113
CODE_UNDERLINE + "Thrown Exceptions:" + CODE_RESET + "\n" +
114
"ShortExcp - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
115
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
116
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
117
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
118
" 1234 1234 1234 1234\n" +
119
"aVeryLongException1234567890123456789012345678901234567890 - \n" +
120
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
121
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
122
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
123
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
124
125
if (!Objects.equals(actual, expected)) {
126
throw new AssertionError("Incorrect output: " + actual);
127
}
128
actual = new JavadocFormatter(66, true).formatJavadoc("test",
129
"@return 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
130
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
131
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
132
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
133
134
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
135
"\n" +
136
CODE_UNDERLINE + "Returns:" + CODE_RESET + "\n" +
137
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
138
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
139
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
140
"1234 1234 1234 1234 1234 1234 1234 1234 1234 \n";
141
142
if (!Objects.equals(actual, expected)) {
143
throw new AssertionError("Incorrect output: " + actual);
144
}
145
146
//handling of <p>, <pre>:
147
actual = new JavadocFormatter(66, true).formatJavadoc("test",
148
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
149
"1234 1234 1234 1234 1234 <p>1234 1234 <p>1234 1234 1234 1234 1234 " +
150
"1234 1234 1234 1234 1234 1234 1234 1234 <p>1234 1234 1234 1234 " +
151
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
152
"<blockquote><pre>\n" +
153
"for (String data : content) {\n" +
154
" System.err.println(data);\n" +
155
"}\n" +
156
"</pre></blockquote>\n");
157
158
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
159
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
160
"1234 1234 1234 1234\n" +
161
"1234 1234\n" +
162
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
163
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
164
"1234 1234 1234\n" +
165
" for (String data : content) {\n" +
166
" System.err.println(data);\n" +
167
" }\n" +
168
" \n";
169
170
if (!Objects.equals(actual, expected)) {
171
throw new AssertionError("Incorrect output: " + actual);
172
}
173
174
//list handling:
175
actual = new JavadocFormatter(66, true).formatJavadoc("test",
176
"<ul>" +
177
" <li>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</li>" +
178
" <li>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
179
" <li>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234<ol>" +
180
" <li>D 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</li>" +
181
" <li>E 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234<ul>" +
182
" <li>F 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234<ol>" +
183
" <li>G 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
184
" </ol>" +
185
" </ul>" +
186
" </OL>" +
187
" <LI><p>H 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 <p>1234 1234 1234 1234 1234 1234 1234<ul>" +
188
" <li>I 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
189
" </ul>" +
190
"</ul> followup" +
191
"<dl>" +
192
"<dt>Term1</dt>" +
193
"<dd>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</dd>" +
194
"<dt>Term2" +
195
"<dd>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
196
"<dt>Term3" +
197
"<dd>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
198
"</dl>" +
199
"<dl>" +
200
"<dt>TermUnfinished" +
201
"</dl> followup");
202
203
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
204
" * A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
205
" 1234 1234 1234 1234 1234\n" +
206
" * B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
207
" 1234 1234 1234 1234 1234\n" +
208
" * C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
209
" 1234 1234 1234 1234 1234\n" +
210
" 1. D 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
211
" 1234 1234 1234 1234 1234 1234\n" +
212
" 2. E 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
213
" 1234 1234 1234 1234 1234 1234\n" +
214
" * F 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
215
" 1234 1234 1234 1234 1234 1234 1234\n" +
216
" 1. G 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
217
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
218
" * H 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
219
" 1234 1234 1234 1234 1234 1234 1234\n" +
220
" * I 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
221
" 1234 1234 1234 1234 1234 1234\n" +
222
"followup\n" +
223
CODE_HIGHLIGHT + "Term1" + CODE_RESET + "\n" +
224
" A 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
225
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
226
CODE_HIGHLIGHT + "Term2" + CODE_RESET + "\n" +
227
" B 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
228
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
229
CODE_HIGHLIGHT + "Term3" + CODE_RESET + "\n" +
230
" C 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
231
" 1234 1234 1234 1234 1234 1234 1234 1234\n" +
232
CODE_HIGHLIGHT + "TermUnfinished" + CODE_RESET + "\n" +
233
"followup\n";
234
235
if (!Objects.equals(actual, expected)) {
236
throw new AssertionError("Incorrect output: " + actual);
237
}
238
239
//sections:
240
actual = new JavadocFormatter(66, true).formatJavadoc("test",
241
"text 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
242
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
243
"<h3>1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</h3>" +
244
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
245
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234");
246
247
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
248
"text 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
249
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
250
"1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
251
"\n" +
252
CODE_UNDERLINE + "1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
253
"1234 1234 1234 1234 1234" + CODE_RESET + "\n" +
254
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
255
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
256
"1234 1234 1234 1234 1234 1234 1234 1234\n";
257
258
if (!Objects.equals(actual, expected)) {
259
throw new AssertionError("Incorrect output: " + actual);
260
}
261
262
//table:
263
actual = new JavadocFormatter(66, true).formatJavadoc("test",
264
"<table>" +
265
"<tr>" +
266
"<th>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</th>" +
267
"<th>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</th>" +
268
"<th>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</th>" +
269
"</tr>" +
270
"<tr>" +
271
"<td>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td> \n" +
272
"<td>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
273
"<td>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
274
"<tr>" +
275
"<td>A 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
276
"<td>B 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
277
"<td>C 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
278
"</tr>" +
279
"<tr>" +
280
"<td>1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
281
"<td>1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234</td>" +
282
"</table>");
283
284
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
285
"----------------------------------------------------------------\n" +
286
"| " + 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" +
287
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
288
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
289
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
290
"| " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234 1234" + CODE_RESET + " |\n" +
291
"| " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " | " + CODE_HIGHLIGHT + "1234 1234" + CODE_RESET + " |\n" +
292
"----------------------------------------------------------------\n" +
293
"| A 1234 1234 1234 | B 1234 1234 1234 | C 1234 1234 1234 |\n" +
294
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
295
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
296
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
297
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
298
"| 1234 1234 | 1234 1234 | 1234 1234 |\n" +
299
"----------------------------------------------------------------\n" +
300
"| A 1234 1234 1234 | B 1234 1234 1234 | C 1234 1234 1234 |\n" +
301
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
302
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
303
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
304
"| 1234 1234 1234 | 1234 1234 1234 | 1234 1234 1234 |\n" +
305
"| 1234 1234 | 1234 1234 | 1234 1234 |\n" +
306
"----------------------------------------------------------------\n" +
307
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
308
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
309
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
310
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
311
"| 1234 1234 1234 | 1234 1234 1234 |\n" +
312
"| 1234 1234 | 1234 1234 |\n" +
313
"-------------------------------------------\n";
314
315
if (!Objects.equals(actual, expected)) {
316
throw new AssertionError("Incorrect output: " + actual);
317
}
318
319
//no escape sequences:
320
actual = new JavadocFormatter(66, false).formatJavadoc("test",
321
"@param shortName 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
322
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
323
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
324
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n" +
325
"@param aVeryLongName1234567890123456789012345678901234567890 " +
326
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
327
"1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 " +
328
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234" +
329
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 \n");
330
331
expected = "test\n" +
332
"\n" +
333
"Parameters:\n" +
334
"shortName - 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
335
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
336
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
337
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
338
" 1234 1234 1234 1234\n" +
339
"aVeryLongName1234567890123456789012345678901234567890 - \n" +
340
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
341
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
342
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n" +
343
" 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234\n";
344
345
if (!Objects.equals(actual, expected)) {
346
throw new AssertionError("Incorrect output: " + actual);
347
}
348
349
//null javadoc:
350
actual = new JavadocFormatter(66, true).formatJavadoc("test", null);
351
352
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n";
353
354
if (!Objects.equals(actual, expected)) {
355
throw new AssertionError("Incorrect output: " + actual);
356
}
357
358
//stray tags:
359
for (String tag : new String[] {"li", "ol", "h3", "table", "tr", "td", "dl", "dt", "dd"}) {
360
for (boolean closing : new boolean[] {false, true}) {
361
actual = new JavadocFormatter(66, true).formatJavadoc("test",
362
"<" + (closing ? "/" : "") + tag + ">text");
363
364
if (!actual.contains("text")) {
365
throw new AssertionError("Incorrect output: " + actual);
366
}
367
}
368
}
369
370
//entities:
371
actual = new JavadocFormatter(66, false).formatJavadoc("test",
372
"&alpha; &lt; &#65; &#X42; &gt; &broken; &#xFFFFFFFF; &#xFFFFFFF;\n");
373
374
expected = "test\n" +
375
"\u03b1 < A B > &broken; &#xFFFFFFFF; &#xFFFFFFF;\n";
376
377
if (!Objects.equals(actual, expected)) {
378
throw new AssertionError("Incorrect output: " + actual);
379
}
380
381
//img:
382
actual = new JavadocFormatter(66, true).formatJavadoc("test",
383
"1234 <img src='any.png' alt='text'/> 1234");
384
385
expected = CODE_HIGHLIGHT + "test" + CODE_RESET + "\n" +
386
"1234 text 1234\n";
387
388
if (!Objects.equals(actual, expected)) {
389
throw new AssertionError("Incorrect output: " + actual);
390
}
391
392
//unknown HTML tag:
393
actual = new JavadocFormatter(66, false).formatJavadoc("test",
394
"1234 <unknown any any>1234</unknown> 1234");
395
396
expected = "test\n" +
397
"1234 1234 1234\n";
398
399
if (!Objects.equals(actual, expected)) {
400
throw new AssertionError("Incorrect output: " + actual);
401
}
402
}
403
404
public void testSpaceAtEndOfLine() {
405
String header = "Class<?> Class<T>.forName(Module module, String name)";
406
String javadoc = """
407
@throws SecurityException
408
<ul>
409
<li> test </li>
410
</ul>
411
""";
412
413
new JavadocFormatter(60, true).formatJavadoc(header, javadoc);
414
}
415
416
}
417
418