diff options
Diffstat (limited to 'plugins/base/src/test/kotlin/model')
-rw-r--r-- | plugins/base/src/test/kotlin/model/ClassesTest.kt | 11 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/model/FunctionsTest.kt | 10 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/model/InheritorsTest.kt | 94 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/model/JavaTest.kt | 9 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/model/PropertyTest.kt | 23 |
5 files changed, 122 insertions, 25 deletions
diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index d627dab4..4855056c 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -6,6 +6,7 @@ import org.jetbrains.dokka.model.DFunction import org.junit.Test import utils.AbstractModelTest import utils.assertNotNull +import utils.name import utils.supers @@ -54,7 +55,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class parameters counts 1 with(parameters.firstOrNull().assertNotNull("Constructor parameter")) { name equals "name" - type.constructorFqName equals "kotlin.String" + type.name equals "String" } } @@ -76,7 +77,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class children counts 5 with((this / "fn").cast<DFunction>()) { - type.constructorFqName equals "kotlin.Unit" + type.name equals "Unit" parameters counts 0 visibility.values allEquals KotlinVisibility.Public } @@ -132,7 +133,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class with((this / "foo").cast<DFunction>()) { name equals "foo" parameters counts 0 - type.constructorFqName equals "kotlin.Unit" + type.name equals "Unit" } } } @@ -172,7 +173,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class ) { with((this / "classes" / "Klass").cast<DClass>()) { name equals "Klass" - modifier equals KotlinModifier.Sealed + modifier equals Sealed } } } @@ -356,7 +357,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class parameters counts 1 with(parameters.firstOrNull() notNull "Constructor parameter") { name equals "s" - type.constructorFqName equals "kotlin.String" + type.name equals "String" } } } diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index f3a7adc7..97d6b237 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -19,7 +19,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { with((this / "function" / "fn").cast<DFunction>()) { name equals "fn" - type.constructorFqName equals "kotlin.Unit" + type.name equals "Unit" this.children.assertCount(0, "Function children: ") } } @@ -55,7 +55,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun with(fn2) { name equals "fn" parameters.assertCount(1) - parameters.first().type.constructorFqName equals "kotlin.Int" + parameters.first().type.name equals "Int" } } } @@ -94,7 +94,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun name equals "fn" parameters counts 1 receiver.assertNotNull("fn(Int) receiver") - parameters.first().type.constructorFqName equals "kotlin.Int" + parameters.first().type.name equals "Int" } } } @@ -121,11 +121,11 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun parameters counts 1 parameters.firstOrNull().assertNotNull("Parameter: ").also { it.name equals "x" - it.type.constructorFqName equals "kotlin.Int" + it.type.name equals "Int" it.comments() equals "parameter" } - type.assertNotNull("Return type: ").constructorFqName equals "kotlin.Unit" + type.assertNotNull("Return type: ").name equals "Unit" } } } diff --git a/plugins/base/src/test/kotlin/model/InheritorsTest.kt b/plugins/base/src/test/kotlin/model/InheritorsTest.kt new file mode 100644 index 00000000..b3d7bf92 --- /dev/null +++ b/plugins/base/src/test/kotlin/model/InheritorsTest.kt @@ -0,0 +1,94 @@ +package model + +import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.transformers.documentables.InheritorsExtractorTransformer +import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo +import org.jetbrains.dokka.model.DInterface +import org.jetbrains.dokka.model.DPackage +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.junit.Test +import utils.AbstractModelTest +import utils.assertNotNull + +class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt", "inheritors") { + + object InheritorsPlugin : DokkaPlugin() { + val inheritors by extending { + CoreExtensions.documentableTransformer with InheritorsExtractorTransformer() + } + } + + @Test + fun simple() { + inlineModelTest( + """|interface A{} + |class B() : A {} + """.trimMargin(), + pluginsOverrides = listOf(InheritorsPlugin) + ) { + with((this / "inheritors" / "A").cast<DInterface>()) { + val map = extra[InheritorsInfo].assertNotNull("InheritorsInfo").value.map + with(map.keys.also { it counts 1 }.find { it.platformType == Platform.jvm }.assertNotNull("jvm key").let { map[it]!! } + ) { + this counts 1 + first().classNames equals "B" + } + } + } + } + + @Test + fun multiplatform() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("common/src/", "jvm/src/") + analysisPlatform = "jvm" + targets = listOf("jvm") + } + pass { + sourceRoots = listOf("common/src/", "js/src/") + analysisPlatform = "js" + targets = listOf("js") + } + } + } + + testInline( + """ + |/common/src/main/kotlin/inheritors/Test.kt + |package inheritors + |interface A{} + |/jvm/src/main/kotlin/inheritors/Test.kt + |package inheritors + |class B() : A {} + |/js/src/main/kotlin/inheritors/Test.kt + |package inheritors + |class B() : A {} + |class C() : A {} + """.trimMargin(), + configuration, + cleanupOutput = false, + pluginOverrides = listOf(InheritorsPlugin) + ) { + documentablesTransformationStage = { m -> + with((m / "inheritors" / "A").cast<DInterface>()) { + val map = extra[InheritorsInfo].assertNotNull("InheritorsInfo").value.map + with(map.keys.also { it counts 2 }) { + with(find { it.platformType == Platform.jvm }.assertNotNull("jvm key").let { map[it]!! }) { + this counts 1 + first().classNames equals "B" + } + with(find { it.platformType == Platform.js }.assertNotNull("js key").let { map[it]!! }) { + this counts 2 + val classes = listOf("B", "C") + assert(all{ classes.contains(it.classNames) }){"One of subclasses missing in js"} + } + } + + } + } + } + } +}
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index c2545e7a..1e33d6fd 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -7,6 +7,7 @@ import org.junit.Assert.assertTrue import org.junit.Test import utils.AbstractModelTest import utils.assertNotNull +import utils.name class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { @@ -134,10 +135,10 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { with((this / "arrayToString").cast<DFunction>()) { name equals "arrayToString" - type.constructorFqName equals "java.lang.String[]" + type.name equals "Array" with(parameters.firstOrNull().assertNotNull("parameters")) { name equals "data" - type.constructorFqName equals "int[]" + type.name equals "Array" } } } @@ -196,7 +197,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { constructors.find { it.parameters.isNullOrEmpty() }.assertNotNull("Test()") with(constructors.find { it.parameters.isNotEmpty() }.assertNotNull("Test(String)")) { - parameters.firstOrNull()?.type?.constructorFqName equals "java.lang.String" + parameters.firstOrNull()?.type?.name equals "String" } } } @@ -238,7 +239,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { name equals "bar" with(parameters.firstOrNull().assertNotNull("parameter")) { name equals "x" - type.constructorFqName equals "java.lang.String..." + type.name equals "Array" } } } diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index d12e292b..4af4ee5a 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -6,6 +6,7 @@ import org.jetbrains.dokka.model.DProperty import org.junit.Test import utils.AbstractModelTest import utils.assertNotNull +import utils.name class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "property") { @@ -19,9 +20,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.String" + type.name equals "String" } - type.constructorFqName equals "kotlin.String" + type.name equals "String" } } } @@ -38,9 +39,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro children counts 0 setter.assertNotNull("Setter") with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.String" + type.name equals "String" } - type.constructorFqName equals "kotlin.String" + type.name equals "String" } } } @@ -57,9 +58,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.String" + type.name equals "String" } - type.constructorFqName equals "kotlin.String" + type.name equals "String" } } } @@ -78,7 +79,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro children counts 0 setter.assertNotNull("Setter") with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.String" + type.name equals "String" } visibility.values allEquals KotlinVisibility.Public } @@ -98,10 +99,10 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro children counts 0 with(receiver.assertNotNull("property receiver")) { name equals null - type.constructorFqName equals "kotlin.String" + type.name equals "String" } with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.Int" + type.name equals "Int" } visibility.values allEquals KotlinVisibility.Public } @@ -125,14 +126,14 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.Int" + type.name equals "Int" } } with((this / "Bar" / "property").cast<DProperty>()) { name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { - type.constructorFqName equals "kotlin.Int" + type.name equals "Int" } } } |