aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test
diff options
context:
space:
mode:
authorKamil Doległo <9080183+kamildoleglo@users.noreply.github.com>2021-07-05 14:10:23 +0200
committerGitHub <noreply@github.com>2021-07-05 14:10:23 +0200
commit0bf1d0f5491a62c56393a06cdfb4168778d9829e (patch)
tree808f631e72b652dc2c3d5929f85f677968bc56f6 /plugins/base/src/test
parenta1d44ab80df217196fe5ee9455c7cf1c135e3b07 (diff)
downloaddokka-0bf1d0f5491a62c56393a06cdfb4168778d9829e.tar.gz
dokka-0bf1d0f5491a62c56393a06cdfb4168778d9829e.tar.bz2
dokka-0bf1d0f5491a62c56393a06cdfb4168778d9829e.zip
Flatten multi-module structure (#1980)
* Add support for multimodule package lists * Merge package-lists in multi-module generation * Remove double-wrapping of modules in multi-module generation * Handle empty modules in package lists
Diffstat (limited to 'plugins/base/src/test')
-rw-r--r--plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt4
-rw-r--r--plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt0
-rw-r--r--plugins/base/src/test/kotlin/locationProvider/MultiModuleLinkingTest.kt71
-rw-r--r--plugins/base/src/test/kotlin/packageList/PackageListTest.kt65
-rw-r--r--plugins/base/src/test/resources/locationProvider/multi-module-package-list8
5 files changed, 146 insertions, 2 deletions
diff --git a/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt
index c85b5946..071997fc 100644
--- a/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt
+++ b/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt
@@ -19,7 +19,7 @@ class AndroidExternalLocationProviderTest : BaseAbstractTest() {
URL("https://developer.android.com/reference/kotlin"),
PackageList(
RecognizedLinkFormat.DokkaHtml,
- setOf("android.content", "android.net"),
+ mapOf("" to setOf("android.content", "android.net")),
emptyMap(),
URL("file://not-used")
)
@@ -28,7 +28,7 @@ class AndroidExternalLocationProviderTest : BaseAbstractTest() {
URL("https://developer.android.com/reference/kotlin"),
PackageList(
RecognizedLinkFormat.DokkaHtml,
- setOf("androidx.appcompat.app"),
+ mapOf("" to setOf("androidx.appcompat.app")),
emptyMap(),
URL("file://not-used")
)
diff --git a/plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt
deleted file mode 100644
index e69de29b..00000000
--- a/plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt
+++ /dev/null
diff --git a/plugins/base/src/test/kotlin/locationProvider/MultiModuleLinkingTest.kt b/plugins/base/src/test/kotlin/locationProvider/MultiModuleLinkingTest.kt
new file mode 100644
index 00000000..aefe913c
--- /dev/null
+++ b/plugins/base/src/test/kotlin/locationProvider/MultiModuleLinkingTest.kt
@@ -0,0 +1,71 @@
+package locationProvider
+
+import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider
+import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation
+import org.jetbrains.dokka.base.resolvers.shared.PackageList
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import java.net.URL
+
+class MultiModuleLinkingTest : BaseAbstractTest() {
+ private val testDataDir =
+ getTestDataDir("locationProvider").toAbsolutePath().toString().removePrefix("/").let { "/$it" }
+ private val exampleDomain = "https://example.com"
+ private val packageListURL = URL("file://$testDataDir/multi-module-package-list")
+ private val kotlinLang = "https://kotlinlang.org/api/latest/jvm/stdlib"
+ private val stdlibPackageListURL = URL("file://$testDataDir/stdlib-package-list")
+ private val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ classpath += jvmStdlibPath!!
+ }
+ }
+ }
+
+ private fun getTestLocationProvider(context: DokkaContext? = null): DefaultExternalLocationProvider {
+ val dokkaContext = context ?: DokkaContext.create(configuration, logger, emptyList())
+ val packageList = PackageList.load(packageListURL, 8, true)!!
+ val externalDocumentation =
+ ExternalDocumentation(URL(exampleDomain), packageList)
+ return DefaultExternalLocationProvider(externalDocumentation, ".html", dokkaContext)
+ }
+
+ private fun getStdlibTestLocationProvider(context: DokkaContext? = null): DefaultExternalLocationProvider {
+ val dokkaContext = context ?: DokkaContext.create(configuration, logger, emptyList())
+ val packageList = PackageList.load(stdlibPackageListURL, 8, true)!!
+ val externalDocumentation =
+ ExternalDocumentation(URL(kotlinLang), packageList)
+ return DefaultExternalLocationProvider(externalDocumentation, ".html", dokkaContext)
+ }
+
+ @Test
+ fun `should link to a multi-module declaration`() {
+ val locationProvider = getTestLocationProvider()
+ val dri = DRI("baz", "BazClass")
+
+ assertEquals("$exampleDomain/moduleB/baz/-baz-class/index.html", locationProvider.resolve(dri))
+ }
+
+ @Test
+ fun `should not fail on non-present package`() {
+ val stdlibLocationProvider = getStdlibTestLocationProvider()
+ val locationProvider = getTestLocationProvider()
+ val dri = DRI("baz", "BazClass")
+
+ assertEquals(null, stdlibLocationProvider.resolve(dri))
+ assertEquals("$exampleDomain/moduleB/baz/-baz-class/index.html", locationProvider.resolve(dri))
+ }
+
+ @Test
+ fun `should handle relocations`() {
+ val locationProvider = getTestLocationProvider()
+ val dri = DRI("", "NoPackageClass")
+
+ assertEquals("$exampleDomain/moduleB/[root]/-no-package-class/index.html", locationProvider.resolve(dri))
+ }
+}
diff --git a/plugins/base/src/test/kotlin/packageList/PackageListTest.kt b/plugins/base/src/test/kotlin/packageList/PackageListTest.kt
new file mode 100644
index 00000000..310a23c6
--- /dev/null
+++ b/plugins/base/src/test/kotlin/packageList/PackageListTest.kt
@@ -0,0 +1,65 @@
+package packageList
+
+import org.jetbrains.dokka.base.renderers.PackageListService
+import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+
+class PackageListTest {
+ @Test
+ fun `one module package list is created correctly`() {
+ val nonStandardLocations = mapOf("//longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/" to "[JS root]/long-array-with-fun.html")
+ val modules = mapOf("" to setOf("foo", "bar", "baz"))
+ val format = RecognizedLinkFormat.DokkaHtml
+ val output = PackageListService.renderPackageList(nonStandardLocations, modules, format.formatName, format.linkExtension)
+ val expected = """
+ |${'$'}dokka.format:html-v1
+ |${'$'}dokka.linkExtension:html
+ |${'$'}dokka.location://longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/[JS root]/long-array-with-fun.html
+ |bar
+ |baz
+ |foo
+ |""".trimMargin()
+ assertEquals(expected, output)
+ }
+
+ @Test
+ fun `multi-module package list is created correctly`() {
+ val nonStandardLocations = mapOf("//longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/" to "[JS root]/long-array-with-fun.html")
+ val modules = mapOf("moduleA" to setOf("foo", "bar"), "moduleB" to setOf("baz"), "moduleC" to setOf("qux"))
+ val format = RecognizedLinkFormat.DokkaHtml
+ val output = PackageListService.renderPackageList(nonStandardLocations, modules, format.formatName, format.linkExtension)
+ val expected = """
+ |${'$'}dokka.format:html-v1
+ |${'$'}dokka.linkExtension:html
+ |${'$'}dokka.location://longArrayWithFun/#kotlin.Int#kotlin.Function1[kotlin.Int,kotlin.Long]/PointingToDeclaration/[JS root]/long-array-with-fun.html
+ |module:moduleA
+ |bar
+ |foo
+ |module:moduleB
+ |baz
+ |module:moduleC
+ |qux
+ |""".trimMargin()
+ assertEquals(expected, output)
+ }
+
+ @Test
+ fun `empty package set in module`() {
+ val nonStandardLocations = emptyMap<String, String>()
+ val modules = mapOf("moduleA" to setOf("foo", "bar"), "moduleB" to emptySet(), "moduleC" to setOf("qux"))
+ val format = RecognizedLinkFormat.DokkaHtml
+ val output = PackageListService.renderPackageList(nonStandardLocations, modules, format.formatName, format.linkExtension)
+ val expected = """
+ |${'$'}dokka.format:html-v1
+ |${'$'}dokka.linkExtension:html
+ |
+ |module:moduleA
+ |bar
+ |foo
+ |module:moduleC
+ |qux
+ |""".trimMargin()
+ assertEquals(expected, output)
+ }
+}
diff --git a/plugins/base/src/test/resources/locationProvider/multi-module-package-list b/plugins/base/src/test/resources/locationProvider/multi-module-package-list
new file mode 100644
index 00000000..03f33d9a
--- /dev/null
+++ b/plugins/base/src/test/resources/locationProvider/multi-module-package-list
@@ -0,0 +1,8 @@
+$dokka.format:html-v1
+$dokka.linkExtension:html
+$dokka.location:/NoPackageClass///PointingToDeclaration/moduleB/[root]/-no-package-class/index.html
+module:moduleA
+foo
+bar
+module:moduleB
+baz