<lambda>null1 package org.jetbrains.dokka.tests
2
3 import org.jetbrains.dokka.*
4 import org.junit.Before
5 import org.junit.Ignore
6 import org.junit.Test
7
8 class MarkdownFormatTest: FileGeneratorTestCase() {
9 override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf())
10
11 @Test fun emptyDescription() {
12 verifyMarkdownNode("emptyDescription")
13 }
14
15 @Test fun classWithCompanionObject() {
16 verifyMarkdownNode("classWithCompanionObject")
17 }
18
19 @Test fun annotations() {
20 verifyMarkdownNode("annotations")
21 }
22
23 @Test fun annotationClass() {
24 verifyMarkdownNode("annotationClass", withKotlinRuntime = true)
25 verifyMarkdownPackage("annotationClass", withKotlinRuntime = true)
26 }
27
28 @Test fun exceptionClass() {
29 verifyMarkdownNode("exceptionClass", withKotlinRuntime = true)
30 verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true)
31 }
32
33 @Test fun annotationParams() {
34 verifyMarkdownNode("annotationParams", withKotlinRuntime = true)
35 }
36
37 @Test fun extensions() {
38 verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output ->
39 buildPagesAndReadInto(model.members, output)
40 }
41 verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output ->
42 buildPagesAndReadInto(model.members.single().members, output)
43 }
44 }
45
46 @Test fun enumClass() {
47 verifyOutput("testdata/format/enumClass.kt", ".md") { model, output ->
48 buildPagesAndReadInto(model.members.single().members, output)
49 }
50 verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output ->
51 val enumClassNode = model.members.single().members[0]
52 buildPagesAndReadInto(
53 enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" },
54 output
55 )
56 }
57 }
58
59 @Test fun varargsFunction() {
60 verifyMarkdownNode("varargsFunction")
61 }
62
63 @Test fun overridingFunction() {
64 verifyMarkdownNodes("overridingFunction") { model->
65 val classMembers = model.members.single().members.first { it.name == "D" }.members
66 classMembers.filter { it.name == "f" }
67 }
68 }
69
70 @Test fun propertyVar() {
71 verifyMarkdownNode("propertyVar")
72 }
73
74 @Test fun functionWithDefaultParameter() {
75 verifyMarkdownNode("functionWithDefaultParameter")
76 }
77
78 @Test fun accessor() {
79 verifyMarkdownNodes("accessor") { model ->
80 model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" }
81 }
82 }
83
84 @Test fun paramTag() {
85 verifyMarkdownNode("paramTag")
86 }
87
88 @Test fun throwsTag() {
89 verifyMarkdownNode("throwsTag")
90 }
91
92 @Test fun typeParameterBounds() {
93 verifyMarkdownNode("typeParameterBounds")
94 }
95
96 @Test fun typeParameterVariance() {
97 verifyMarkdownNode("typeParameterVariance")
98 }
99
100 @Test fun typeProjectionVariance() {
101 verifyMarkdownNode("typeProjectionVariance")
102 }
103
104 @Test
105 fun javadocCodeMultiline() {
106 verifyJavaMarkdownNode("javadocCodeMultiline")
107 }
108
109 // TODO: FIXME
110 @Ignore
111 @Test
112 fun javadocHtml() {
113 verifyJavaMarkdownNode("javadocHtml")
114 }
115
116 // TODO: FIXME
117 @Ignore
118 @Test
119 fun javaCodeLiteralTags() {
120 verifyJavaMarkdownNode("javaCodeLiteralTags")
121 }
122
123 @Test
124 fun javaSample() {
125 verifyJavaMarkdownNode("javaSample")
126 }
127
128 // TODO: FIXME
129 @Ignore
130 @Test
131 fun javaCodeInParam() {
132 verifyJavaMarkdownNode("javaCodeInParam")
133 }
134
135 @Test fun javaSpaceInAuthor() {
136 verifyJavaMarkdownNode("javaSpaceInAuthor")
137 }
138
139 @Test fun nullability() {
140 verifyMarkdownNode("nullability")
141 }
142
143 @Test fun operatorOverloading() {
144 verifyMarkdownNodes("operatorOverloading") { model->
145 model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" }
146 }
147 }
148
149 @Test fun javadocOrderedList() {
150 verifyJavaMarkdownNodes("javadocOrderedList") { model ->
151 model.members.single().members.filter { it.name == "Bar" }
152 }
153 }
154
155 @Test fun codeBlockNoHtmlEscape() {
156 verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic")
157 }
158
159 @Test fun companionObjectExtension() {
160 verifyMarkdownNodeByName("companionObjectExtension", "Foo")
161 }
162
163 @Test fun starProjection() {
164 verifyMarkdownNode("starProjection")
165 }
166
167 @Test fun extensionFunctionParameter() {
168 verifyMarkdownNode("extensionFunctionParameter")
169 }
170
171 @Test fun summarizeSignatures() {
172 verifyMarkdownNodes("summarizeSignatures") { model -> model.members }
173 }
174
175 @Test fun summarizeSignaturesProperty() {
176 verifyMarkdownNodes("summarizeSignaturesProperty") { model -> model.members }
177 }
178
179 @Test fun reifiedTypeParameter() {
180 verifyMarkdownNode("reifiedTypeParameter", withKotlinRuntime = true)
181 }
182
183 @Test fun annotatedTypeParameter() {
184 verifyMarkdownNode("annotatedTypeParameter", withKotlinRuntime = true)
185 }
186
187 @Test fun inheritedMembers() {
188 verifyMarkdownNodeByName("inheritedMembers", "Bar")
189 }
190
191 @Test fun inheritedExtensions() {
192 verifyMarkdownNodeByName("inheritedExtensions", "Bar")
193 }
194
195 @Test fun genericInheritedExtensions() {
196 verifyMarkdownNodeByName("genericInheritedExtensions", "Bar")
197 }
198
199 @Test fun arrayAverage() {
200 verifyMarkdownNodeByName("arrayAverage", "XArray")
201 }
202
203 @Test fun multipleTypeParameterConstraints() {
204 verifyMarkdownNode("multipleTypeParameterConstraints", withKotlinRuntime = true)
205 }
206
207 @Test fun inheritedCompanionObjectProperties() {
208 verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C")
209 }
210
211 @Test fun shadowedExtensionFunctions() {
212 verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar")
213 }
214
215 @Test fun inapplicableExtensionFunctions() {
216 verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar")
217 }
218
219 @Test fun receiverParameterTypeBound() {
220 verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo")
221 }
222
223 @Test fun extensionWithDocumentedReceiver() {
224 verifyMarkdownNodes("extensionWithDocumentedReceiver") { model ->
225 model.members.single().members.single().members.filter { it.name == "fn" }
226 }
227 }
228
229 @Test fun codeBlock() {
230 verifyMarkdownNode("codeBlock")
231 }
232
233 @Test fun exclInCodeBlock() {
234 verifyMarkdownNodeByName("exclInCodeBlock", "foo")
235 }
236
237 @Test fun backtickInCodeBlock() {
238 verifyMarkdownNodeByName("backtickInCodeBlock", "foo")
239 }
240
241 @Test fun qualifiedNameLink() {
242 verifyMarkdownNodeByName("qualifiedNameLink", "foo", withKotlinRuntime = true)
243 }
244
245 @Test fun functionalTypeWithNamedParameters() {
246 verifyMarkdownNode("functionalTypeWithNamedParameters")
247 }
248
249 @Test fun typeAliases() {
250 verifyMarkdownNode("typeAliases")
251 verifyMarkdownPackage("typeAliases")
252 }
253
254 @Test fun sampleByFQName() {
255 verifyMarkdownNode("sampleByFQName")
256 }
257
258 @Test fun sampleByShortName() {
259 verifyMarkdownNode("sampleByShortName")
260 }
261
262
263 @Test fun suspendParam() {
264 verifyMarkdownNode("suspendParam")
265 verifyMarkdownPackage("suspendParam")
266 }
267
268 @Test fun sinceKotlin() {
269 verifyMarkdownNode("sinceKotlin")
270 verifyMarkdownPackage("sinceKotlin")
271 }
272
273 @Test fun sinceKotlinWide() {
274 verifyMarkdownPackage("sinceKotlinWide")
275 }
276
277 @Test fun dynamicType() {
278 verifyMarkdownNode("dynamicType")
279 }
280
281 @Test fun dynamicExtension() {
282 verifyMarkdownNodes("dynamicExtension") { model -> model.members.single().members.filter { it.name == "Foo" } }
283 }
284
285 @Test fun memberExtension() {
286 verifyMarkdownNodes("memberExtension") { model -> model.members.single().members.filter { it.name == "Foo" } }
287 }
288
289 @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() {
290 verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver")
291 }
292
293 @Test fun multiplePlatforms() {
294 verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple")
295 }
296
297 @Test fun multiplePlatformsMerge() {
298 verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge")
299 }
300
301 @Test fun multiplePlatformsMergeMembers() {
302 val module = buildMultiplePlatforms("multiplatform/mergeMembers")
303 verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output ->
304 buildPagesAndReadInto(model.members.single().members, output)
305 }
306 }
307
308 @Test fun multiplePlatformsOmitRedundant() {
309 val module = buildMultiplePlatforms("multiplatform/omitRedundant")
310 verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output ->
311 buildPagesAndReadInto(model.members.single().members, output)
312 }
313 }
314
315 @Test fun multiplePlatformsImplied() {
316 val module = buildMultiplePlatforms("multiplatform/implied")
317 verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output ->
318 val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS"))
319 fileGenerator.formatService = service
320 buildPagesAndReadInto(model.members.single().members, output)
321 }
322 }
323
324 @Test fun packagePlatformsWithExtExtensions() {
325 val path = "multiplatform/packagePlatformsWithExtExtensions"
326 val module = DocumentationModule("test")
327 val options = DocumentationOptions(
328 outputDir = "",
329 outputFormat = "html",
330 generateClassIndexPage = false,
331 generatePackageIndexPage = false,
332 noStdlibLink = true,
333 noJdkLink = true,
334 languageVersion = null,
335 apiVersion = null
336 )
337 appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, options = options)
338 verifyMultiplatformIndex(module, path)
339 verifyMultiplatformPackage(module, path)
340 }
341
342 @Test fun multiplePlatformsPackagePlatformFromMembers() {
343 val path = "multiplatform/packagePlatformsFromMembers"
344 val module = buildMultiplePlatforms(path)
345 verifyMultiplatformIndex(module, path)
346 verifyMultiplatformPackage(module, path)
347 }
348
349 @Test fun multiplePlatformsGroupNode() {
350 val path = "multiplatform/groupNode"
351 val module = buildMultiplePlatforms(path)
352 verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output ->
353 buildPagesAndReadInto(
354 listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }),
355 output
356 )
357 }
358 verifyMultiplatformPackage(module, path)
359 }
360
361 @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() {
362 val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode"
363 val module = buildMultiplePlatforms(path)
364 verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output ->
365 buildPagesAndReadInto(
366 listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)),
367 output
368 )
369 }
370 }
371
372 @Test fun linksInEmphasis() {
373 verifyMarkdownNode("linksInEmphasis")
374 }
375
376 @Test fun linksInStrong() {
377 verifyMarkdownNode("linksInStrong")
378 }
379
380 @Test fun linksInHeaders() {
381 verifyMarkdownNode("linksInHeaders")
382 }
383
384 @Test fun tokensInEmphasis() {
385 verifyMarkdownNode("tokensInEmphasis")
386 }
387
388 @Test fun tokensInStrong() {
389 verifyMarkdownNode("tokensInStrong")
390 }
391
392 @Test fun tokensInHeaders() {
393 verifyMarkdownNode("tokensInHeaders")
394 }
395
396 @Test fun unorderedLists() {
397 verifyMarkdownNode("unorderedLists")
398 }
399
400 @Test fun nestedLists() {
401 verifyMarkdownNode("nestedLists")
402 }
403
404 @Test fun referenceLink() {
405 verifyMarkdownNode("referenceLink")
406 }
407
408 @Test fun externalReferenceLink() {
409 verifyMarkdownNode("externalReferenceLink")
410 }
411
412 @Test fun newlineInTableCell() {
413 verifyMarkdownPackage("newlineInTableCell")
414 }
415
416 @Test fun indentedCodeBlock() {
417 verifyMarkdownNode("indentedCodeBlock")
418 }
419
420 @Test fun receiverReference() {
421 verifyMarkdownNode("receiverReference")
422 }
423
424 @Test fun extensionScope() {
425 verifyMarkdownNodeByName("extensionScope", "test")
426 }
427
428 @Test fun typeParameterReference() {
429 verifyMarkdownNode("typeParameterReference")
430 }
431
432 @Test fun notPublishedTypeAliasAutoExpansion() {
433 verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", includeNonPublic = false)
434 }
435
436 @Test fun companionImplements() {
437 verifyMarkdownNodeByName("companionImplements", "Foo")
438 }
439
440 @Test fun enumRef() {
441 verifyMarkdownNode("enumRef")
442 }
443
444 @Test fun inheritedLink() {
445 val filePath = "testdata/format/inheritedLink"
446 verifyOutput(
447 arrayOf(
448 contentRootFromPath("$filePath.kt"),
449 contentRootFromPath("$filePath.1.kt")
450 ),
451 ".md",
452 withJdk = true,
453 withKotlinRuntime = true,
454 includeNonPublic = false
455 ) { model, output ->
456 buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output)
457 }
458 }
459
460
461 private fun buildMultiplePlatforms(path: String): DocumentationModule {
462 val module = DocumentationModule("test")
463 val options = DocumentationOptions(
464 outputDir = "",
465 outputFormat = "html",
466 generateClassIndexPage = false,
467 generatePackageIndexPage = false,
468 noStdlibLink = true,
469 noJdkLink = true,
470 languageVersion = null,
471 apiVersion = null
472 )
473 appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options)
474 appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options)
475 return module
476 }
477
478 private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) {
479 verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output ->
480 buildPagesAndReadInto(model.members, output)
481 }
482 }
483
484 private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) {
485 verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") {
486 model, output ->
487 val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf())
488 fileGenerator.formatService = service
489 buildPagesAndReadInto(listOf(model), output)
490 }
491 }
492
493 @Test fun blankLineInsideCodeBlock() {
494 verifyMarkdownNode("blankLineInsideCodeBlock")
495 }
496
497 private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
498 verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
499 buildPagesAndReadInto(model.members, output)
500 }
501 }
502
503 private fun verifyMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) {
504 verifyMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
505 }
506
507 private fun verifyMarkdownNodes(
508 fileName: String,
509 withKotlinRuntime: Boolean = false,
510 includeNonPublic: Boolean = true,
511 nodeFilter: (DocumentationModule) -> List<DocumentationNode>
512 ) {
513 verifyOutput(
514 "testdata/format/$fileName.kt",
515 ".md",
516 withKotlinRuntime = withKotlinRuntime,
517 includeNonPublic = includeNonPublic
518 ) { model, output ->
519 buildPagesAndReadInto(nodeFilter(model), output)
520 }
521 }
522
523 private fun verifyJavaMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) {
524 verifyJavaMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
525 }
526
527 private fun verifyJavaMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) {
528 verifyJavaOutput("testdata/format/$fileName.java", ".md", withKotlinRuntime = withKotlinRuntime) { model, output ->
529 buildPagesAndReadInto(nodeFilter(model), output)
530 }
531 }
532
533 private fun verifyMarkdownNodeByName(
534 fileName: String,
535 name: String,
536 withKotlinRuntime: Boolean = false,
537 includeNonPublic: Boolean = true
538 ) {
539 verifyMarkdownNodes(fileName, withKotlinRuntime, includeNonPublic) { model->
540 val nodesWithName = model.members.single().members.filter { it.name == name }
541 if (nodesWithName.isEmpty()) {
542 throw IllegalArgumentException("Found no nodes named $name")
543 }
544 nodesWithName
545 }
546 }
547 }
548