From 960ea9ebb01f280c4966e139c1697f083e9d8965 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 12 Jul 2018 15:37:18 +0300 Subject: Test refactoring and split by different platforms --- core/src/test/kotlin/model/BaseClassTest.kt | 269 +++++++++++++++++++++++ core/src/test/kotlin/model/BasePropertyTest.kt | 101 +++++++++ core/src/test/kotlin/model/ClassTest.kt | 293 ------------------------- core/src/test/kotlin/model/CommentTest.kt | 28 +-- core/src/test/kotlin/model/FunctionTest.kt | 44 ++-- core/src/test/kotlin/model/JSClassTest.kt | 6 + core/src/test/kotlin/model/JSFunctionTest.kt | 8 + core/src/test/kotlin/model/JSPropertyTest.kt | 8 + core/src/test/kotlin/model/JVMClassTest.kt | 55 +++++ core/src/test/kotlin/model/JVMFunctionTest.kt | 29 +++ core/src/test/kotlin/model/JVMPropertyTest.kt | 33 +++ core/src/test/kotlin/model/JavaTest.kt | 34 +-- core/src/test/kotlin/model/KotlinAsJavaTest.kt | 14 +- core/src/test/kotlin/model/LinkTest.kt | 12 +- core/src/test/kotlin/model/PackageTest.kt | 40 +++- core/src/test/kotlin/model/PropertyTest.kt | 111 ---------- core/src/test/kotlin/model/TypeAliasTest.kt | 18 +- 17 files changed, 616 insertions(+), 487 deletions(-) create mode 100644 core/src/test/kotlin/model/BaseClassTest.kt create mode 100644 core/src/test/kotlin/model/BasePropertyTest.kt delete mode 100644 core/src/test/kotlin/model/ClassTest.kt create mode 100644 core/src/test/kotlin/model/JSClassTest.kt create mode 100644 core/src/test/kotlin/model/JSFunctionTest.kt create mode 100644 core/src/test/kotlin/model/JSPropertyTest.kt create mode 100644 core/src/test/kotlin/model/JVMClassTest.kt create mode 100644 core/src/test/kotlin/model/JVMFunctionTest.kt create mode 100644 core/src/test/kotlin/model/JVMPropertyTest.kt delete mode 100644 core/src/test/kotlin/model/PropertyTest.kt (limited to 'core/src/test/kotlin/model') diff --git a/core/src/test/kotlin/model/BaseClassTest.kt b/core/src/test/kotlin/model/BaseClassTest.kt new file mode 100644 index 00000000..d48ecb48 --- /dev/null +++ b/core/src/test/kotlin/model/BaseClassTest.kt @@ -0,0 +1,269 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.RefKind +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BaseClassTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun emptyClass() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertEquals("", members.single().name) + assertTrue(links.none()) + } + } + } + + @Test fun emptyObject() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Object, kind) + assertEquals("Obj", name) + assertEquals(Content.Empty, content) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun classWithConstructor() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> + with (model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(1, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(3, details.count()) + assertEquals("public", details.elementAt(0).name) + with(details.elementAt(2)) { + assertEquals("name", name) + assertEquals(NodeKind.Parameter, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithFunction() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + with(members.elementAt(1)) { + assertEquals("fn", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Function, kind) + assertEquals("Unit", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithProperty() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("name", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Property, kind) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun classWithCompanionObject() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(3, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + } + with(members.elementAt(1)) { + assertEquals("x", name) + assertEquals(NodeKind.CompanionObjectProperty, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(2)) { + assertEquals("foo", name) + assertEquals(NodeKind.CompanionObjectFunction, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun dataClass() { + verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertTrue("data" in modifiers) + } + } + + @Test fun sealedClass() { + verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertEquals(1, modifiers.count { it == "sealed" }) + } + } + + @Test fun annotatedClassWithAnnotationParameters() { + checkSourceExistsAndVerifyModel( + "testdata/classes/annotatedClassWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + with(deprecation!!) { + assertEquals("Deprecated", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Annotation, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Parameter, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Value, kind) + assertEquals("\"should no longer be used\"", name) + } + } + } + } + } + } + + @Test fun notOpenClass() { + checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun indirectOverride() { + checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun innerClass() { + verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> + val innerClass = cls.members.single { it.name == "D" } + val modifiers = innerClass.details(NodeKind.Modifier) + assertEquals(3, modifiers.size) + assertEquals("inner", modifiers[2].name) + } + } + + @Test fun companionObjectExtension() { + checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> + val pkg = model.members.single() + val cls = pkg.members.single { it.name == "Foo" } + val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } + assertEquals(1, extensions.size) + } + } + + @Test fun secondaryConstructor() { + verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> + val constructors = cls.members(NodeKind.Constructor) + assertEquals(2, constructors.size) + with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { + assertEquals("", name) + assertEquals("This is a secondary constructor.", summary.toTestString()) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } + + @Test fun privateCompanionObject() { + checkSourceExistsAndVerifyModel( + "testdata/classes/privateCompanionObject.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) + ) { model -> + with(model.members.single().members.single()) { + assertEquals(0, members(NodeKind.CompanionObjectFunction).size) + assertEquals(0, members(NodeKind.CompanionObjectProperty).size) + } + } + } + +} diff --git a/core/src/test/kotlin/model/BasePropertyTest.kt b/core/src/test/kotlin/model/BasePropertyTest.kt new file mode 100644 index 00000000..c88fe702 --- /dev/null +++ b/core/src/test/kotlin/model/BasePropertyTest.kt @@ -0,0 +1,101 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BasePropertyTest(val analysisPlatform: Platform) { + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun valueProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun variableProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun valuePropertyWithGetter() { + checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun variablePropertyWithAccessors() { + checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + val modifiers = details(NodeKind.Modifier).map { it.name } + assertTrue("final" in modifiers) + assertTrue("public" in modifiers) + assertTrue("var" in modifiers) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun propertyWithReceiver() { + checkSourceExistsAndVerifyModel( + "testdata/properties/propertyWithReceiver.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + assertEquals("kotlin.String", name) + assertEquals(NodeKind.ExternalClass, kind) + with(members.single()) { + assertEquals("foobar", name) + assertEquals(NodeKind.Property, kind) + } + } + } + } + + @Test fun propertyOverride() { + checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { + assertEquals("xyzzy", name) + val override = references(RefKind.Override).single().to + assertEquals("xyzzy", override.name) + assertEquals("Foo", override.owner!!.name) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } +} diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt deleted file mode 100644 index ea586041..00000000 --- a/core/src/test/kotlin/model/ClassTest.kt +++ /dev/null @@ -1,293 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -class ClassTest { - @Test fun emptyClass() { - verifyModel("testdata/classes/emptyClass.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertEquals("", members.single().name) - assertTrue(links.none()) - } - } - } - - @Test fun emptyObject() { - verifyModel("testdata/classes/emptyObject.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Object, kind) - assertEquals("Obj", name) - assertEquals(Content.Empty, content) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun classWithConstructor() { - verifyModel("testdata/classes/classWithConstructor.kt") { model -> - with (model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(1, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(3, details.count()) - assertEquals("public", details.elementAt(0).name) - with(details.elementAt(2)) { - assertEquals("name", name) - assertEquals(NodeKind.Parameter, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithFunction() { - verifyModel("testdata/classes/classWithFunction.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - with(members.elementAt(1)) { - assertEquals("fn", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Function, kind) - assertEquals("Unit", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithProperty() { - verifyModel("testdata/classes/classWithProperty.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(1)) { - assertEquals("name", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Property, kind) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun classWithCompanionObject() { - verifyModel("testdata/classes/classWithCompanionObject.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(3, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - } - with(members.elementAt(1)) { - assertEquals("x", name) - assertEquals(NodeKind.CompanionObjectProperty, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(2)) { - assertEquals("foo", name) - assertEquals(NodeKind.CompanionObjectFunction, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun annotatedClass() { - verifyPackageMember("testdata/classes/annotatedClass.kt", withKotlinRuntime = true) { cls -> - assertEquals(1, cls.annotations.count()) - with(cls.annotations[0]) { - assertEquals("Strictfp", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - - @Test fun dataClass() { - verifyPackageMember("testdata/classes/dataClass.kt") { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertTrue("data" in modifiers) - } - } - - @Test fun sealedClass() { - verifyPackageMember("testdata/classes/sealedClass.kt") { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertEquals(1, modifiers.count { it == "sealed" }) - } - } - - @Test fun annotatedClassWithAnnotationParameters() { - verifyModel("testdata/classes/annotatedClassWithAnnotationParameters.kt") { model -> - with(model.members.single().members.single()) { - with(deprecation!!) { - assertEquals("Deprecated", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("\"should no longer be used\"", name) - } - } - } - } - } - } - - @Test fun javaAnnotationClass() { - verifyModel("testdata/classes/javaAnnotationClass.kt", withJdk = true) { model -> - with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { - assertEquals("Retention", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("RetentionPolicy.SOURCE", name) - } - } - } - } - } - } - - @Test fun notOpenClass() { - verifyModel("testdata/classes/notOpenClass.kt") { model -> - with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun indirectOverride() { - verifyModel("testdata/classes/indirectOverride.kt") { model -> - with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun innerClass() { - verifyPackageMember("testdata/classes/innerClass.kt") { cls -> - val innerClass = cls.members.single { it.name == "D" } - val modifiers = innerClass.details(NodeKind.Modifier) - assertEquals(3, modifiers.size) - assertEquals("inner", modifiers[2].name) - } - } - - @Test fun companionObjectExtension() { - verifyModel("testdata/classes/companionObjectExtension.kt") { model -> - val pkg = model.members.single() - val cls = pkg.members.single { it.name == "Foo" } - val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } - assertEquals(1, extensions.size) - } - } - - @Test fun secondaryConstructor() { - verifyPackageMember("testdata/classes/secondaryConstructor.kt") { cls -> - val constructors = cls.members(NodeKind.Constructor) - assertEquals(2, constructors.size) - with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { - assertEquals("", name) - assertEquals("This is a secondary constructor.", summary.toTestString()) - } - } - } - - @Test fun sinceKotlin() { - verifyModel("testdata/classes/sinceKotlin.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } - - @Test fun privateCompanionObject() { - verifyModel("testdata/classes/privateCompanionObject.kt", includeNonPublic = false) { model -> - with(model.members.single().members.single()) { - assertEquals(0, members(NodeKind.CompanionObjectFunction).size) - assertEquals(0, members(NodeKind.CompanionObjectProperty).size) - } - } - } - -} diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt index 3752bb8c..a97c55eb 100644 --- a/core/src/test/kotlin/model/CommentTest.kt +++ b/core/src/test/kotlin/model/CommentTest.kt @@ -7,7 +7,7 @@ import org.jetbrains.dokka.* public class CommentTest { @Test fun codeBlockComment() { - verifyModel("testdata/comments/codeBlockComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt") { model -> with(model.members.single().members.first()) { assertEqualsIgnoringSeparators("""[code lang=brainfuck] | @@ -30,7 +30,7 @@ public class CommentTest { } @Test fun emptyDoc() { - verifyModel("testdata/comments/emptyDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt") { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -38,7 +38,7 @@ public class CommentTest { } @Test fun emptyDocButComment() { - verifyModel("testdata/comments/emptyDocButComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt") { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -46,7 +46,7 @@ public class CommentTest { } @Test fun multilineDoc() { - verifyModel("testdata/comments/multilineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -55,7 +55,7 @@ public class CommentTest { } @Test fun multilineDocWithComment() { - verifyModel("testdata/comments/multilineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -64,7 +64,7 @@ public class CommentTest { } @Test fun oneLineDoc() { - verifyModel("testdata/comments/oneLineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -72,7 +72,7 @@ public class CommentTest { } @Test fun oneLineDocWithComment() { - verifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -80,7 +80,7 @@ public class CommentTest { } @Test fun oneLineDocWithEmptyLine() { - verifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -88,7 +88,7 @@ public class CommentTest { } @Test fun emptySection() { - verifyModel("testdata/comments/emptySection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -101,7 +101,7 @@ public class CommentTest { } @Test fun quotes() { - verifyModel("testdata/comments/quotes.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt") { model -> with(model.members.single().members.single()) { assertEquals("it's \"useful\"", content.summary.toTestString()) } @@ -109,7 +109,7 @@ public class CommentTest { } @Test fun section1() { - verifyModel("testdata/comments/section1.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section1.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -122,7 +122,7 @@ public class CommentTest { } @Test fun section2() { - verifyModel("testdata/comments/section2.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section2.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(2, content.sections.count()) @@ -139,7 +139,7 @@ public class CommentTest { } @Test fun multilineSection() { - verifyModel("testdata/comments/multilineSection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt") { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -153,7 +153,7 @@ line two""", toTestString()) } @Test fun directive() { - verifyModel("testdata/comments/directive.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/directive.kt") { model -> with(model.members.single().members.first()) { assertEquals("Summary", content.summary.toTestString()) with (content.description) { diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 32910682..2704bf65 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -2,14 +2,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test -import kotlin.test.assertNotNull -class FunctionTest { +abstract class BaseFunctionTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun function() { - verifyModel("testdata/functions/function.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/function.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("fn", name) assertEquals(NodeKind.Function, kind) @@ -22,7 +24,7 @@ class FunctionTest { } @Test fun functionWithReceiver() { - verifyModel("testdata/functions/functionWithReceiver.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithReceiver.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("kotlin.String", name) assertEquals(NodeKind.ExternalClass, kind) @@ -54,7 +56,7 @@ class FunctionTest { } @Test fun genericFunction() { - verifyModel("testdata/functions/genericFunction.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/genericFunction.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("generic", name) assertEquals(NodeKind.Function, kind) @@ -78,7 +80,7 @@ class FunctionTest { } } @Test fun genericFunctionWithConstraints() { - verifyModel("testdata/functions/genericFunctionWithConstraints.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/genericFunctionWithConstraints.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("generic", name) assertEquals(NodeKind.Function, kind) @@ -118,7 +120,7 @@ class FunctionTest { } @Test fun functionWithParams() { - verifyModel("testdata/functions/functionWithParams.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithParams.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("function", name) assertEquals(NodeKind.Function, kind) @@ -143,32 +145,21 @@ Documentation""", content.description.toTestString()) } } - @Test fun annotatedFunction() { - verifyPackageMember("testdata/functions/annotatedFunction.kt", withKotlinRuntime = true) { func -> - assertEquals(1, func.annotations.count()) - with(func.annotations[0]) { - assertEquals("Strictfp", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - @Test fun functionWithNotDocumentedAnnotation() { - verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt") { func -> + verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt", defaultModelConfig) { func -> assertEquals(0, func.annotations.count()) } } @Test fun inlineFunction() { - verifyPackageMember("testdata/functions/inlineFunction.kt") { func -> + verifyPackageMember("testdata/functions/inlineFunction.kt", defaultModelConfig) { func -> val modifiers = func.details(NodeKind.Modifier).map { it.name } assertTrue("inline" in modifiers) } } @Test fun functionWithAnnotatedParam() { - verifyModel("testdata/functions/functionWithAnnotatedParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithAnnotatedParam.kt", defaultModelConfig) { model -> with(model.members.single().members.single { it.name == "function" }) { with(details(NodeKind.Parameter).first()) { assertEquals(1, annotations.count()) @@ -183,7 +174,7 @@ Documentation""", content.description.toTestString()) } @Test fun functionWithNoinlineParam() { - verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt") { func -> + verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt", defaultModelConfig) { func -> with(func.details(NodeKind.Parameter).first()) { val modifiers = details(NodeKind.Modifier).map { it.name } assertTrue("noinline" in modifiers) @@ -192,7 +183,10 @@ Documentation""", content.description.toTestString()) } @Test fun annotatedFunctionWithAnnotationParameters() { - verifyModel("testdata/functions/annotatedFunctionWithAnnotationParameters.kt") { model -> + checkSourceExistsAndVerifyModel( + "testdata/functions/annotatedFunctionWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> with(model.members.single().members.single { it.name == "f" }) { assertEquals(1, annotations.count()) with(annotations[0]) { @@ -214,7 +208,7 @@ Documentation""", content.description.toTestString()) } @Test fun functionWithDefaultParameter() { - verifyModel("testdata/functions/functionWithDefaultParameter.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithDefaultParameter.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { with(details.elementAt(3)) { val value = details(NodeKind.Value) @@ -228,7 +222,7 @@ Documentation""", content.description.toTestString()) } @Test fun sinceKotlin() { - verifyModel("testdata/functions/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/sinceKotlin.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } diff --git a/core/src/test/kotlin/model/JSClassTest.kt b/core/src/test/kotlin/model/JSClassTest.kt new file mode 100644 index 00000000..e39b95cc --- /dev/null +++ b/core/src/test/kotlin/model/JSClassTest.kt @@ -0,0 +1,6 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseClassTest + +class JSClassTest: BaseClassTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSFunctionTest.kt b/core/src/test/kotlin/model/JSFunctionTest.kt new file mode 100644 index 00000000..f6b987a9 --- /dev/null +++ b/core/src/test/kotlin/model/JSFunctionTest.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseFunctionTest + +class JSFunctionTest: BaseFunctionTest(Platform.js) { + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSPropertyTest.kt b/core/src/test/kotlin/model/JSPropertyTest.kt new file mode 100644 index 00000000..0193d899 --- /dev/null +++ b/core/src/test/kotlin/model/JSPropertyTest.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BasePropertyTest + +class JSPropertyTest: BasePropertyTest(Platform.js) { + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMClassTest.kt b/core/src/test/kotlin/model/JVMClassTest.kt new file mode 100644 index 00000000..22e23722 --- /dev/null +++ b/core/src/test/kotlin/model/JVMClassTest.kt @@ -0,0 +1,55 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseClassTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.jetbrains.dokka.tests.verifyPackageMember +import org.junit.Assert +import org.junit.Test + +class JVMClassTest: BaseClassTest(Platform.jvm) { + @Test + fun annotatedClass() { + verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { cls -> + Assert.assertEquals(1, cls.annotations.count()) + with(cls.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + + + @Test fun javaAnnotationClass() { + checkSourceExistsAndVerifyModel( + "testdata/classes/javaAnnotationClass.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Retention", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + with(details[0]) { + Assert.assertEquals(NodeKind.Parameter, kind) + Assert.assertEquals(1, details.count()) + with(details[0]) { + Assert.assertEquals(NodeKind.Value, kind) + Assert.assertEquals("RetentionPolicy.SOURCE", name) + } + } + } + } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMFunctionTest.kt b/core/src/test/kotlin/model/JVMFunctionTest.kt new file mode 100644 index 00000000..a2fb0d2a --- /dev/null +++ b/core/src/test/kotlin/model/JVMFunctionTest.kt @@ -0,0 +1,29 @@ +package org.jetbrains.dokka.tests.model + +import com.sun.tools.javac.util.BaseFileManager +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BaseFunctionTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.verifyPackageMember +import org.junit.Assert +import org.junit.Test + +class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { + @Test + fun annotatedFunction() { + verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( + analysisPlatform = Platform.jvm, + withKotlinRuntime = true + )) { func -> + Assert.assertEquals(1, func.annotations.count()) + with(func.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMPropertyTest.kt b/core/src/test/kotlin/model/JVMPropertyTest.kt new file mode 100644 index 00000000..182dedbe --- /dev/null +++ b/core/src/test/kotlin/model/JVMPropertyTest.kt @@ -0,0 +1,33 @@ +package org.jetbrains.dokka.tests.model + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.BasePropertyTest +import org.jetbrains.dokka.tests.ModelConfig +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel +import org.junit.Assert +import org.junit.Test + +class JVMPropertyTest : BasePropertyTest(Platform.jvm) { + @Test + fun annotatedProperty() { + checkSourceExistsAndVerifyModel( + "testdata/properties/annotatedProperty.kt", + modelConfig = ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Volatile", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + } + +} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index e6c22ee4..946abcad 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -1,14 +1,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.RefKind import org.junit.Assert.* import org.junit.Ignore import org.junit.Test public class JavaTest { + private val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) @Test fun function() { - verifyJavaPackageMember("testdata/java/member.java") { cls -> + verifyJavaPackageMember("testdata/java/member.java", defaultModelConfig) { cls -> assertEquals("Test", cls.name) assertEquals(NodeKind.Class, cls.kind) with(cls.members(NodeKind.Function).single()) { @@ -45,7 +47,7 @@ public class JavaTest { } @Test fun memberWithModifiers() { - verifyJavaPackageMember("testdata/java/memberWithModifiers.java") { cls -> + verifyJavaPackageMember("testdata/java/memberWithModifiers.java", defaultModelConfig) { cls -> val modifiers = cls.details(NodeKind.Modifier).map { it.name } assertTrue("abstract" in modifiers) with(cls.members.single { it.name == "fn" }) { @@ -58,7 +60,7 @@ public class JavaTest { } @Test fun superClass() { - verifyJavaPackageMember("testdata/java/superClass.java") { cls -> + verifyJavaPackageMember("testdata/java/superClass.java", defaultModelConfig) { cls -> val superTypes = cls.details(NodeKind.Supertype) assertEquals(2, superTypes.size) assertEquals("Exception", superTypes[0].name) @@ -67,7 +69,7 @@ public class JavaTest { } @Test fun arrayType() { - verifyJavaPackageMember("testdata/java/arrayType.java") { cls -> + verifyJavaPackageMember("testdata/java/arrayType.java", defaultModelConfig) { cls -> with(cls.members(NodeKind.Function).single()) { val type = detail(NodeKind.Type) assertEquals("Array", type.name) @@ -81,7 +83,7 @@ public class JavaTest { } @Test fun typeParameter() { - verifyJavaPackageMember("testdata/java/typeParameter.java") { cls -> + verifyJavaPackageMember("testdata/java/typeParameter.java", defaultModelConfig) { cls -> val typeParameters = cls.details(NodeKind.TypeParameter) with(typeParameters.single()) { assertEquals("T", name) @@ -100,7 +102,7 @@ public class JavaTest { } @Test fun constructors() { - verifyJavaPackageMember("testdata/java/constructors.java") { cls -> + verifyJavaPackageMember("testdata/java/constructors.java", defaultModelConfig) { cls -> val constructors = cls.members(NodeKind.Constructor) assertEquals(2, constructors.size) with(constructors[0]) { @@ -110,14 +112,14 @@ public class JavaTest { } @Test fun innerClass() { - verifyJavaPackageMember("testdata/java/InnerClass.java") { cls -> + verifyJavaPackageMember("testdata/java/InnerClass.java", defaultModelConfig) { cls -> val innerClass = cls.members(NodeKind.Class).single() assertEquals("D", innerClass.name) } } @Test fun varargs() { - verifyJavaPackageMember("testdata/java/varargs.java") { cls -> + verifyJavaPackageMember("testdata/java/varargs.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() val param = fn.detail(NodeKind.Parameter) assertEquals("vararg", param.details(NodeKind.Modifier).first().name) @@ -128,7 +130,7 @@ public class JavaTest { } @Test fun fields() { - verifyJavaPackageMember("testdata/java/field.java") { cls -> + verifyJavaPackageMember("testdata/java/field.java", defaultModelConfig) { cls -> val i = cls.members(NodeKind.Property).single { it.name == "i" } assertEquals("Int", i.detail(NodeKind.Type).name) assertTrue("var" in i.details(NodeKind.Modifier).map { it.name }) @@ -141,7 +143,7 @@ public class JavaTest { } @Test fun staticMethod() { - verifyJavaPackageMember("testdata/java/staticMethod.java") { cls -> + verifyJavaPackageMember("testdata/java/staticMethod.java", defaultModelConfig) { cls -> val m = cls.members(NodeKind.Function).single { it.name == "foo" } assertTrue("static" in m.details(NodeKind.Modifier).map { it.name }) } @@ -154,13 +156,13 @@ public class JavaTest { * Proposed tag `@exclude` for it, but not supported yet */ @Ignore("@suppress not supported in Java!") @Test fun suppressTag() { - verifyJavaPackageMember("testdata/java/suppressTag.java") { cls -> + verifyJavaPackageMember("testdata/java/suppressTag.java", defaultModelConfig) { cls -> assertEquals(1, cls.members(NodeKind.Function).size) } } @Test fun annotatedAnnotation() { - verifyJavaPackageMember("testdata/java/annotatedAnnotation.java") { cls -> + verifyJavaPackageMember("testdata/java/annotatedAnnotation.java", defaultModelConfig) { cls -> assertEquals(1, cls.annotations.size) with(cls.annotations[0]) { assertEquals(1, details.count()) @@ -177,21 +179,21 @@ public class JavaTest { } @Test fun deprecation() { - verifyJavaPackageMember("testdata/java/deprecation.java") { cls -> + verifyJavaPackageMember("testdata/java/deprecation.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() assertEquals("This should no longer be used", fn.deprecation!!.content.toTestString()) } } @Test fun javaLangObject() { - verifyJavaPackageMember("testdata/java/javaLangObject.java") { cls -> + verifyJavaPackageMember("testdata/java/javaLangObject.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() assertEquals("Any", fn.detail(NodeKind.Type).name) } } @Test fun enumValues() { - verifyJavaPackageMember("testdata/java/enumValues.java") { cls -> + verifyJavaPackageMember("testdata/java/enumValues.java", defaultModelConfig) { cls -> val superTypes = cls.details(NodeKind.Supertype) assertEquals(0, superTypes.size) assertEquals(1, cls.members(NodeKind.EnumItem).size) @@ -199,7 +201,7 @@ public class JavaTest { } @Test fun inheritorLinks() { - verifyJavaPackageMember("testdata/java/InheritorLinks.java") { cls -> + verifyJavaPackageMember("testdata/java/InheritorLinks.java", defaultModelConfig) { cls -> val fooClass = cls.members.single { it.name == "Foo" } val inheritors = fooClass.references(RefKind.Inheritor) assertEquals(1, inheritors.size) diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index d24d8bdd..1d95556f 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -2,10 +2,13 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.DocumentationModule import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.junit.Test import org.junit.Assert.assertEquals class KotlinAsJavaTest { + private val defaultModelConfig = ModelConfig (analysisPlatform = Platform.jvm) + @Test fun function() { verifyModelAsJava("testdata/functions/function.kt") { model -> val pkg = model.members.single() @@ -33,8 +36,13 @@ fun verifyModelAsJava(source: String, withJdk: Boolean = false, withKotlinRuntime: Boolean = false, verifier: (DocumentationModule) -> Unit) { - verifyModel(source, - withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, + checkSourceExistsAndVerifyModel( + source, + modelConfig = ModelConfig( + withJdk = withJdk, + withKotlinRuntime = withKotlinRuntime, format = "html-as-java", - verifier = verifier) + analysisPlatform = Platform.jvm), + verifier = verifier + ) } diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index 6b72525f..d7283bae 100644 --- a/core/src/test/kotlin/model/LinkTest.kt +++ b/core/src/test/kotlin/model/LinkTest.kt @@ -8,7 +8,7 @@ import org.junit.Test class LinkTest { @Test fun linkToSelf() { - verifyModel("testdata/links/linkToSelf.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -18,7 +18,7 @@ class LinkTest { } @Test fun linkToMember() { - verifyModel("testdata/links/linkToMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -28,7 +28,7 @@ class LinkTest { } @Test fun linkToConstantWithUnderscores() { - verifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -38,7 +38,7 @@ class LinkTest { } @Test fun linkToQualifiedMember() { - verifyModel("testdata/links/linkToQualifiedMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -48,7 +48,7 @@ class LinkTest { } @Test fun linkToParam() { - verifyModel("testdata/links/linkToParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt") { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Function, kind) @@ -58,7 +58,7 @@ class LinkTest { } @Test fun linkToPackage() { - verifyModel("testdata/links/linkToPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt") { model -> val packageNode = model.members.single() with(packageNode) { assertEquals(this.name, "test.magic") diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index 052f0d28..bc8a0e0d 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -9,7 +9,7 @@ import org.junit.Test public class PackageTest { @Test fun rootPackage() { - verifyModel("testdata/packages/rootPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt") { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("", name) @@ -22,7 +22,7 @@ public class PackageTest { } @Test fun simpleNamePackage() { - verifyModel("testdata/packages/simpleNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt") { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("simple", name) @@ -35,7 +35,7 @@ public class PackageTest { } @Test fun dottedNamePackage() { - verifyModel("testdata/packages/dottedNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt") { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("dot.name", name) @@ -48,8 +48,14 @@ public class PackageTest { } @Test fun multipleFiles() { - verifyModel(KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), - KotlinSourceRoot("testdata/packages/simpleNamePackage.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), + KotlinSourceRoot("testdata/packages/simpleNamePackage.kt") + ) + ) + ) { model -> assertEquals(2, model.members.count()) with(model.members.single { it.name == "simple" }) { assertEquals(NodeKind.Package, kind) @@ -70,8 +76,14 @@ public class PackageTest { } @Test fun multipleFilesSamePackage() { - verifyModel(KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), - KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), + KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt") + ) + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -85,7 +97,9 @@ public class PackageTest { } @Test fun classAtPackageLevel() { - verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt")) { model -> + verifyModel( + ModelConfig(roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt"))) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -99,8 +113,14 @@ public class PackageTest { } @Test fun suppressAtPackageLevel() { - verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt"), - perPackageOptions = listOf(PackageOptionsImpl(prefix = "simple.name", suppress = true))) { model -> + verifyModel( + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + perPackageOptions = listOf( + PackageOptionsImpl(prefix = "simple.name", suppress = true) + ) + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt deleted file mode 100644 index 0ee0e0f5..00000000 --- a/core/src/test/kotlin/model/PropertyTest.kt +++ /dev/null @@ -1,111 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -class PropertyTest { - @Test fun valueProperty() { - verifyModel("testdata/properties/valueProperty.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun variableProperty() { - verifyModel("testdata/properties/variableProperty.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun valuePropertyWithGetter() { - verifyModel("testdata/properties/valuePropertyWithGetter.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun variablePropertyWithAccessors() { - verifyModel("testdata/properties/variablePropertyWithAccessors.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - val modifiers = details(NodeKind.Modifier).map { it.name } - assertTrue("final" in modifiers) - assertTrue("public" in modifiers) - assertTrue("var" in modifiers) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun annotatedProperty() { - verifyModel("testdata/properties/annotatedProperty.kt", withKotlinRuntime = true) { model -> - with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { - assertEquals("Volatile", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - } - - @Test fun propertyWithReceiver() { - verifyModel("testdata/properties/propertyWithReceiver.kt") { model -> - with(model.members.single().members.single()) { - assertEquals("kotlin.String", name) - assertEquals(NodeKind.ExternalClass, kind) - with(members.single()) { - assertEquals("foobar", name) - assertEquals(NodeKind.Property, kind) - } - } - } - } - - @Test fun propertyOverride() { - verifyModel("testdata/properties/propertyOverride.kt") { model -> - with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { - assertEquals("xyzzy", name) - val override = references(RefKind.Override).single().to - assertEquals("xyzzy", override.name) - assertEquals("Foo", override.owner!!.name) - } - } - } - - @Test fun sinceKotlin() { - verifyModel("testdata/properties/sinceKotlin.kt") { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } -} diff --git a/core/src/test/kotlin/model/TypeAliasTest.kt b/core/src/test/kotlin/model/TypeAliasTest.kt index c653ac83..a011b44f 100644 --- a/core/src/test/kotlin/model/TypeAliasTest.kt +++ b/core/src/test/kotlin/model/TypeAliasTest.kt @@ -8,7 +8,7 @@ import org.junit.Test class TypeAliasTest { @Test fun testSimple() { - verifyModel("testdata/typealias/simple.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/simple.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -20,7 +20,7 @@ class TypeAliasTest { @Test fun testInheritanceFromTypeAlias() { - verifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -36,7 +36,7 @@ class TypeAliasTest { @Test fun testChain() { - verifyModel("testdata/typealias/chain.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/chain.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) { assertEquals(Content.Empty, content) @@ -51,7 +51,7 @@ class TypeAliasTest { @Test fun testDocumented() { - verifyModel("testdata/typealias/documented.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/documented.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals("Just typealias", content.summary.toTestString()) @@ -61,7 +61,7 @@ class TypeAliasTest { @Test fun testDeprecated() { - verifyModel("testdata/typealias/deprecated.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/deprecated.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -73,7 +73,7 @@ class TypeAliasTest { @Test fun testGeneric() { - verifyModel("testdata/typealias/generic.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/generic.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) { assertEquals("Any", detail(NodeKind.TypeAliasUnderlyingType).detail(NodeKind.Type).name) @@ -88,7 +88,7 @@ class TypeAliasTest { @Test fun testFunctional() { - verifyModel("testdata/typealias/functional.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/functional.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals("Function1", detail(NodeKind.TypeAliasUnderlyingType).name) @@ -105,7 +105,7 @@ class TypeAliasTest { @Test fun testAsTypeBoundWithVariance() { - verifyModel("testdata/typealias/asTypeBoundWithVariance.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/asTypeBoundWithVariance.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.Class).find { it.name == "C" }!!) { val tParam = detail(NodeKind.TypeParameter) @@ -123,7 +123,7 @@ class TypeAliasTest { @Test fun sinceKotlin() { - verifyModel("testdata/typealias/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/typealias/sinceKotlin.kt") { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } -- cgit From 742be4ef7c024a5ea6023fb684cd24d1898f37e4 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 12 Jul 2018 20:23:02 +0300 Subject: Test refactoring, add common platform tests --- core/src/test/kotlin/TestAPI.kt | 15 +- core/src/test/kotlin/format/BaseHtmlFormatTest.kt | 146 ------ .../test/kotlin/format/BaseMarkdownFormatTest.kt | 467 ----------------- core/src/test/kotlin/format/GFMFormatTest.kt | 18 +- core/src/test/kotlin/format/HtmlFormatTest.kt | 193 +++++++ core/src/test/kotlin/format/JSHtmlFormatTest.kt | 6 - .../src/test/kotlin/format/JSMarkdownFormatTest.kt | 7 - core/src/test/kotlin/format/JVMHtmlFormatTest.kt | 54 -- .../test/kotlin/format/JVMMarkdownFormatTest.kt | 117 ----- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 29 +- core/src/test/kotlin/format/MarkdownFormatTest.kt | 580 +++++++++++++++++++++ core/src/test/kotlin/issues/IssuesTest.kt | 11 +- core/src/test/kotlin/javadoc/JavadocTest.kt | 58 ++- core/src/test/kotlin/model/BaseClassTest.kt | 269 ---------- core/src/test/kotlin/model/BasePropertyTest.kt | 101 ---- core/src/test/kotlin/model/ClassTest.kt | 318 +++++++++++ core/src/test/kotlin/model/CommentTest.kt | 36 +- core/src/test/kotlin/model/FunctionTest.kt | 23 + core/src/test/kotlin/model/JSClassTest.kt | 6 - core/src/test/kotlin/model/JSFunctionTest.kt | 8 - core/src/test/kotlin/model/JSPropertyTest.kt | 8 - core/src/test/kotlin/model/JVMClassTest.kt | 55 -- core/src/test/kotlin/model/JVMFunctionTest.kt | 29 -- core/src/test/kotlin/model/JVMPropertyTest.kt | 33 -- core/src/test/kotlin/model/KotlinAsJavaTest.kt | 9 +- core/src/test/kotlin/model/LinkTest.kt | 22 +- core/src/test/kotlin/model/PackageTest.kt | 31 +- core/src/test/kotlin/model/PropertyTest.kt | 129 +++++ 28 files changed, 1395 insertions(+), 1383 deletions(-) delete mode 100644 core/src/test/kotlin/format/BaseHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/BaseMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/HtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JSHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JSMarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JVMHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JVMMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/MarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/model/BaseClassTest.kt delete mode 100644 core/src/test/kotlin/model/BasePropertyTest.kt create mode 100644 core/src/test/kotlin/model/ClassTest.kt delete mode 100644 core/src/test/kotlin/model/JSClassTest.kt delete mode 100644 core/src/test/kotlin/model/JSFunctionTest.kt delete mode 100644 core/src/test/kotlin/model/JSPropertyTest.kt delete mode 100644 core/src/test/kotlin/model/JVMClassTest.kt delete mode 100644 core/src/test/kotlin/model/JVMFunctionTest.kt delete mode 100644 core/src/test/kotlin/model/JVMPropertyTest.kt create mode 100644 core/src/test/kotlin/model/PropertyTest.kt (limited to 'core/src/test/kotlin/model') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index bcbbf2fc..7042f41b 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.config.ContentRoot import org.jetbrains.kotlin.config.KotlinSourceRoot import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.utils.PathUtil import org.junit.Assert import org.junit.Assert.fail import java.io.File @@ -24,7 +25,7 @@ data class ModelConfig( val format: String = "html", val includeNonPublic: Boolean = true, val perPackageOptions: List = emptyList(), - val analysisPlatform: Platform = Platform.js, + val analysisPlatform: Platform = Platform.DEFAULT, val defaultPlatforms: List = emptyList() ) @@ -84,18 +85,22 @@ fun appendDocumentation(documentation: DocumentationModule, val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) environment.apply { if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { - val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") - addClasspath(File(stringRoot)) + addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } if (modelConfig.withKotlinRuntime) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) + if (analysisPlatform == Platform.jvm) { + val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") + addClasspath(File(kotlinStrictfpRoot)) + } // TODO: Fix concrete path to correct gradle path providing if (analysisPlatform == Platform.js) { addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-jslib.jar")) addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js.jar")) addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js-sources.jar")) } + if (analysisPlatform == Platform.common) { + addClasspath(File("/home/jetbrains/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.51/e4a9d4b13ab19ed1e6531fce6df98e8cfa7f7301/kotlin-stdlib-common-1.2.51.jar")) + } } addRoots(modelConfig.roots.toList()) diff --git a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt b/core/src/test/kotlin/format/BaseHtmlFormatTest.kt deleted file mode 100644 index 7fd331cf..00000000 --- a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt +++ /dev/null @@ -1,146 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Before -import org.junit.Test -import java.io.File - -abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) - - @Test fun classWithCompanionObject() { - verifyHtmlNode("classWithCompanionObject", defaultModelConfig) - } - - @Test fun htmlEscaping() { - verifyHtmlNode("htmlEscaping", defaultModelConfig) - } - - @Test fun overloads() { - verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } - } - - @Test fun overloadsWithDescription() { - verifyHtmlNode("overloadsWithDescription", defaultModelConfig) - } - - @Test fun overloadsWithDifferentDescriptions() { - verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) - } - - @Test fun deprecated() { - verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun brokenLink() { - verifyHtmlNode("brokenLink", defaultModelConfig) - } - - @Test fun codeSpan() { - verifyHtmlNode("codeSpan", defaultModelConfig) - } - - @Test fun parenthesis() { - verifyHtmlNode("parenthesis", defaultModelConfig) - } - - @Test fun bracket() { - verifyHtmlNode("bracket", defaultModelConfig) - } - - @Test fun see() { - verifyHtmlNode("see", defaultModelConfig) - } - - @Test fun tripleBackticks() { - verifyHtmlNode("tripleBackticks", defaultModelConfig) - } - - @Test fun typeLink() { - verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun parameterAnchor() { - verifyHtmlNode("parameterAnchor", defaultModelConfig) - } - - @Test fun codeBlock() { - verifyHtmlNode("codeBlock", defaultModelConfig) - } - @Test fun orderedList() { - verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun linkWithLabel() { - verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun entity() { - verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun uninterpretedEmphasisCharacters() { - verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) - } - - @Test fun markdownInLinks() { - verifyHtmlNode("markdownInLinks", defaultModelConfig) - } - - @Test fun returnWithLink() { - verifyHtmlNode("returnWithLink", defaultModelConfig) - } - - @Test fun linkWithStarProjection() { - verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) - } - - @Test fun sinceKotlin() { - verifyHtmlNode("sinceKotlin", defaultModelConfig) - } - - @Test fun blankLineInsideCodeBlock() { - verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) - } - - @Test fun indentedCodeBlock() { - verifyHtmlNode("indentedCodeBlock", defaultModelConfig) - } - - private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - private fun verifyHtmlNodes(fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List) { - verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyJavaHtmlNodes(fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } -} - diff --git a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt b/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt deleted file mode 100644 index 5612b1fd..00000000 --- a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt +++ /dev/null @@ -1,467 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Before -import org.junit.Test - -abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { - override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - - @Test fun emptyDescription() { - verifyMarkdownNode("emptyDescription", defaultModelConfig) - } - - @Test fun classWithCompanionObject() { - verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) - } - - @Test fun annotations() { - verifyMarkdownNode("annotations", defaultModelConfig) - } - - @Test fun annotationClass() { - verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun enumClass() { - verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> - val enumClassNode = model.members.single().members[0] - buildPagesAndReadInto( - enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, - output - ) - } - } - - @Test fun varargsFunction() { - verifyMarkdownNode("varargsFunction", defaultModelConfig) - } - - @Test fun overridingFunction() { - verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> - val classMembers = model.members.single().members.first { it.name == "D" }.members - classMembers.filter { it.name == "f" } - } - } - - @Test fun propertyVar() { - verifyMarkdownNode("propertyVar", defaultModelConfig) - } - - @Test fun functionWithDefaultParameter() { - verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) - } - - @Test fun accessor() { - verifyMarkdownNodes("accessor", defaultModelConfig) { model -> - model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } - } - } - - @Test fun paramTag() { - verifyMarkdownNode("paramTag", defaultModelConfig) - } - - @Test fun throwsTag() { - verifyMarkdownNode("throwsTag", defaultModelConfig) - } - - @Test fun typeParameterBounds() { - verifyMarkdownNode("typeParameterBounds", defaultModelConfig) - } - - @Test fun typeParameterVariance() { - verifyMarkdownNode("typeParameterVariance", defaultModelConfig) - } - - @Test fun typeProjectionVariance() { - verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) - } - - @Test fun codeBlockNoHtmlEscape() { - verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) - } - - @Test fun companionObjectExtension() { - verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) - } - - @Test fun starProjection() { - verifyMarkdownNode("starProjection", defaultModelConfig) - } - - @Test fun extensionFunctionParameter() { - verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) - } - - @Test fun summarizeSignatures() { - verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } - } - - @Test fun reifiedTypeParameter() { - verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun annotatedTypeParameter() { - verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedMembers() { - verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) - } - - @Test fun inheritedExtensions() { - verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) - } - - @Test fun genericInheritedExtensions() { - verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) - } - - @Test fun arrayAverage() { - verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) - } - - @Test fun multipleTypeParameterConstraints() { - verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedCompanionObjectProperties() { - verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) - } - - @Test fun shadowedExtensionFunctions() { - verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) - } - - @Test fun inapplicableExtensionFunctions() { - verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) - } - - @Test fun receiverParameterTypeBound() { - verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) - } - - @Test fun extensionWithDocumentedReceiver() { - verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> - model.members.single().members.single().members.filter { it.name == "fn" } - } - } - - @Test fun codeBlock() { - verifyMarkdownNode("codeBlock", defaultModelConfig) - } - - @Test fun exclInCodeBlock() { - verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) - } - - @Test fun backtickInCodeBlock() { - verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) - } - - @Test fun qualifiedNameLink() { - verifyMarkdownNodeByName("qualifiedNameLink", "foo", - ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) - } - - @Test fun typeAliases() { - verifyMarkdownNode("typeAliases", defaultModelConfig) - verifyMarkdownPackage("typeAliases", defaultModelConfig) - } - - @Test fun sampleByShortName() { - verifyMarkdownNode("sampleByShortName", defaultModelConfig) - } - - - @Test fun suspendParam() { - verifyMarkdownNode("suspendParam", defaultModelConfig) - verifyMarkdownPackage("suspendParam", defaultModelConfig) - } - - @Test fun sinceKotlin() { - verifyMarkdownNode("sinceKotlin", defaultModelConfig) - verifyMarkdownPackage("sinceKotlin", defaultModelConfig) - } - - @Test fun sinceKotlinWide() { - verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) - } - - @Test fun dynamicType() { - verifyMarkdownNode("dynamicType", defaultModelConfig) - } - - @Test fun dynamicExtension() { - verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun memberExtension() { - verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { - verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) - } - - @Test fun multiplePlatforms() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") - } - - @Test fun multiplePlatformsMerge() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") - } - - @Test fun multiplePlatformsMergeMembers() { - val module = buildMultiplePlatforms("multiplatform/mergeMembers") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsOmitRedundant() { - val module = buildMultiplePlatforms("multiplatform/omitRedundant") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsImplied() { - val module = buildMultiplePlatforms("multiplatform/implied") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) - fileGenerator.formatService = service - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun packagePlatformsWithExtExtensions() { - val path = "multiplatform/packagePlatformsWithExtExtensions" - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation(module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), - defaultPlatforms = listOf("JVM"), - withKotlinRuntime = true, - analysisPlatform = analysisPlatform - ) - ) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsPackagePlatformFromMembers() { - val path = "multiplatform/packagePlatformsFromMembers" - val module = buildMultiplePlatforms(path) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsGroupNode() { - val path = "multiplatform/groupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), - output - ) - } - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { - val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), - output - ) - } - } - - @Test fun linksInEmphasis() { - verifyMarkdownNode("linksInEmphasis", defaultModelConfig) - } - - @Test fun linksInStrong() { - verifyMarkdownNode("linksInStrong", defaultModelConfig) - } - - @Test fun linksInHeaders() { - verifyMarkdownNode("linksInHeaders", defaultModelConfig) - } - - @Test fun tokensInEmphasis() { - verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) - } - - @Test fun tokensInStrong() { - verifyMarkdownNode("tokensInStrong", defaultModelConfig) - } - - @Test fun tokensInHeaders() { - verifyMarkdownNode("tokensInHeaders", defaultModelConfig) - } - - @Test fun unorderedLists() { - verifyMarkdownNode("unorderedLists", defaultModelConfig) - } - - @Test fun nestedLists() { - verifyMarkdownNode("nestedLists", defaultModelConfig) - } - - @Test fun referenceLink() { - verifyMarkdownNode("referenceLink", defaultModelConfig) - } - - @Test fun externalReferenceLink() { - verifyMarkdownNode("externalReferenceLink", defaultModelConfig) - } - - @Test fun newlineInTableCell() { - verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) - } - - @Test fun indentedCodeBlock() { - verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) - } - - @Test fun receiverReference() { - verifyMarkdownNode("receiverReference", defaultModelConfig) - } - - @Test fun extensionScope() { - verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) - } - - @Test fun typeParameterReference() { - verifyMarkdownNode("typeParameterReference", defaultModelConfig) - } - - @Test fun notPublishedTypeAliasAutoExpansion() { - verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( - analysisPlatform = analysisPlatform, - includeNonPublic = false - )) - } - - @Test fun companionImplements() { - verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) - } - - - private fun buildMultiplePlatforms(path: String): DocumentationModule { - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation( - module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), - defaultPlatforms = listOf("JVM"), - analysisPlatform = Platform.jvm - ) - ) - appendDocumentation( - module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), - defaultPlatforms = listOf("JS"), - analysisPlatform = Platform.js - ) - ) - - return module - } - - private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { - model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - fileGenerator.formatService = service - buildPagesAndReadInto(listOf(model), output) - } - } - - @Test fun blankLineInsideCodeBlock() { - verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) - } - - protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyMarkdownNodes( - fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List - ) { - verifyOutput( - "testdata/format/$fileName.kt", - ".md", - modelConfig - ) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyMarkdownNodeByName( - fileName: String, - name: String, - modelConfig: ModelConfig = ModelConfig() - ) { - verifyMarkdownNodes(fileName, modelConfig) { model-> - val nodesWithName = model.members.single().members.filter { it.name == name } - if (nodesWithName.isEmpty()) { - throw IllegalArgumentException("Found no nodes named $name") - } - nodesWithName - } - } -} diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index b90ab2bf..60de7d29 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -2,23 +2,26 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService +import org.jetbrains.dokka.Platform import org.junit.Test -class GFMFormatTest : FileGeneratorTestCase() { +abstract class BaseGFMFormatTest(val analysisPlatform: Platform) : FileGeneratorTestCase() { override val formatService = GFMFormatService(fileGenerator, KotlinLanguageService(), listOf()) + private val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun sample() { - verifyGFMNodeByName("sample", "Foo") + verifyGFMNodeByName("sample", "Foo", defaultModelConfig) } @Test fun listInTableCell() { - verifyGFMNodeByName("listInTableCell", "Foo") + verifyGFMNodeByName("listInTableCell", "Foo", defaultModelConfig) } - private fun verifyGFMNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> + private fun verifyGFMNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { + verifyOutput("testdata/format/gfm/$fileName.kt", ".md", modelConfig) { model, output -> buildPagesAndReadInto( model.members.single().members.filter { it.name == name }, output @@ -26,3 +29,8 @@ class GFMFormatTest : FileGeneratorTestCase() { } } } + + +class JsGFMFormatTest : BaseGFMFormatTest(Platform.js) +class JvmGFMFormatTest : BaseGFMFormatTest(Platform.jvm) +class CommonGFMFormatTest : BaseGFMFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt new file mode 100644 index 00000000..20891963 --- /dev/null +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -0,0 +1,193 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Before +import org.junit.Test +import java.io.File + +abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + + @Test fun classWithCompanionObject() { + verifyHtmlNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun htmlEscaping() { + verifyHtmlNode("htmlEscaping", defaultModelConfig) + } + + @Test fun overloads() { + verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } + } + + @Test fun overloadsWithDescription() { + verifyHtmlNode("overloadsWithDescription", defaultModelConfig) + } + + @Test fun overloadsWithDifferentDescriptions() { + verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) + } + + @Test fun deprecated() { + verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun brokenLink() { + verifyHtmlNode("brokenLink", defaultModelConfig) + } + + @Test fun codeSpan() { + verifyHtmlNode("codeSpan", defaultModelConfig) + } + + @Test fun parenthesis() { + verifyHtmlNode("parenthesis", defaultModelConfig) + } + + @Test fun bracket() { + verifyHtmlNode("bracket", defaultModelConfig) + } + + @Test fun see() { + verifyHtmlNode("see", defaultModelConfig) + } + + @Test fun tripleBackticks() { + verifyHtmlNode("tripleBackticks", defaultModelConfig) + } + + @Test fun typeLink() { + verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun parameterAnchor() { + verifyHtmlNode("parameterAnchor", defaultModelConfig) + } + + @Test fun codeBlock() { + verifyHtmlNode("codeBlock", defaultModelConfig) + } + @Test fun orderedList() { + verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun linkWithLabel() { + verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun entity() { + verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun uninterpretedEmphasisCharacters() { + verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) + } + + @Test fun markdownInLinks() { + verifyHtmlNode("markdownInLinks", defaultModelConfig) + } + + @Test fun returnWithLink() { + verifyHtmlNode("returnWithLink", defaultModelConfig) + } + + @Test fun linkWithStarProjection() { + verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyHtmlNode("sinceKotlin", defaultModelConfig) + } + + @Test fun blankLineInsideCodeBlock() { + verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyHtmlNode("indentedCodeBlock", defaultModelConfig) + } + + private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + private fun verifyHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } +} + +class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) + +class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { + @Test + fun javaSeeTag() { + verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) + } + + @Test fun javaDeprecated() { + verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } + } + } + + @Test fun crossLanguageKotlinExtendsJava() { + verifyOutput( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), + JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) + ), + analysisPlatform = analysisPlatform + ), ".html") { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) + } + } + + @Test fun javaLinkTag() { + verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) + } + + @Test fun javaLinkTagWithLabel() { + verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) + } + + @Test fun javaSupertypeLink() { + verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } + } + } + +} + +class CommonHtmlFormatTest: BaseHtmlFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSHtmlFormatTest.kt b/core/src/test/kotlin/format/JSHtmlFormatTest.kt deleted file mode 100644 index afa0ce0a..00000000 --- a/core/src/test/kotlin/format/JSHtmlFormatTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseHtmlFormatTest - -class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt b/core/src/test/kotlin/format/JSMarkdownFormatTest.kt deleted file mode 100644 index ca92d9f6..00000000 --- a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseMarkdownFormatTest - -class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) { -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt b/core/src/test/kotlin/format/JVMHtmlFormatTest.kt deleted file mode 100644 index 1696ffb2..00000000 --- a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseHtmlFormatTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyOutput -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Test -import java.io.File - -class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { - @Test - fun javaSeeTag() { - verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) - } - - @Test fun javaDeprecated() { - verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> - model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } - } - } - - @Test fun crossLanguageKotlinExtendsJava() { - verifyOutput( - ModelConfig( - roots = arrayOf( - KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), - JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) - ), - analysisPlatform = analysisPlatform - ), ".html") { model, output -> - buildPagesAndReadInto( - model.members.single().members.filter { it.name == "Bar" }, - output - ) - } - } - - @Test fun javaLinkTag() { - verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) - } - - @Test fun javaLinkTagWithLabel() { - verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) - } - - @Test fun javaSupertypeLink() { - verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> - model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt b/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt deleted file mode 100644 index ee8169af..00000000 --- a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt +++ /dev/null @@ -1,117 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.contentRootFromPath -import org.jetbrains.dokka.tests.BaseMarkdownFormatTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyOutput -import org.junit.Test - -class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { - - @Test - fun enumRef() { - verifyMarkdownNode("enumRef", defaultModelConfig) - } - - @Test - fun javaCodeLiteralTags() { - verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) - } - - @Test - fun nullability() { - verifyMarkdownNode("nullability", defaultModelConfig) - } - - @Test - fun exceptionClass() { - verifyMarkdownNode( - "exceptionClass", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) - verifyMarkdownPackage( - "exceptionClass", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) - } - - @Test - fun operatorOverloading() { - verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> - model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } - } - } - - @Test - fun extensions() { - verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test - fun summarizeSignaturesProperty() { - verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } - } - - @Test - fun javaSpaceInAuthor() { - verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) - } - - @Test - fun javaCodeInParam() { - verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) - } - - @Test - fun annotationParams() { - verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedLink() { - val filePath = "testdata/format/inheritedLink" - verifyOutput( - filePath, - ".md", - ModelConfig( - roots = arrayOf( - contentRootFromPath("$filePath.kt"), - contentRootFromPath("$filePath.1.kt") - ), - withJdk = true, - withKotlinRuntime = true, - includeNonPublic = false, - analysisPlatform = analysisPlatform - - ) - ) { model, output -> - buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) - } - } - - @Test - fun javadocOrderedList() { - verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> - model.members.single().members.filter { it.name == "Bar" } - } - } - - @Test - fun jdkLinks() { - verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) - } - - @Test - fun javadocHtml() { - verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) - } -} diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index c02d3ad4..5df43017 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -3,35 +3,36 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.junit.Test -class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { +abstract class BaseKotlinWebSiteHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) override val formatService = KotlinWebsiteHtmlFormatService(fileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) @Test fun dropImport() { - verifyKWSNodeByName("dropImport", "foo") + verifyKWSNodeByName("dropImport", "foo", defaultModelConfig) } @Test fun sample() { - verifyKWSNodeByName("sample", "foo") + verifyKWSNodeByName("sample", "foo", defaultModelConfig) } @Test fun sampleWithAsserts() { - verifyKWSNodeByName("sampleWithAsserts", "a") + verifyKWSNodeByName("sampleWithAsserts", "a", defaultModelConfig) } @Test fun newLinesInSamples() { - verifyKWSNodeByName("newLinesInSamples", "foo") + verifyKWSNodeByName("newLinesInSamples", "foo", defaultModelConfig) } @Test fun newLinesInImportList() { - verifyKWSNodeByName("newLinesInImportList", "foo") + verifyKWSNodeByName("newLinesInImportList", "foo", defaultModelConfig) } @Test fun returnTag() { - verifyKWSNodeByName("returnTag", "indexOf") + verifyKWSNodeByName("returnTag", "indexOf", defaultModelConfig) } @Test fun overloadGroup() { - verifyKWSNodeByName("overloadGroup", "magic") + verifyKWSNodeByName("overloadGroup", "magic", defaultModelConfig) } @Test fun dataTags() { @@ -51,8 +52,12 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { verifyMultiplatformPackage(module, path) } - private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-html/$fileName.kt", ".html", ModelConfig(format = "kotlin-website-html")) { model, output -> + private fun verifyKWSNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { + verifyOutput( + "testdata/format/website-html/$fileName.kt", + ".html", + ModelConfig(analysisPlatform = modelConfig.analysisPlatform, format = "kotlin-website-html") + ) { model, output -> buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -96,3 +101,7 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { } } + +class JsKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.js) +class JvmKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.jvm) +class CommonKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt new file mode 100644 index 00000000..6c62587b --- /dev/null +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -0,0 +1,580 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Test + +abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + + @Test fun emptyDescription() { + verifyMarkdownNode("emptyDescription", defaultModelConfig) + } + + @Test fun classWithCompanionObject() { + verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun annotations() { + verifyMarkdownNode("annotations", defaultModelConfig) + } + + @Test fun annotationClass() { + verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun enumClass() { + verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> + val enumClassNode = model.members.single().members[0] + buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) + } + } + + @Test fun varargsFunction() { + verifyMarkdownNode("varargsFunction", defaultModelConfig) + } + + @Test fun overridingFunction() { + verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> + val classMembers = model.members.single().members.first { it.name == "D" }.members + classMembers.filter { it.name == "f" } + } + } + + @Test fun propertyVar() { + verifyMarkdownNode("propertyVar", defaultModelConfig) + } + + @Test fun functionWithDefaultParameter() { + verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) + } + + @Test fun accessor() { + verifyMarkdownNodes("accessor", defaultModelConfig) { model -> + model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } + } + } + + @Test fun paramTag() { + verifyMarkdownNode("paramTag", defaultModelConfig) + } + + @Test fun throwsTag() { + verifyMarkdownNode("throwsTag", defaultModelConfig) + } + + @Test fun typeParameterBounds() { + verifyMarkdownNode("typeParameterBounds", defaultModelConfig) + } + + @Test fun typeParameterVariance() { + verifyMarkdownNode("typeParameterVariance", defaultModelConfig) + } + + @Test fun typeProjectionVariance() { + verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) + } + + @Test fun codeBlockNoHtmlEscape() { + verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) + } + + @Test fun companionObjectExtension() { + verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) + } + + @Test fun starProjection() { + verifyMarkdownNode("starProjection", defaultModelConfig) + } + + @Test fun extensionFunctionParameter() { + verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) + } + + @Test fun summarizeSignatures() { + verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } + } + + @Test fun reifiedTypeParameter() { + verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun annotatedTypeParameter() { + verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedMembers() { + verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) + } + + @Test fun inheritedExtensions() { + verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun genericInheritedExtensions() { + verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun arrayAverage() { + verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) + } + + @Test fun multipleTypeParameterConstraints() { + verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedCompanionObjectProperties() { + verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) + } + + @Test fun shadowedExtensionFunctions() { + verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun inapplicableExtensionFunctions() { + verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun receiverParameterTypeBound() { + verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) + } + + @Test fun extensionWithDocumentedReceiver() { + verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> + model.members.single().members.single().members.filter { it.name == "fn" } + } + } + + @Test fun codeBlock() { + verifyMarkdownNode("codeBlock", defaultModelConfig) + } + + @Test fun exclInCodeBlock() { + verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun backtickInCodeBlock() { + verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun qualifiedNameLink() { + verifyMarkdownNodeByName("qualifiedNameLink", "foo", + ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun typeAliases() { + verifyMarkdownNode("typeAliases", defaultModelConfig) + verifyMarkdownPackage("typeAliases", defaultModelConfig) + } + + @Test fun sampleByShortName() { + verifyMarkdownNode("sampleByShortName", defaultModelConfig) + } + + + @Test fun suspendParam() { + verifyMarkdownNode("suspendParam", defaultModelConfig) + verifyMarkdownPackage("suspendParam", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyMarkdownNode("sinceKotlin", defaultModelConfig) + verifyMarkdownPackage("sinceKotlin", defaultModelConfig) + } + + @Test fun sinceKotlinWide() { + verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) + } + + @Test fun dynamicType() { + verifyMarkdownNode("dynamicType", defaultModelConfig) + } + + @Test fun dynamicExtension() { + verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun memberExtension() { + verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { + verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) + } + + @Test fun multiplePlatforms() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") + } + + @Test fun multiplePlatformsMerge() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") + } + + @Test fun multiplePlatformsMergeMembers() { + val module = buildMultiplePlatforms("multiplatform/mergeMembers") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsOmitRedundant() { + val module = buildMultiplePlatforms("multiplatform/omitRedundant") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsImplied() { + val module = buildMultiplePlatforms("multiplatform/implied") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) + fileGenerator.formatService = service + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun packagePlatformsWithExtExtensions() { + val path = "multiplatform/packagePlatformsWithExtExtensions" + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation(module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + withKotlinRuntime = true, + analysisPlatform = analysisPlatform + ) + ) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsPackagePlatformFromMembers() { + val path = "multiplatform/packagePlatformsFromMembers" + val module = buildMultiplePlatforms(path) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsGroupNode() { + val path = "multiplatform/groupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) + } + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { + val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) + } + } + + @Test fun linksInEmphasis() { + verifyMarkdownNode("linksInEmphasis", defaultModelConfig) + } + + @Test fun linksInStrong() { + verifyMarkdownNode("linksInStrong", defaultModelConfig) + } + + @Test fun linksInHeaders() { + verifyMarkdownNode("linksInHeaders", defaultModelConfig) + } + + @Test fun tokensInEmphasis() { + verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) + } + + @Test fun tokensInStrong() { + verifyMarkdownNode("tokensInStrong", defaultModelConfig) + } + + @Test fun tokensInHeaders() { + verifyMarkdownNode("tokensInHeaders", defaultModelConfig) + } + + @Test fun unorderedLists() { + verifyMarkdownNode("unorderedLists", defaultModelConfig) + } + + @Test fun nestedLists() { + verifyMarkdownNode("nestedLists", defaultModelConfig) + } + + @Test fun referenceLink() { + verifyMarkdownNode("referenceLink", defaultModelConfig) + } + + @Test fun externalReferenceLink() { + verifyMarkdownNode("externalReferenceLink", defaultModelConfig) + } + + @Test fun newlineInTableCell() { + verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) + } + + @Test fun receiverReference() { + verifyMarkdownNode("receiverReference", defaultModelConfig) + } + + @Test fun extensionScope() { + verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) + } + + @Test fun typeParameterReference() { + verifyMarkdownNode("typeParameterReference", defaultModelConfig) + } + + @Test fun notPublishedTypeAliasAutoExpansion() { + verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( + analysisPlatform = analysisPlatform, + includeNonPublic = false + )) + } + + @Test fun companionImplements() { + verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) + } + + + private fun buildMultiplePlatforms(path: String): DocumentationModule { + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + analysisPlatform = Platform.jvm + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), + defaultPlatforms = listOf("JS"), + analysisPlatform = Platform.js + ) + ) + + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { + model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) + } + } + + @Test fun blankLineInsideCodeBlock() { + verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyMarkdownNodes( + fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List + ) { + verifyOutput( + "testdata/format/$fileName.kt", + ".md", + modelConfig + ) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyMarkdownNodeByName( + fileName: String, + name: String, + modelConfig: ModelConfig = ModelConfig() + ) { + verifyMarkdownNodes(fileName, modelConfig) { model-> + val nodesWithName = model.members.single().members.filter { it.name == name } + if (nodesWithName.isEmpty()) { + throw IllegalArgumentException("Found no nodes named $name") + } + nodesWithName + } + } +} + +class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) + +class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { + + @Test + fun enumRef() { + verifyMarkdownNode("enumRef", defaultModelConfig) + } + + @Test + fun javaCodeLiteralTags() { + verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) + } + + @Test + fun nullability() { + verifyMarkdownNode("nullability", defaultModelConfig) + } + + @Test + fun exceptionClass() { + verifyMarkdownNode( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + verifyMarkdownPackage( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + } + + @Test + fun operatorOverloading() { + verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> + model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } + } + } + + @Test + fun extensions() { + verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test + fun summarizeSignaturesProperty() { + verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } + } + + @Test + fun javaSpaceInAuthor() { + verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) + } + + @Test + fun javaCodeInParam() { + verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) + } + + @Test + fun annotationParams() { + verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + filePath, + ".md", + ModelConfig( + roots = arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false, + analysisPlatform = analysisPlatform + + ) + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + + @Test + fun javadocOrderedList() { + verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> + model.members.single().members.filter { it.name == "Bar" } + } + } + + @Test + fun jdkLinks() { + verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) + } + + @Test + fun javadocHtml() { + verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) + } +} + +class CommonMarkdownFormatTest: BaseMarkdownFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/issues/IssuesTest.kt b/core/src/test/kotlin/issues/IssuesTest.kt index 58b3a2d2..da5acd6e 100644 --- a/core/src/test/kotlin/issues/IssuesTest.kt +++ b/core/src/test/kotlin/issues/IssuesTest.kt @@ -2,18 +2,19 @@ package issues import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.tests.ModelConfig import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel import org.junit.Test import kotlin.test.assertEquals - -class IssuesTest { +abstract class BaseIssuesTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun errorClasses() { checkSourceExistsAndVerifyModel("testdata/issues/errorClasses.kt", - modelConfig = ModelConfig(withJdk = true, withKotlinRuntime = true)) { model -> + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true, withKotlinRuntime = true)) { model -> val cls = model.members.single().members.single() fun DocumentationNode.returnType() = this.details.find { it.kind == NodeKind.Type }?.name @@ -27,3 +28,7 @@ class IssuesTest { } } } + +class JSIssuesTest: BaseIssuesTest(Platform.js) +class JVMIssuesTest: BaseIssuesTest(Platform.jvm) +class CommonIssuesTest: BaseIssuesTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index dc576b61..7976fccc 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -11,8 +11,10 @@ import org.junit.Assert.* import org.junit.Test class JavadocTest { + val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) + @Test fun testTypes() { - verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(withJdk = true)) { doc -> + verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(analysisPlatform = Platform.jvm, withJdk = true)) { doc -> val classDoc = doc.classNamed("foo.TypesKt")!! val method = classDoc.methods().find { it.name() == "foo" }!! @@ -28,7 +30,7 @@ class JavadocTest { } @Test fun testObject() { - verifyJavadoc("testdata/javadoc/obj.kt") { doc -> + verifyJavadoc("testdata/javadoc/obj.kt", defaultModelConfig) { doc -> val classDoc = doc.classNamed("foo.O") assertNotNull(classDoc) @@ -41,7 +43,10 @@ class JavadocTest { } @Test fun testException() { - verifyJavadoc("testdata/javadoc/exception.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/exception.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.MyException")!! val member = classDoc.methods().find { it.name() == "foo" } assertEquals(classDoc, member!!.containingClass()) @@ -49,7 +54,10 @@ class JavadocTest { } @Test fun testByteArray() { - verifyJavadoc("testdata/javadoc/bytearr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/bytearr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.ByteArray")!! assertNotNull(classDoc.asClassDoc()) @@ -59,7 +67,10 @@ class JavadocTest { } @Test fun testStringArray() { - verifyJavadoc("testdata/javadoc/stringarr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/stringarr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Foo")!! assertNotNull(classDoc.asClassDoc()) @@ -72,7 +83,10 @@ class JavadocTest { } @Test fun testJvmName() { - verifyJavadoc("testdata/javadoc/jvmname.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/jvmname.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Apple")!! assertNotNull(classDoc.asClassDoc()) @@ -82,7 +96,10 @@ class JavadocTest { } @Test fun testLinkWithParam() { - verifyJavadoc("testdata/javadoc/paramlink.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/paramlink.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("demo.Apple")!! assertNotNull(classDoc.asClassDoc()) val tags = classDoc.inlineTags().filterIsInstance() @@ -93,7 +110,10 @@ class JavadocTest { } @Test fun testInternalVisibility() { - verifyJavadoc("testdata/javadoc/internal.kt", ModelConfig(withKotlinRuntime = true, includeNonPublic = false)) { doc -> + verifyJavadoc( + "testdata/javadoc/internal.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true, includeNonPublic = false) + ) { doc -> val classDoc = doc.classNamed("foo.Person")!! val constructors = classDoc.constructors() assertEquals(1, constructors.size) @@ -102,7 +122,10 @@ class JavadocTest { } @Test fun testSuppress() { - verifyJavadoc("testdata/javadoc/suppress.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/suppress.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("Some")) assertNull(doc.classNamed("SomeAgain")) assertNull(doc.classNamed("Interface")) @@ -113,7 +136,10 @@ class JavadocTest { } @Test fun testTypeAliases() { - verifyJavadoc("testdata/javadoc/typealiases.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/typealiases.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("B")) assertNull(doc.classNamed("D")) @@ -128,7 +154,10 @@ class JavadocTest { } @Test fun testKDocKeywordsOnMethod() { - verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/kdocKeywordsOnMethod.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val method = doc.classNamed("KdocKeywordsOnMethodKt")!!.methods()[0] assertEquals("@return [ContentText(text=value of a)]", method.tags("return").first().text()) assertEquals("@param a [ContentText(text=Some string)]", method.paramTags().first().text()) @@ -138,7 +167,10 @@ class JavadocTest { @Test fun testBlankLineInsideCodeBlock() { - verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/blankLineInsideCodeBlock.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val method = doc.classNamed("BlankLineInsideCodeBlockKt")!!.methods()[0] val text = method.inlineTags().joinToString(separator = "", transform = Tag::text) assertEqualsIgnoringSeparators(""" @@ -155,7 +187,7 @@ class JavadocTest { @Test fun testCompanionMethodReference() { - verifyJavadoc("testdata/javadoc/companionMethodReference.kt") { doc -> + verifyJavadoc("testdata/javadoc/companionMethodReference.kt", defaultModelConfig) { doc -> val classDoc = doc.classNamed("foo.TestClass")!! val tag = classDoc.inlineTags().filterIsInstance().first() assertEquals("TestClass.Companion", tag.referencedClassName()) diff --git a/core/src/test/kotlin/model/BaseClassTest.kt b/core/src/test/kotlin/model/BaseClassTest.kt deleted file mode 100644 index d48ecb48..00000000 --- a/core/src/test/kotlin/model/BaseClassTest.kt +++ /dev/null @@ -1,269 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -abstract class BaseClassTest(val analysisPlatform: Platform) { - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - @Test fun emptyClass() { - checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertEquals("", members.single().name) - assertTrue(links.none()) - } - } - } - - @Test fun emptyObject() { - checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Object, kind) - assertEquals("Obj", name) - assertEquals(Content.Empty, content) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun classWithConstructor() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> - with (model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(1, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(3, details.count()) - assertEquals("public", details.elementAt(0).name) - with(details.elementAt(2)) { - assertEquals("name", name) - assertEquals(NodeKind.Parameter, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithFunction() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - with(members.elementAt(1)) { - assertEquals("fn", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Function, kind) - assertEquals("Unit", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithProperty() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(1)) { - assertEquals("name", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Property, kind) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun classWithCompanionObject() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(3, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - } - with(members.elementAt(1)) { - assertEquals("x", name) - assertEquals(NodeKind.CompanionObjectProperty, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(2)) { - assertEquals("foo", name) - assertEquals(NodeKind.CompanionObjectFunction, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun dataClass() { - verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertTrue("data" in modifiers) - } - } - - @Test fun sealedClass() { - verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertEquals(1, modifiers.count { it == "sealed" }) - } - } - - @Test fun annotatedClassWithAnnotationParameters() { - checkSourceExistsAndVerifyModel( - "testdata/classes/annotatedClassWithAnnotationParameters.kt", - defaultModelConfig - ) { model -> - with(model.members.single().members.single()) { - with(deprecation!!) { - assertEquals("Deprecated", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("\"should no longer be used\"", name) - } - } - } - } - } - } - - @Test fun notOpenClass() { - checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> - with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun indirectOverride() { - checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> - with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun innerClass() { - verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> - val innerClass = cls.members.single { it.name == "D" } - val modifiers = innerClass.details(NodeKind.Modifier) - assertEquals(3, modifiers.size) - assertEquals("inner", modifiers[2].name) - } - } - - @Test fun companionObjectExtension() { - checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> - val pkg = model.members.single() - val cls = pkg.members.single { it.name == "Foo" } - val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } - assertEquals(1, extensions.size) - } - } - - @Test fun secondaryConstructor() { - verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> - val constructors = cls.members(NodeKind.Constructor) - assertEquals(2, constructors.size) - with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { - assertEquals("", name) - assertEquals("This is a secondary constructor.", summary.toTestString()) - } - } - } - - @Test fun sinceKotlin() { - checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } - - @Test fun privateCompanionObject() { - checkSourceExistsAndVerifyModel( - "testdata/classes/privateCompanionObject.kt", - modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) - ) { model -> - with(model.members.single().members.single()) { - assertEquals(0, members(NodeKind.CompanionObjectFunction).size) - assertEquals(0, members(NodeKind.CompanionObjectProperty).size) - } - } - } - -} diff --git a/core/src/test/kotlin/model/BasePropertyTest.kt b/core/src/test/kotlin/model/BasePropertyTest.kt deleted file mode 100644 index c88fe702..00000000 --- a/core/src/test/kotlin/model/BasePropertyTest.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -abstract class BasePropertyTest(val analysisPlatform: Platform) { - - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - @Test fun valueProperty() { - checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun variableProperty() { - checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun valuePropertyWithGetter() { - checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun variablePropertyWithAccessors() { - checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - val modifiers = details(NodeKind.Modifier).map { it.name } - assertTrue("final" in modifiers) - assertTrue("public" in modifiers) - assertTrue("var" in modifiers) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun propertyWithReceiver() { - checkSourceExistsAndVerifyModel( - "testdata/properties/propertyWithReceiver.kt", - defaultModelConfig - ) { model -> - with(model.members.single().members.single()) { - assertEquals("kotlin.String", name) - assertEquals(NodeKind.ExternalClass, kind) - with(members.single()) { - assertEquals("foobar", name) - assertEquals(NodeKind.Property, kind) - } - } - } - } - - @Test fun propertyOverride() { - checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> - with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { - assertEquals("xyzzy", name) - val override = references(RefKind.Override).single().to - assertEquals("xyzzy", override.name) - assertEquals("Foo", override.owner!!.name) - } - } - } - - @Test fun sinceKotlin() { - checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } -} diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt new file mode 100644 index 00000000..b8e58a62 --- /dev/null +++ b/core/src/test/kotlin/model/ClassTest.kt @@ -0,0 +1,318 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.RefKind +import org.junit.Assert +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BaseClassTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun emptyClass() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertEquals("", members.single().name) + assertTrue(links.none()) + } + } + } + + @Test fun emptyObject() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Object, kind) + assertEquals("Obj", name) + assertEquals(Content.Empty, content) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun classWithConstructor() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> + with (model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(1, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(3, details.count()) + assertEquals("public", details.elementAt(0).name) + with(details.elementAt(2)) { + assertEquals("name", name) + assertEquals(NodeKind.Parameter, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithFunction() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + with(members.elementAt(1)) { + assertEquals("fn", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Function, kind) + assertEquals("Unit", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithProperty() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("name", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Property, kind) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun classWithCompanionObject() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(3, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + } + with(members.elementAt(1)) { + assertEquals("x", name) + assertEquals(NodeKind.CompanionObjectProperty, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(2)) { + assertEquals("foo", name) + assertEquals(NodeKind.CompanionObjectFunction, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun dataClass() { + verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertTrue("data" in modifiers) + } + } + + @Test fun sealedClass() { + verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertEquals(1, modifiers.count { it == "sealed" }) + } + } + + @Test fun annotatedClassWithAnnotationParameters() { + checkSourceExistsAndVerifyModel( + "testdata/classes/annotatedClassWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + with(deprecation!!) { + assertEquals("Deprecated", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Annotation, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Parameter, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Value, kind) + assertEquals("\"should no longer be used\"", name) + } + } + } + } + } + } + + @Test fun notOpenClass() { + checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun indirectOverride() { + checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun innerClass() { + verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> + val innerClass = cls.members.single { it.name == "D" } + val modifiers = innerClass.details(NodeKind.Modifier) + assertEquals(3, modifiers.size) + assertEquals("inner", modifiers[2].name) + } + } + + @Test fun companionObjectExtension() { + checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> + val pkg = model.members.single() + val cls = pkg.members.single { it.name == "Foo" } + val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } + assertEquals(1, extensions.size) + } + } + + @Test fun secondaryConstructor() { + verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> + val constructors = cls.members(NodeKind.Constructor) + assertEquals(2, constructors.size) + with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { + assertEquals("", name) + assertEquals("This is a secondary constructor.", summary.toTestString()) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } + + @Test fun privateCompanionObject() { + checkSourceExistsAndVerifyModel( + "testdata/classes/privateCompanionObject.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) + ) { model -> + with(model.members.single().members.single()) { + assertEquals(0, members(NodeKind.CompanionObjectFunction).size) + assertEquals(0, members(NodeKind.CompanionObjectProperty).size) + } + } + } + +} + +class JSClassTest: BaseClassTest(Platform.js) {} + +class JVMClassTest: BaseClassTest(Platform.jvm) { + @Test + fun annotatedClass() { + verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { cls -> + Assert.assertEquals(1, cls.annotations.count()) + with(cls.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + + + @Test fun javaAnnotationClass() { + checkSourceExistsAndVerifyModel( + "testdata/classes/javaAnnotationClass.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Retention", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + with(details[0]) { + Assert.assertEquals(NodeKind.Parameter, kind) + Assert.assertEquals(1, details.count()) + with(details[0]) { + Assert.assertEquals(NodeKind.Value, kind) + Assert.assertEquals("RetentionPolicy.SOURCE", name) + } + } + } + } + } + } + +} + +class CommonClassTest: BaseClassTest(Platform.common) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt index a97c55eb..08aa3572 100644 --- a/core/src/test/kotlin/model/CommentTest.kt +++ b/core/src/test/kotlin/model/CommentTest.kt @@ -4,10 +4,10 @@ import org.junit.Test import org.junit.Assert.* import org.jetbrains.dokka.* -public class CommentTest { - +abstract class BaseCommentTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun codeBlockComment() { - checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt", defaultModelConfig) { model -> with(model.members.single().members.first()) { assertEqualsIgnoringSeparators("""[code lang=brainfuck] | @@ -30,7 +30,7 @@ public class CommentTest { } @Test fun emptyDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -38,7 +38,7 @@ public class CommentTest { } @Test fun emptyDocButComment() { - checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -46,7 +46,7 @@ public class CommentTest { } @Test fun multilineDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -55,7 +55,7 @@ public class CommentTest { } @Test fun multilineDocWithComment() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -64,7 +64,7 @@ public class CommentTest { } @Test fun oneLineDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -72,7 +72,7 @@ public class CommentTest { } @Test fun oneLineDocWithComment() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -80,7 +80,7 @@ public class CommentTest { } @Test fun oneLineDocWithEmptyLine() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -88,7 +88,7 @@ public class CommentTest { } @Test fun emptySection() { - checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -101,7 +101,7 @@ public class CommentTest { } @Test fun quotes() { - checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("it's \"useful\"", content.summary.toTestString()) } @@ -109,7 +109,7 @@ public class CommentTest { } @Test fun section1() { - checkSourceExistsAndVerifyModel("testdata/comments/section1.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section1.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -122,7 +122,7 @@ public class CommentTest { } @Test fun section2() { - checkSourceExistsAndVerifyModel("testdata/comments/section2.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section2.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(2, content.sections.count()) @@ -139,7 +139,7 @@ public class CommentTest { } @Test fun multilineSection() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -153,7 +153,7 @@ line two""", toTestString()) } @Test fun directive() { - checkSourceExistsAndVerifyModel("testdata/comments/directive.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/directive.kt", defaultModelConfig) { model -> with(model.members.single().members.first()) { assertEquals("Summary", content.summary.toTestString()) with (content.description) { @@ -184,3 +184,7 @@ line two""", toTestString()) } } } + +class JSCommentTest: BaseCommentTest(Platform.js) +class JVMCommentTest: BaseCommentTest(Platform.jvm) +class CommonCommentTest: BaseCommentTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 2704bf65..47685df2 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test @@ -229,3 +230,25 @@ Documentation""", content.description.toTestString()) } } } + +class JSFunctionTest: BaseFunctionTest(Platform.js) + +class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { + @Test + fun annotatedFunction() { + verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( + analysisPlatform = Platform.jvm, + withKotlinRuntime = true + )) { func -> + Assert.assertEquals(1, func.annotations.count()) + with(func.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + +} + +class CommonFunctionTest: BaseFunctionTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSClassTest.kt b/core/src/test/kotlin/model/JSClassTest.kt deleted file mode 100644 index e39b95cc..00000000 --- a/core/src/test/kotlin/model/JSClassTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseClassTest - -class JSClassTest: BaseClassTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSFunctionTest.kt b/core/src/test/kotlin/model/JSFunctionTest.kt deleted file mode 100644 index f6b987a9..00000000 --- a/core/src/test/kotlin/model/JSFunctionTest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseFunctionTest - -class JSFunctionTest: BaseFunctionTest(Platform.js) { - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSPropertyTest.kt b/core/src/test/kotlin/model/JSPropertyTest.kt deleted file mode 100644 index 0193d899..00000000 --- a/core/src/test/kotlin/model/JSPropertyTest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BasePropertyTest - -class JSPropertyTest: BasePropertyTest(Platform.js) { - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMClassTest.kt b/core/src/test/kotlin/model/JVMClassTest.kt deleted file mode 100644 index 22e23722..00000000 --- a/core/src/test/kotlin/model/JVMClassTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseClassTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel -import org.jetbrains.dokka.tests.verifyPackageMember -import org.junit.Assert -import org.junit.Test - -class JVMClassTest: BaseClassTest(Platform.jvm) { - @Test - fun annotatedClass() { - verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) { cls -> - Assert.assertEquals(1, cls.annotations.count()) - with(cls.annotations[0]) { - Assert.assertEquals("Strictfp", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - - - @Test fun javaAnnotationClass() { - checkSourceExistsAndVerifyModel( - "testdata/classes/javaAnnotationClass.kt", - modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) - ) { model -> - with(model.members.single().members.single()) { - Assert.assertEquals(1, annotations.count()) - with(annotations[0]) { - Assert.assertEquals("Retention", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - with(details[0]) { - Assert.assertEquals(NodeKind.Parameter, kind) - Assert.assertEquals(1, details.count()) - with(details[0]) { - Assert.assertEquals(NodeKind.Value, kind) - Assert.assertEquals("RetentionPolicy.SOURCE", name) - } - } - } - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMFunctionTest.kt b/core/src/test/kotlin/model/JVMFunctionTest.kt deleted file mode 100644 index a2fb0d2a..00000000 --- a/core/src/test/kotlin/model/JVMFunctionTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import com.sun.tools.javac.util.BaseFileManager -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseFunctionTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyPackageMember -import org.junit.Assert -import org.junit.Test - -class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { - @Test - fun annotatedFunction() { - verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( - analysisPlatform = Platform.jvm, - withKotlinRuntime = true - )) { func -> - Assert.assertEquals(1, func.annotations.count()) - with(func.annotations[0]) { - Assert.assertEquals("Strictfp", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMPropertyTest.kt b/core/src/test/kotlin/model/JVMPropertyTest.kt deleted file mode 100644 index 182dedbe..00000000 --- a/core/src/test/kotlin/model/JVMPropertyTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BasePropertyTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel -import org.junit.Assert -import org.junit.Test - -class JVMPropertyTest : BasePropertyTest(Platform.jvm) { - @Test - fun annotatedProperty() { - checkSourceExistsAndVerifyModel( - "testdata/properties/annotatedProperty.kt", - modelConfig = ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) { model -> - with(model.members.single().members.single()) { - Assert.assertEquals(1, annotations.count()) - with(annotations[0]) { - Assert.assertEquals("Volatile", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index 1d95556f..f6f0aa20 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -7,8 +7,6 @@ import org.junit.Test import org.junit.Assert.assertEquals class KotlinAsJavaTest { - private val defaultModelConfig = ModelConfig (analysisPlatform = Platform.jvm) - @Test fun function() { verifyModelAsJava("testdata/functions/function.kt") { model -> val pkg = model.members.single() @@ -33,14 +31,13 @@ class KotlinAsJavaTest { } fun verifyModelAsJava(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { checkSourceExistsAndVerifyModel( source, modelConfig = ModelConfig( - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, format = "html-as-java", analysisPlatform = Platform.jvm), verifier = verifier diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index d7283bae..9b2f9f0d 100644 --- a/core/src/test/kotlin/model/LinkTest.kt +++ b/core/src/test/kotlin/model/LinkTest.kt @@ -3,12 +3,14 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.ContentBlock import org.jetbrains.dokka.ContentNodeLazyLink import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.junit.Assert.assertEquals import org.junit.Test -class LinkTest { +abstract class BaseLinkTest(val analysisPlatform: Platform) { + private val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun linkToSelf() { - checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -18,7 +20,7 @@ class LinkTest { } @Test fun linkToMember() { - checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -28,7 +30,7 @@ class LinkTest { } @Test fun linkToConstantWithUnderscores() { - checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -38,7 +40,7 @@ class LinkTest { } @Test fun linkToQualifiedMember() { - checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -48,7 +50,7 @@ class LinkTest { } @Test fun linkToParam() { - checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Function, kind) @@ -58,7 +60,7 @@ class LinkTest { } @Test fun linkToPackage() { - checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt", defaultModelConfig) { model -> val packageNode = model.members.single() with(packageNode) { assertEquals(this.name, "test.magic") @@ -72,4 +74,8 @@ class LinkTest { } } -} \ No newline at end of file +} + +class JSLinkTest: BaseLinkTest(Platform.js) +class JVMLinkTest: BaseLinkTest(Platform.jvm) +class CommonLinkTest: BaseLinkTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index bc8a0e0d..80a2fd56 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -1,15 +1,14 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.PackageOptionsImpl +import org.jetbrains.dokka.* import org.jetbrains.kotlin.config.KotlinSourceRoot import org.junit.Assert.* import org.junit.Test -public class PackageTest { +abstract class BasePackageTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun rootPackage() { - checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("", name) @@ -22,7 +21,7 @@ public class PackageTest { } @Test fun simpleNamePackage() { - checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("simple", name) @@ -35,7 +34,7 @@ public class PackageTest { } @Test fun dottedNamePackage() { - checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("dot.name", name) @@ -53,7 +52,8 @@ public class PackageTest { roots = arrayOf( KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), KotlinSourceRoot("testdata/packages/simpleNamePackage.kt") - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(2, model.members.count()) @@ -81,7 +81,8 @@ public class PackageTest { roots = arrayOf( KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt") - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(1, model.members.count()) @@ -98,7 +99,10 @@ public class PackageTest { @Test fun classAtPackageLevel() { verifyModel( - ModelConfig(roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt"))) + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + analysisPlatform = analysisPlatform + ) ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { @@ -118,7 +122,8 @@ public class PackageTest { roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), perPackageOptions = listOf( PackageOptionsImpl(prefix = "simple.name", suppress = true) - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(1, model.members.count()) @@ -133,3 +138,7 @@ public class PackageTest { } } } + +class JSPackageTest : BasePackageTest(Platform.js) +class JVMPackageTest : BasePackageTest(Platform.jvm) +class CommonPackageTest : BasePackageTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt new file mode 100644 index 00000000..a41ab5a3 --- /dev/null +++ b/core/src/test/kotlin/model/PropertyTest.kt @@ -0,0 +1,129 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Assert +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BasePropertyTest(val analysisPlatform: Platform) { + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun valueProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun variableProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun valuePropertyWithGetter() { + checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun variablePropertyWithAccessors() { + checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + val modifiers = details(NodeKind.Modifier).map { it.name } + assertTrue("final" in modifiers) + assertTrue("public" in modifiers) + assertTrue("var" in modifiers) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun propertyWithReceiver() { + checkSourceExistsAndVerifyModel( + "testdata/properties/propertyWithReceiver.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + assertEquals("kotlin.String", name) + assertEquals(NodeKind.ExternalClass, kind) + with(members.single()) { + assertEquals("foobar", name) + assertEquals(NodeKind.Property, kind) + } + } + } + } + + @Test fun propertyOverride() { + checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { + assertEquals("xyzzy", name) + val override = references(RefKind.Override).single().to + assertEquals("xyzzy", override.name) + assertEquals("Foo", override.owner!!.name) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } +} + +class JSPropertyTest: BasePropertyTest(Platform.js) {} + +class JVMPropertyTest : BasePropertyTest(Platform.jvm) { + @Test + fun annotatedProperty() { + checkSourceExistsAndVerifyModel( + "testdata/properties/annotatedProperty.kt", + modelConfig = ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Volatile", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + } + +} + +class CommonPropertyTest: BasePropertyTest(Platform.common) {} \ No newline at end of file -- cgit From c776aaab9af80987e3c073a40f92de748dbd38ca Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 11 Jan 2018 22:22:36 +0300 Subject: [backport] Support deep inheritance with external classes Original: 9e65c3d --- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 70 ++++++++++++++-------- .../main/kotlin/Kotlin/KotlinLanguageService.kt | 2 +- core/src/main/kotlin/Model/DocumentationNode.kt | 19 +++++- .../main/kotlin/Model/DocumentationReference.kt | 3 +- core/src/test/kotlin/TestAPI.kt | 48 ++++++++------- core/src/test/kotlin/model/JavaTest.kt | 2 +- 6 files changed, 92 insertions(+), 52 deletions(-) (limited to 'core/src/test/kotlin/model') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 99d4d888..11a36a4f 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -103,6 +103,10 @@ interface DefaultPlatformsProvider { fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List } +val ignoredSupertypes = setOf( + "kotlin.Annotation", "kotlin.Enum", "kotlin.Any" +) + class DocumentationBuilder @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val descriptorDocumentationParser: DescriptorDocumentationParser, @@ -173,7 +177,7 @@ class DocumentationBuilder val unwrappedType = superType.unwrap() if (unwrappedType is AbbreviatedType) { appendSupertype(descriptor, unwrappedType.abbreviation) - } else if (!ignoreSupertype(unwrappedType)) { + } else { appendType(unwrappedType, NodeKind.Supertype) val superclass = unwrappedType.constructor.declarationDescriptor link(superclass, descriptor, RefKind.Inheritor) @@ -181,15 +185,6 @@ class DocumentationBuilder } } - private fun ignoreSupertype(superType: KotlinType): Boolean { - val superClass = superType.constructor.declarationDescriptor as? ClassDescriptor - if (superClass != null) { - val fqName = DescriptorUtils.getFqNameSafe(superClass).asString() - return fqName == "kotlin.Annotation" || fqName == "kotlin.Enum" || fqName == "kotlin.Any" - } - return false - } - fun DocumentationNode.appendProjection(projection: TypeProjection, kind: NodeKind = NodeKind.Type) { if (projection.isStarProjection) { appendTextNode("*", NodeKind.Type) @@ -233,14 +228,25 @@ class DocumentationBuilder if (classifierDescriptor != null) { val externalLink = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(classifierDescriptor) if (externalLink != null) { + val targetNode = refGraph.lookup(classifierDescriptor.signature()) ?: classifierDescriptor.build(true) node.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link) - node.append(DocumentationNode(classifierDescriptor.fqNameUnsafe.asString(), Content.Empty, NodeKind.QualifiedName), RefKind.Detail) + node.append(targetNode, RefKind.ExternalType) } else { link(node, classifierDescriptor, if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link) } + if (classifierDescriptor !is TypeParameterDescriptor) { + node.append( + DocumentationNode( + classifierDescriptor.fqNameUnsafe.asString(), + Content.Empty, + NodeKind.QualifiedName + ), RefKind.Detail + ) + } } + append(node, RefKind.Detail) node.appendAnnotations(kotlinType) for (typeArgument in kotlinType.arguments) { @@ -496,34 +502,42 @@ class DocumentationBuilder } fun DeclarationDescriptor.build(): DocumentationNode = when (this) { - is ClassDescriptor -> build() + is ClassifierDescriptor -> build() is ConstructorDescriptor -> build() is PropertyDescriptor -> build() is FunctionDescriptor -> build() - is TypeParameterDescriptor -> build() is ValueParameterDescriptor -> build() is ReceiverParameterDescriptor -> build() - is TypeAliasDescriptor -> build() else -> throw IllegalStateException("Descriptor $this is not known") } - fun TypeAliasDescriptor.build(): DocumentationNode { + fun ClassifierDescriptor.build(external: Boolean = false): DocumentationNode = when (this) { + is ClassDescriptor -> build(external) + is TypeAliasDescriptor -> build(external) + is TypeParameterDescriptor -> build() + else -> throw IllegalStateException("Descriptor $this is not known") + } + + fun TypeAliasDescriptor.build(external: Boolean = false): DocumentationNode { val node = nodeForDescriptor(this, NodeKind.TypeAlias) - node.appendAnnotations(this) + if (!external) { + node.appendAnnotations(this) + } node.appendModifiers(this) node.appendInPageChildren(typeConstructor.parameters, RefKind.Detail) node.appendType(underlyingType, NodeKind.TypeAliasUnderlyingType) - node.appendSourceLink(source) - node.appendDefaultPlatforms(this) - + if (!external) { + node.appendSourceLink(source) + node.appendDefaultPlatforms(this) + } register(this, node) return node } - fun ClassDescriptor.build(): DocumentationNode { + fun ClassDescriptor.build(external: Boolean = false): DocumentationNode { val kind = when { kind == ClassKind.OBJECT -> NodeKind.Object kind == ClassKind.INTERFACE -> NodeKind.Interface @@ -534,20 +548,24 @@ class DocumentationBuilder else -> NodeKind.Class } val node = nodeForDescriptor(this, kind) + register(this, node) typeConstructor.supertypes.forEach { node.appendSupertype(this, it) } if (getKind() != ClassKind.OBJECT && getKind() != ClassKind.ENUM_ENTRY) { node.appendInPageChildren(typeConstructor.parameters, RefKind.Detail) } - for ((descriptor, inheritedLinkKind, extraModifier) in collectMembersToDocument()) { - node.appendClassMember(descriptor, inheritedLinkKind, extraModifier) + if (!external) { + for ((descriptor, inheritedLinkKind, extraModifier) in collectMembersToDocument()) { + node.appendClassMember(descriptor, inheritedLinkKind, extraModifier) + } + node.appendAnnotations(this) } - node.appendAnnotations(this) node.appendModifiers(this) - node.appendSourceLink(source) - node.appendDefaultPlatforms(this) - register(this, node) + if (!external) { + node.appendSourceLink(source) + node.appendDefaultPlatforms(this) + } return node } diff --git a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt index b6f44716..aa185de7 100644 --- a/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt +++ b/core/src/main/kotlin/Kotlin/KotlinLanguageService.kt @@ -291,7 +291,7 @@ class KotlinLanguageService : LanguageService { } private fun ContentBlock.renderSupertypesForNode(node: DocumentationNode, renderMode: RenderMode) { - val supertypes = node.details(NodeKind.Supertype) + val supertypes = node.details(NodeKind.Supertype).filterNot { it.qualifiedNameFromType() in ignoredSupertypes } if (supertypes.any()) { nbsp() symbol(":") diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index a145ae8d..a792460f 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -104,12 +104,27 @@ open class DocumentationNode(val name: String, get() = references(RefKind.Deprecation).singleOrNull()?.to val platforms: List get() = references(RefKind.Platform).map { it.to.name } + val externalType: DocumentationNode? + get() = references(RefKind.ExternalType).map { it.to }.firstOrNull() val supertypes: List get() = details(NodeKind.Supertype) - val superclass: DocumentationNode? - get() = supertypes.firstOrNull { it.links.any { it.kind in NodeKind.classLike } } + val superclassType: DocumentationNode? + get() = when (kind) { + NodeKind.Supertype -> (links.firstOrNull { it.kind in NodeKind.classLike } ?: externalType)?.superclassType + NodeKind.Interface -> null + in NodeKind.classLike -> supertypes.firstOrNull { + it.links.any { it.kind in NodeKind.classLike } || + it.externalType != null + } + else -> null + } + + val superclassTypeSequence: Sequence + get() = generateSequence(superclassType) { + it.superclassType + } // TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice fun addReferenceTo(to: DocumentationNode, kind: RefKind) { diff --git a/core/src/main/kotlin/Model/DocumentationReference.kt b/core/src/main/kotlin/Model/DocumentationReference.kt index a968f400..b0f011be 100644 --- a/core/src/main/kotlin/Model/DocumentationReference.kt +++ b/core/src/main/kotlin/Model/DocumentationReference.kt @@ -18,7 +18,8 @@ enum class RefKind { HiddenAnnotation, Deprecation, TopLevelPage, - Platform + Platform, + ExternalType } data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: RefKind) { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index aa3eff48..559b715e 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -6,7 +6,6 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.io.FileUtil import com.intellij.rt.execution.junit.FileComparisonFailure import org.jetbrains.dokka.* -import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.dokka.Utilities.DokkaAnalysisModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -25,6 +24,7 @@ fun verifyModel(vararg roots: ContentRoot, format: String = "html", includeNonPublic: Boolean = true, perPackageOptions: List = emptyList(), + noStdlibLink: Boolean = true, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") @@ -37,7 +37,7 @@ fun verifyModel(vararg roots: ContentRoot, sourceLinks = listOf(), perPackageOptions = perPackageOptions, generateIndexPages = false, - noStdlibLink = true, + noStdlibLink = noStdlibLink, cacheRoot = "default", languageVersion = null, apiVersion = null @@ -161,13 +161,15 @@ fun verifyOutput(roots: Array, withKotlinRuntime: Boolean = false, format: String = "html", includeNonPublic: Boolean = true, + noStdlibLink: Boolean = true, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { verifyModel( - *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic + *roots, + withJdk = withJdk, + withKotlinRuntime = withKotlinRuntime, + format = format, + includeNonPublic = includeNonPublic, + noStdlibLink = noStdlibLink ) { verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) } @@ -184,21 +186,25 @@ fun verifyModelOutput(it: DocumentationModule, assertEqualsIgnoringSeparators(expectedFile, output.toString()) } -fun verifyOutput(path: String, - outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { +fun verifyOutput( + path: String, + outputExtension: String, + withJdk: Boolean = false, + withKotlinRuntime: Boolean = false, + format: String = "html", + includeNonPublic: Boolean = true, + noStdlibLink: Boolean = true, + outputGenerator: (DocumentationModule, StringBuilder) -> Unit +) { verifyOutput( - arrayOf(contentRootFromPath(path)), - outputExtension, - withJdk, - withKotlinRuntime, - format, - includeNonPublic, - outputGenerator + arrayOf(contentRootFromPath(path)), + outputExtension, + withJdk, + withKotlinRuntime, + format, + includeNonPublic, + noStdlibLink, + outputGenerator ) } diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index e6c22ee4..c2ede8f0 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -193,7 +193,7 @@ public class JavaTest { @Test fun enumValues() { verifyJavaPackageMember("testdata/java/enumValues.java") { cls -> val superTypes = cls.details(NodeKind.Supertype) - assertEquals(0, superTypes.size) + assertEquals(1, superTypes.size) assertEquals(1, cls.members(NodeKind.EnumItem).size) } } -- cgit From 23861925232505dbd70344a1d690f2475bb022e8 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 4 Jun 2018 16:23:34 +0300 Subject: [backport] Introduce option to enable/disable jdk linking Original: 8e9e768 --- core/src/main/kotlin/DokkaBootstrapImpl.kt | 39 +++++++++++----------- .../main/kotlin/Generation/configurationImpl.kt | 1 + .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 6 +++- core/src/test/kotlin/TestAPI.kt | 9 +++++ .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 1 + .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 1 + core/src/test/kotlin/format/MarkdownFormatTest.kt | 2 ++ core/src/test/kotlin/model/JavaTest.kt | 4 +-- .../kotlin/org/jetbrains/dokka/configuration.kt | 2 ++ runners/ant/src/main/kotlin/ant/dokka.kt | 2 ++ runners/gradle-plugin/src/main/kotlin/main.kt | 14 +++++--- 11 files changed, 54 insertions(+), 27 deletions(-) (limited to 'core/src/test/kotlin/model') diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index b7787be8..e18ab6cf 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -52,25 +52,26 @@ class DokkaBootstrapImpl : DokkaBootstrap { includes, moduleName, DocumentationOptions( - outputDir, - format, - includeNonPublic, - includeRootPackage, - reportUndocumented, - skipEmptyPackages, - skipDeprecated, - jdkVersion, - generateIndexPages, - sourceLinks, - impliedPlatforms, - perPackageOptions, - externalDocumentationLinks, - noStdlibLink, - languageVersion, - apiVersion, - cacheRoot, - suppressedFiles.map { File(it) }.toSet(), - collectInheritedExtensionsFromLibraries + outputDir = outputDir, + outputFormat = format, + includeNonPublic = includeNonPublic, + includeRootPackage = includeRootPackage, + reportUndocumented = reportUndocumented, + skipEmptyPackages = skipEmptyPackages, + skipDeprecated = skipDeprecated, + jdkVersion = jdkVersion, + generateIndexPages = generateIndexPages, + sourceLinks = sourceLinks, + impliedPlatforms = impliedPlatforms, + perPackageOptions = perPackageOptions, + externalDocumentationLinks = externalDocumentationLinks, + noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, + languageVersion = languageVersion, + apiVersion = apiVersion, + cacheRoot = cacheRoot, + suppressedFiles = suppressedFiles.map { File(it) }.toSet(), + collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries ) ) } diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt index 52e8446f..90e27b4b 100644 --- a/core/src/main/kotlin/Generation/configurationImpl.kt +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -55,6 +55,7 @@ data class DokkaConfigurationImpl( override val perPackageOptions: List, override val externalDocumentationLinks: List, override val noStdlibLink: Boolean, + override val noJdkLink: Boolean, override val cacheRoot: String?, override val suppressedFiles: List, override val languageVersion: String?, diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index e6a75277..58f5e246 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -55,6 +55,7 @@ class DocumentationOptions(val outputDir: String, perPackageOptions: List = emptyList(), externalDocumentationLinks: List = emptyList(), noStdlibLink: Boolean, + noJdkLink: Boolean, val languageVersion: String?, val apiVersion: String?, cacheRoot: String? = null, @@ -72,7 +73,10 @@ class DocumentationOptions(val outputDir: String, fun effectivePackageOptions(pack: FqName): PackageOptions = effectivePackageOptions(pack.asString()) val defaultLinks = run { - val links = mutableListOf(ExternalDocumentationLink.Builder("http://docs.oracle.com/javase/$jdkVersion/docs/api/").build()) + val links = mutableListOf() + if (!noJdkLink) + links += ExternalDocumentationLink.Builder("http://docs.oracle.com/javase/$jdkVersion/docs/api/").build() + if (!noStdlibLink) links += ExternalDocumentationLink.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/").build() links diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index aeff9284..953e3bab 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -39,6 +39,7 @@ fun verifyModel(vararg roots: ContentRoot, perPackageOptions = perPackageOptions, generateIndexPages = false, noStdlibLink = noStdlibLink, + noJdkLink = false, cacheRoot = "default", languageVersion = null, apiVersion = null, @@ -269,6 +270,14 @@ fun StringBuilder.appendNode(node: ContentNode): StringBuilder { is ContentBlock -> { appendChildren(node) } + is NodeRenderContent -> { + append("render(") + append(node.node) + append(",") + append(node.mode) + append(")") + } + is ContentSymbol -> { append(node.text) } is ContentEmpty -> { /* nothing */ } else -> throw IllegalStateException("Don't know how to format node $node") } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index b971b54d..062cf0b5 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -54,6 +54,7 @@ class KotlinWebSiteFormatTest: FileGeneratorTestCase() { outputFormat = "html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 49fa6d2f..8076fb92 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -65,6 +65,7 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { outputFormat = "kotlin-website-html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 9e4c831d..3723e5ae 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -313,6 +313,7 @@ class MarkdownFormatTest: FileGeneratorTestCase() { outputFormat = "html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) @@ -447,6 +448,7 @@ class MarkdownFormatTest: FileGeneratorTestCase() { outputFormat = "html", generateIndexPages = false, noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index c2ede8f0..66eb84f1 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -18,12 +18,12 @@ public class JavaTest { with(content.sections[0]) { assertEquals("Parameters", tag) assertEquals("name", subjectName) - assertEquals("is String parameter", toTestString()) + assertEquals("render(Type:String,SUMMARY): is String parameter", toTestString()) } with(content.sections[1]) { assertEquals("Parameters", tag) assertEquals("value", subjectName) - assertEquals("is int parameter", toTestString()) + assertEquals("render(Type:String,SUMMARY): is int parameter", toTestString()) } with(content.sections[2]) { assertEquals("Author", tag) diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index 46a57278..69d19944 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -39,6 +39,7 @@ interface DokkaConfiguration { val languageVersion: String? val apiVersion: String? val noStdlibLink: Boolean + val noJdkLink: Boolean val cacheRoot: String? val suppressedFiles: List val collectInheritedExtensionsFromLibraries: Boolean @@ -102,6 +103,7 @@ data class SerializeOnlyDokkaConfiguration( override val perPackageOptions: List, override val externalDocumentationLinks: List, override val noStdlibLink: Boolean, + override val noJdkLink: Boolean, override val cacheRoot: String?, override val suppressedFiles: List, override val languageVersion: String?, diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index d1b6bef5..79583a1f 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -40,6 +40,7 @@ class DokkaAntTask: Task() { var jdkVersion: Int = 6 var noStdlibLink: Boolean = false + var noJdkLink: Boolean = false var skipDeprecated: Boolean = false @@ -131,6 +132,7 @@ class DokkaAntTask: Task() { perPackageOptions = antPackageOptions, externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, cacheRoot = cacheRoot, languageVersion = languageVersion, apiVersion = apiVersion diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 4812e217..d3a341e0 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -124,6 +124,9 @@ open class DokkaTask : DefaultTask() { @Input var noStdlibLink: Boolean = false + @Input + var noJdkLink: Boolean = false + @Optional @Input var cacheRoot: String? = null @@ -309,11 +312,12 @@ open class DokkaTask : DefaultTask() { perPackageOptions, externalDocumentationLinks, noStdlibLink, - cacheRoot, - collectSuppressedFiles(sourceRoots), - languageVersion, - apiVersion, - collectInheritedExtensionsFromLibraries + noJdkLink, + cacheRoot, + collectSuppressedFiles(sourceRoots), + languageVersion, + apiVersion, + collectInheritedExtensionsFromLibraries ) -- cgit