-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathJavaDocDescriptionRendererTest.java
More file actions
320 lines (265 loc) · 10.2 KB
/
JavaDocDescriptionRendererTest.java
File metadata and controls
320 lines (265 loc) · 10.2 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
* Copyright 2016-2026 Qameta Software Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.description;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class JavaDocDescriptionRendererTest {
private final JavaDocDescriptionRenderer renderer = new JavaDocDescriptionRenderer();
@Test
void shouldRenderPlainTextAndTrimBlankLines() {
final String rendered = renderer.render(
"\r\n"
+ " First line \r\n"
+ "\r\n"
+ " Second line\t\r\n"
+ "\r\n"
);
assertThat(rendered)
.isEqualTo("First line\n\nSecond line");
}
@Test
void shouldReturnEmptyStringWhenBodyContainsOnlyBlockTags() {
final String rendered = renderer.render(
"@param value description\n"
+ "@throws Exception description"
);
assertThat(rendered)
.isEmpty();
}
@Test
void shouldIgnoreBlockTagsAndEverythingAfterThem() {
final String rendered = renderer.render(
"Summary paragraph.\n"
+ "\n"
+ "@param value Description of the value.\n"
+ "Continuation that should also be ignored."
);
assertThat(rendered)
.isEqualTo("Summary paragraph.");
}
@Test
void shouldIgnoreStandardBlockTagsAfterMainDescription() {
final List<String> blockTags = List.of(
"author",
"deprecated",
"exception",
"hidden",
"param",
"provides",
"return",
"see",
"serial",
"serialData",
"serialField",
"since",
"spec",
"throws",
"uses",
"version"
);
for (String blockTag : blockTags) {
assertThat(renderer.render("Summary paragraph.\n@" + blockTag + " metadata"))
.as(blockTag)
.isEqualTo("Summary paragraph.");
}
}
@Test
void shouldNotTreatAtSignsInsideTextAsBlockTags() {
final String rendered = renderer.render(
"Email [email protected]\n"
+ "Use @smoke in prose."
);
assertThat(rendered)
.isEqualTo("Email [email protected]\nUse @smoke in prose.");
}
@Test
void shouldDecodeEscapedAtEntityBeforeBlockTags() {
final String rendered = renderer.render(
"@version stays in prose.\n"
+ "@version 2.4.0"
);
assertThat(rendered)
.isEqualTo("@version stays in prose.");
}
@Test
void shouldPreserveUnicodeCharactersInDescriptions() {
final String rendered = renderer.render("Release notes: cafe, café, Привет, 東京, λ.");
assertThat(rendered)
.isEqualTo("Release notes: cafe, café, Привет, 東京, λ.");
}
@Test
void shouldDecodeSupportedNamedAndNumericEntities() {
final String rendered = renderer.render(
"Use <tag>, &, {x}, @, λ, and λ."
);
assertThat(rendered)
.isEqualTo("Use <tag>, &, {x}, @, λ, and λ.");
}
@Test
void shouldRenderSupportedInlineTags() {
final String rendered = renderer.render(
"Use {@code a < b}, {@literal <safe>}, "
+ "{@link java.lang.String}, "
+ "{@linkplain java.lang.String#valueOf(Object)}, "
+ "{@link java.util.List list docs}."
);
assertThat(rendered)
.isEqualTo("Use `a < b`, <safe>, String, valueOf(Object), list docs.");
}
@Test
void shouldSupportBalancedBracesInsideInlineTags() {
final String rendered = renderer.render(
"Payload {@code {\"outer\": {\"inner\": true}}}."
);
assertThat(rendered)
.isEqualTo("Payload `{\"outer\": {\"inner\": true}}`.");
}
@Test
void shouldNotTreatAtLinesInsideBalancedInlineTagsAsBlockTags() {
final String rendered = renderer.render(
"Summary {@literal first line\n"
+ "@notATag\n"
+ "last line}\n"
+ "@param ignored"
);
assertThat(rendered)
.isEqualTo("Summary first line\n@notATag\nlast line");
}
@Test
void shouldRenderNestedInlineTagsInsideLinkLabels() {
final String rendered = renderer.render(
"See {@linkplain java.util.List docs with {@code List}}."
);
assertThat(rendered)
.isEqualTo("See docs with `List`.");
}
@Test
void shouldSafelyDegradeUnsupportedStandardInlineTags() {
final String rendered = renderer.render(
"Fallbacks: {@docRoot}, {@inheritDoc}, {@index release}, "
+ "{@summary quick summary}, {@systemProperty user.home}, "
+ "{@value java.lang.Integer#MAX_VALUE}."
);
assertThat(rendered)
.isEqualTo(
"Fallbacks: docRoot, inheritDoc, index release, summary quick summary, "
+ "systemProperty user.home, value java.lang.Integer#MAX_VALUE."
);
}
@Test
void shouldSafelyDegradeSnippetTags() {
final String rendered = renderer.render(
"Snippet {@snippet :\n"
+ "int answer = 42;\n"
+ "@highlight substring=\"answer\"\n"
+ "}."
);
assertThat(rendered)
.isEqualTo("Snippet snippet :\nint answer = 42;\n@highlight substring=\"answer\".");
}
@Test
void shouldEscapeUnknownInlineTags() {
final String rendered = renderer.render("Unsupported {@unknown <tag>} clause.");
assertThat(rendered)
.isEqualTo("Unsupported unknown <tag> clause.");
}
@Test
void shouldPreserveMalformedInlineTagsAsText() {
final String rendered = renderer.render("Broken {@code tag");
assertThat(rendered)
.isEqualTo("Broken {@code tag");
}
@Test
void shouldRenderSupportedHtmlStructure() {
final String rendered = renderer.render(
"First<p>Second<br>Third<ul><li>one</li><li>two</li></ul><ol><li>three</li></ol>"
);
assertThat(rendered)
.isEqualTo("First\n\nSecond\nThird\n\n- one\n- two\n\n- three");
}
@Test
void shouldIgnoreUnclosedHtmlTagsSafely() {
final String rendered = renderer.render("Broken <b>bold <i>text");
assertThat(rendered)
.isEqualTo("Broken bold text");
}
@Test
void shouldIgnoreUnmatchedCodeHtmlTagsSafely() {
final String rendered = renderer.render("Broken <code>value < limit and stray </code>tag");
assertThat(rendered)
.isEqualTo("Broken `value < limit and stray `tag");
}
@Test
void shouldIgnoreOpeningCodeTagWithoutClosingTag() {
final String rendered = renderer.render("Broken <code>value < limit");
assertThat(rendered)
.isEqualTo("Broken value < limit");
}
@Test
void shouldIgnoreClosingCodeTagWithoutOpeningTag() {
final String rendered = renderer.render("Broken </code>tag");
assertThat(rendered)
.isEqualTo("Broken tag");
}
@Test
void shouldRenderHtmlCodeTagAsCodeSpan() {
final String rendered = renderer.render("<code>name < value & more</code>");
assertThat(rendered)
.isEqualTo("`name < value & more`");
}
@Test
void shouldLeaveUnknownEntitiesEscaped() {
final String rendered = renderer.render("Keep ¬AnEntity; literal.");
assertThat(rendered)
.isEqualTo("Keep &notAnEntity; literal.");
}
@Test
void shouldDropUnknownHtmlTagsButKeepTheirTextContentEscaped() {
final String rendered = renderer.render(
"prefix <script>alert(\"x\")</script> <div>safe & sound</div>"
);
assertThat(rendered)
.isEqualTo("prefix alert(\"x\") safe & sound");
}
@Test
void shouldRenderComplexModernJavadocExampleSafely() {
final String rendered = renderer.render(
"Fetches release metadata for the current build.\n"
+ "\n"
+ "<p>Use {@link java.net.URI URIs} for endpoint configuration.</p>\n"
+ "<ul>\n"
+ "<li>Supports café, Привет, 東京, and λ.</li>\n"
+ "<li>See the <a href=\"https://docs.oracle.com/\">Javadoc specification</a> "
+ "and {@linkplain java.lang.String#formatted(Object...) formatted examples}.</li>\n"
+ "</ul>\n"
+ "Example: <code>client.fetch(\"v2\")</code>\n"
+ "@beta remains prose.\n"
+ "@author Jane Doe\n"
+ "@version 2.3.0\n"
+ "@since 2.0"
);
assertThat(rendered)
.isEqualTo(
"Fetches release metadata for the current build.\n\n"
+ "Use URIs for endpoint configuration.\n\n"
+ "- Supports café, Привет, 東京, and λ.\n"
+ "- See the Javadoc specification and formatted examples.\n\n"
+ "Example: `client.fetch(\"v2\")`\n"
+ "@beta remains prose."
);
}
}