aboutsummaryrefslogtreecommitdiff
path: root/dokka-subprojects/core/src/test
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /dokka-subprojects/core/src/test
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'dokka-subprojects/core/src/test')
-rw-r--r--dokka-subprojects/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt76
-rw-r--r--dokka-subprojects/core/src/test/kotlin/model/DisplaySourceSetTest.kt63
-rw-r--r--dokka-subprojects/core/src/test/kotlin/model/DocumentableTest.kt115
-rw-r--r--dokka-subprojects/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt72
-rw-r--r--dokka-subprojects/core/src/test/kotlin/utilities/JsonKtTest.kt80
5 files changed, 406 insertions, 0 deletions
diff --git a/dokka-subprojects/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt b/dokka-subprojects/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt
new file mode 100644
index 00000000..261ca325
--- /dev/null
+++ b/dokka-subprojects/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package model
+
+import org.jetbrains.dokka.DokkaSourceSetID
+import org.jetbrains.dokka.model.CompositeSourceSetID
+import kotlin.test.*
+
+class CompositeSourceSetIDTest {
+
+ @Test
+ fun `constructor fails with empty collection`() {
+ assertFailsWith<IllegalArgumentException>("Expected no construction of empty `CompositeSourceSetID`") {
+ CompositeSourceSetID(emptyList())
+ }
+ }
+
+ @Test
+ fun `merged for single source set`() {
+ val sourceSetID = DokkaSourceSetID("module", "sourceSet")
+ val composite = CompositeSourceSetID(sourceSetID)
+
+ assertEquals(
+ composite.merged, sourceSetID,
+ "Expected merged source set id to be equal to single child"
+ )
+ }
+
+ @Test
+ fun `merged with multiple source sets`() {
+ val composite = CompositeSourceSetID(
+ listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"), DokkaSourceSetID("m3", "s3"))
+ )
+
+ assertEquals(
+ DokkaSourceSetID("m1+m2+m3", "s1+s2+s3"), composite.merged,
+ "Expected merged source set id to concatenate source sets"
+ )
+ }
+
+ @Test
+ fun `contains with child sourceSetID`() {
+ val composite = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2")))
+
+ assertFalse(
+ DokkaSourceSetID("m3", "s3") in composite,
+ "Expected source set id not being contained in composite"
+ )
+
+ assertTrue(
+ DokkaSourceSetID("m1", "s1") in composite,
+ "Expected child source set id being contained in composite"
+ )
+
+ assertTrue(
+ DokkaSourceSetID("m1+m2", "s1+s2") in composite,
+ "Expected merged source set id being contained in composite"
+ )
+ }
+
+ @Test
+ fun `plus operator`() {
+ val composite = DokkaSourceSetID("m1", "s1") + DokkaSourceSetID("m2", "s2") + DokkaSourceSetID("m3", "s3")
+ assertEquals(
+ DokkaSourceSetID("m1+m2+m3", "s1+s2+s3"), composite.merged,
+ "Expected all three source sets being merged in order"
+ )
+ }
+
+ operator fun DokkaSourceSetID.plus(other: DokkaSourceSetID): CompositeSourceSetID {
+ return CompositeSourceSetID(listOf(this, other))
+ }
+
+}
diff --git a/dokka-subprojects/core/src/test/kotlin/model/DisplaySourceSetTest.kt b/dokka-subprojects/core/src/test/kotlin/model/DisplaySourceSetTest.kt
new file mode 100644
index 00000000..d7b7a2a5
--- /dev/null
+++ b/dokka-subprojects/core/src/test/kotlin/model/DisplaySourceSetTest.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package model
+
+import org.jetbrains.dokka.DokkaSourceSetID
+import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.model.*
+import kotlin.test.Test
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+class DisplaySourceSetTest {
+ @Test
+ fun `contains sourceSetId`() {
+ val contentSourceSet = DisplaySourceSet(
+ sourceSetIDs = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"))),
+ name = "displayName",
+ platform = Platform.common
+ )
+
+ assertFalse(
+ DokkaSourceSetID("m3", "s3") in contentSourceSet.sourceSetIDs,
+ "Expected source set id not being contained in content source set"
+ )
+
+ assertTrue(
+ DokkaSourceSetID("m1", "s1") in contentSourceSet.sourceSetIDs,
+ "Expected source set id being contained in content source set"
+ )
+
+ assertTrue(
+ DokkaSourceSetID("m1+m2", "s1+s2") in contentSourceSet.sourceSetIDs,
+ "Expected merged source set being contained in content source set"
+ )
+ }
+
+ @Test
+ fun `Iterable contains sourceSetId`() {
+
+ val contentSourceSet = DisplaySourceSet(
+ sourceSetIDs = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"))),
+ name = "displayName",
+ platform = Platform.common
+ )
+
+ assertFalse(
+ DokkaSourceSetID("m3", "s3") in listOf(contentSourceSet).computeSourceSetIds(),
+ "Expected source set id not being contained in content source set"
+ )
+
+ assertTrue(
+ DokkaSourceSetID("m1", "s1") in listOf(contentSourceSet).computeSourceSetIds(),
+ "Expected source set id being contained in content source set"
+ )
+
+ assertTrue(
+ DokkaSourceSetID("m1+m2", "s1+s2") in listOf(contentSourceSet).computeSourceSetIds(),
+ "Expected merged source set being contained in content source set"
+ )
+ }
+}
diff --git a/dokka-subprojects/core/src/test/kotlin/model/DocumentableTest.kt b/dokka-subprojects/core/src/test/kotlin/model/DocumentableTest.kt
new file mode 100644
index 00000000..56d32bb2
--- /dev/null
+++ b/dokka-subprojects/core/src/test/kotlin/model/DocumentableTest.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package model
+
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.model.properties.PropertyContainer
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DocumentableTest {
+
+ @Test
+ fun withDescendents() {
+ val dClass = DClass(
+ dri = DRI(),
+ name = "TestClass",
+ constructors = emptyList(),
+ classlikes = emptyList(),
+ companion = null,
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ visibility = emptyMap(),
+ generics = emptyList(),
+ modifier = emptyMap(),
+ properties = emptyList(),
+ sources = emptyMap(),
+ sourceSets = emptySet(),
+ supertypes = emptyMap(),
+ isExpectActual = false,
+ functions = listOf(
+ DFunction(
+ dri = DRI(),
+ name = "function0",
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ visibility = emptyMap(),
+ generics = emptyList(),
+ modifier = emptyMap(),
+ sources = emptyMap(),
+ sourceSets = emptySet(),
+ type = Void,
+ receiver = null,
+ isConstructor = false,
+ isExpectActual = false,
+ parameters = listOf(
+ DParameter(
+ dri = DRI(),
+ name = "f0p0",
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ sourceSets = emptySet(),
+ type = Void
+ ),
+ DParameter(
+ dri = DRI(),
+ name = "f0p1",
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ sourceSets = emptySet(),
+ type = Void
+ )
+ )
+ ),
+ DFunction(
+ dri = DRI(),
+ name = "function1",
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ visibility = emptyMap(),
+ generics = emptyList(),
+ modifier = emptyMap(),
+ sources = emptyMap(),
+ sourceSets = emptySet(),
+ type = Void,
+ receiver = null,
+ isConstructor = false,
+ isExpectActual = false,
+ parameters = listOf(
+ DParameter(
+ dri = DRI(),
+ name = "f1p0",
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ sourceSets = emptySet(),
+ type = Void
+ ),
+ DParameter(
+ dri = DRI(),
+ name = "f1p1",
+ documentation = emptyMap(),
+ expectPresentInSet = null,
+ extra = PropertyContainer.empty(),
+ sourceSets = emptySet(),
+ type = Void
+ )
+ )
+ )
+ )
+ )
+
+ assertEquals(
+ listOf("TestClass", "function0", "f0p0", "f0p1", "function1", "f1p0", "f1p1"),
+ dClass.withDescendants().map { it.name }.toList()
+ )
+ }
+}
diff --git a/dokka-subprojects/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt b/dokka-subprojects/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
new file mode 100644
index 00000000..c10cb32d
--- /dev/null
+++ b/dokka-subprojects/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package utilities
+
+import org.jetbrains.dokka.DokkaConfigurationImpl
+import org.jetbrains.dokka.DokkaSourceSetID
+import org.jetbrains.dokka.DokkaSourceSetImpl
+import org.jetbrains.dokka.toCompactJsonString
+import java.io.File
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class DokkaConfigurationJsonTest {
+ @Test
+ fun `simple configuration toJsonString then parseJson`() {
+ val configuration = DokkaConfigurationImpl(
+ moduleName = "moduleName",
+ outputDir = File("customOutputDir"),
+ pluginsClasspath = listOf(File("plugins/customPlugin.jar")),
+ sourceSets = listOf(
+ DokkaSourceSetImpl(
+ sourceRoots = setOf(File("customSourceRoot")),
+ sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName")
+ )
+ )
+ )
+
+ val jsonString = configuration.toCompactJsonString()
+ val parsedConfiguration = DokkaConfigurationImpl(jsonString)
+ assertEquals(configuration, parsedConfiguration)
+ }
+
+ @Test
+ fun `parse simple configuration json`() {
+ val json = """
+ {
+ "moduleName": "moduleName",
+ "outputDir": "customOutputDir",
+ "pluginsClasspath": [ "plugins/customPlugin.jar" ],
+ "sourceSets": [
+ {
+ "sourceSetID": {
+ "scopeId": "customModuleName",
+ "sourceSetName": "customSourceSetName"
+ },
+ "sourceRoots": [ "customSourceRoot" ],
+ "classpath": [ "classpath/custom1.jar", "classpath/custom2.jar" ]
+ }
+ ]
+ }
+ """.trimIndent()
+
+ val parsedConfiguration = DokkaConfigurationImpl(json)
+ assertEquals(
+ DokkaConfigurationImpl(
+ moduleName = "moduleName",
+ outputDir = File("customOutputDir"),
+ pluginsClasspath = listOf(File("plugins/customPlugin.jar")),
+ sourceSets = listOf(
+ DokkaSourceSetImpl(
+ sourceRoots = setOf(File("customSourceRoot")),
+ sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName"),
+ classpath = listOf(File("classpath/custom1.jar"), File("classpath/custom2.jar"))
+ )
+ )
+ ),
+ parsedConfiguration
+ )
+ }
+}
diff --git a/dokka-subprojects/core/src/test/kotlin/utilities/JsonKtTest.kt b/dokka-subprojects/core/src/test/kotlin/utilities/JsonKtTest.kt
new file mode 100644
index 00000000..c706de5f
--- /dev/null
+++ b/dokka-subprojects/core/src/test/kotlin/utilities/JsonKtTest.kt
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package utilities
+
+import org.jetbrains.dokka.utilities.parseJson
+import org.jetbrains.dokka.utilities.serializeAsCompactJson
+import org.jetbrains.dokka.utilities.serializeAsPrettyJson
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+class JsonTest {
+
+ @Test
+ fun `should serialize an object as compact json`() {
+ val testObject = SimpleTestDataClass(
+ someString = "Foo",
+ someInt = 42,
+ someDouble = 42.0
+ )
+
+ val actual = serializeAsCompactJson(testObject)
+ val expected = "{\"someString\":\"Foo\",\"someInt\":42,\"someIntWithDefaultValue\":42,\"someDouble\":42.0}"
+
+ assertEquals(expected, actual)
+ }
+
+ @Test
+ fun `should serialize an object as pretty json`() {
+ val testObject = SimpleTestDataClass(
+ someString = "Foo",
+ someInt = 42,
+ someDouble = 42.0
+ )
+
+ val actual = serializeAsPrettyJson(testObject)
+
+ val expected = """
+ {
+ "someString" : "Foo",
+ "someInt" : 42,
+ "someIntWithDefaultValue" : 42,
+ "someDouble" : 42.0
+ }""".trimIndent().withSystemLineSeparator()
+
+ assertEquals(expected, actual)
+ }
+
+ @Test
+ fun `should keep order of Set after serialize and deserialize`() {
+ val testObject = SimpleTestSetDataClass(
+ someStringSet = setOf("Foo", "Bar", "ABC")
+ )
+ val expected = testObject.someStringSet.toList() // ["Foo", "Bar", "ABC"]
+
+ val jsonString = serializeAsCompactJson(testObject)
+ val parsedClass: SimpleTestSetDataClass = parseJson(jsonString)
+ val actual = parsedClass.someStringSet.toList()
+
+ assertEquals(expected, actual)
+ }
+
+ /**
+ * If the expected output was generated on Linux, but the tests are run under Windows,
+ * the test might fail when comparing the strings due to different separators.
+ */
+ private fun String.withSystemLineSeparator(): String = this.replace("\n", System.lineSeparator())
+}
+
+data class SimpleTestDataClass(
+ val someString: String,
+ val someInt: Int,
+ val someIntWithDefaultValue: Int = 42,
+ val someDouble: Double
+)
+
+data class SimpleTestSetDataClass(
+ val someStringSet: Set<String>
+)