diff options
author | Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> | 2021-07-05 14:10:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 14:10:23 +0200 |
commit | 0bf1d0f5491a62c56393a06cdfb4168778d9829e (patch) | |
tree | 808f631e72b652dc2c3d5929f85f677968bc56f6 /plugins/base/src/test/kotlin/locationProvider | |
parent | a1d44ab80df217196fe5ee9455c7cf1c135e3b07 (diff) | |
download | dokka-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/kotlin/locationProvider')
3 files changed, 73 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)) + } +} |