From adf99ba137bc6e40c3add9df70f906a16f9199a4 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 8 Sep 2020 00:13:13 +0200 Subject: Add tests for relocations in ExternalLocationProviders --- .../AndroidExternalLocationProviderTest.kt | 16 +++ .../DefaultExternalLocationProviderTest.kt | 13 ++- .../DefaultLocationProviderTest.kt | 121 --------------------- .../Dokka010ExternalLocationProviderTest.kt | 21 +++- .../locationProvider/DokkaLocationProviderTest.kt | 121 +++++++++++++++++++++ 5 files changed, 165 insertions(+), 127 deletions(-) delete mode 100644 plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt create mode 100644 plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt (limited to 'plugins/base/src/test') diff --git a/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt index ea2c434f..b2cfe176 100644 --- a/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt +++ b/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt @@ -86,4 +86,20 @@ class AndroidExternalLocationProviderTest : AbstractCoreTest() { locationProvider.resolve(dri) ) } + + @Test + fun `should return null for method not in list`() { + val locationProvider = getTestLocationProvider(android) + val dri = DRI( + "foo", + "Bar", + Callable( + "baz", + null, + emptyList() + ) + ) + + assertEquals(null, locationProvider.resolve(dri)) + } } diff --git a/plugins/base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt index bfa60d24..7d21e0a7 100644 --- a/plugins/base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt +++ b/plugins/base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt @@ -1,6 +1,5 @@ package locationProvider -import org.jetbrains.dokka.ExternalDocumentationLink import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.PackageList @@ -23,7 +22,6 @@ class DefaultExternalLocationProviderTest : AbstractCoreTest() { sourceSet { sourceRoots = listOf("src/") classpath += jvmStdlibPath!! - ExternalDocumentationLink(kotlinLang, packageListURL.toString()) } } } @@ -62,4 +60,15 @@ class DefaultExternalLocationProviderTest : AbstractCoreTest() { assertEquals("$kotlinLang/kotlin-stdlib/[JS root]/long-array.html", locationProvider.resolve(dri)) } + + @Test + fun `should return null for class not in list`() { + val locationProvider = getTestLocationProvider() + val dri = DRI( + "foo", + "Bar" + ) + + assertEquals(null, locationProvider.resolve(dri)) + } } diff --git a/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt deleted file mode 100644 index 6426c0e1..00000000 --- a/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt +++ /dev/null @@ -1,121 +0,0 @@ -package locationProvider - -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider -import org.jetbrains.dokka.model.dfs -import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -class DefaultLocationProviderTest : AbstractCoreTest() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } - } - } - - @Test - fun `#644 same directory for module and package`() { - testInline( - """ - |/src/main/kotlin/basic/Test.kt - | - |class Test { - | val x = 1 - |} - """.trimMargin(), - configuration - ) { - var context: DokkaContext? = null - pluginsSetupStage = { - context = it - } - - pagesGenerationStage = { module -> - val lp = DokkaLocationProvider(module, context!!) - assertNotEquals(lp.resolve(module.children.single()).removePrefix("/"), lp.resolve(module)) - } - } - } - - @Test - fun `should escape illegal pipe character in file name`() { - /* - Currently even kotlin doesn't escape pipe characters in file names so it is impossible to have a - class named || on windows - */ - testInline( - """ - |/src/main/kotlin/basic/Test.kt - | - |class Test { - | fun `||`() { } - |} - """.trimMargin(), - configuration - ) { - var context: DokkaContext? = null - pluginsSetupStage = { - context = it - } - - pagesGenerationStage = { module -> - val lp = DokkaLocationProvider(module, context!!) - val functionWithPipes = module.dfs { it.name == "||" } - assertNotNull(functionWithPipes, "Failed to find a page for a function named ||") - assertEquals(lp.resolve(functionWithPipes), "[root]/-test/[124][124].html") - } - } - } - - @ParameterizedTest - @MethodSource - fun runEscapeTestForCharacter(data: TestData) { - testInline( - """ - |/src/main/kotlin/basic/Test.kt - | - |class Test { - | fun `${data.tested}`() { } - |} - """.trimMargin(), - configuration - ) { - var context: DokkaContext? = null - pluginsSetupStage = { - context = it - } - - pagesGenerationStage = { module -> - val lp = DokkaLocationProvider(module, context!!) - val functionWithPipes = module.dfs { it.name == "${data.tested}" } - assertNotNull(functionWithPipes, "Failed to find a page for a function named ${data.tested}") - assertEquals(lp.resolve(functionWithPipes), "[root]/-test/${data.expectedReplacement}.html") - } - } - } - - data class TestData(val tested: Char, val expectedReplacement: String) - - companion object TestDataSources { - @JvmStatic - fun runEscapeTestForCharacter(): List = listOf( - '|' to "[124]", - '>' to "[62]", - '<' to "[60]", - '*' to "[42]", - ':' to "[58]", - '"' to "[34]", - '?' to "[63]", - '%' to "[37]" - ).map { - TestData(it.first, it.second) - } - } -} diff --git a/plugins/base/src/test/kotlin/locationProvider/Dokka010ExternalLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/Dokka010ExternalLocationProviderTest.kt index 31ffa0b3..165c7c15 100644 --- a/plugins/base/src/test/kotlin/locationProvider/Dokka010ExternalLocationProviderTest.kt +++ b/plugins/base/src/test/kotlin/locationProvider/Dokka010ExternalLocationProviderTest.kt @@ -1,15 +1,13 @@ package locationProvider -import org.jetbrains.dokka.ExternalDocumentationLink import org.jetbrains.dokka.base.resolvers.external.Dokka010ExternalLocationProvider -import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.PackageList import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.TypeConstructor +import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.net.URL @@ -24,7 +22,6 @@ class Dokka010ExternalLocationProviderTest : AbstractCoreTest() { sourceSet { sourceRoots = listOf("src/") classpath += jvmStdlibPath!! - ExternalDocumentationLink(kotlinLang, packageListURL.toString()) } } } @@ -103,4 +100,20 @@ class Dokka010ExternalLocationProviderTest : AbstractCoreTest() { assertEquals("$kotlinLang/kotlin/-int/max-value.html", locationProvider.resolve(dri)) } + + @Test + fun `should return null for method not in list`() { + val locationProvider = getTestLocationProvider() + val dri = DRI( + "foo", + "Bar", + Callable( + "baz", + null, + emptyList() + ) + ) + + assertEquals(null, locationProvider.resolve(dri)) + } } diff --git a/plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt new file mode 100644 index 00000000..b35310a5 --- /dev/null +++ b/plugins/base/src/test/kotlin/locationProvider/DokkaLocationProviderTest.kt @@ -0,0 +1,121 @@ +package locationProvider + +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.MethodSource +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class DefaultLocationProviderTest : AbstractCoreTest() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + @Test + fun `#644 same directory for module and package`() { + testInline( + """ + |/src/main/kotlin/basic/Test.kt + | + |class Test { + | val x = 1 + |} + """.trimMargin(), + configuration + ) { + var context: DokkaContext? = null + pluginsSetupStage = { + context = it + } + + pagesGenerationStage = { module -> + val lp = DokkaLocationProvider(module, context!!) + assertNotEquals(lp.resolve(module.children.single()).removePrefix("/"), lp.resolve(module)) + } + } + } + + @Test + fun `should escape illegal pipe character in file name`() { + /* + Currently even kotlin doesn't escape pipe characters in file names so it is impossible to have a + class named || on windows + */ + testInline( + """ + |/src/main/kotlin/basic/Test.kt + | + |class Test { + | fun `||`() { } + |} + """.trimMargin(), + configuration + ) { + var context: DokkaContext? = null + pluginsSetupStage = { + context = it + } + + pagesGenerationStage = { module -> + val lp = DokkaLocationProvider(module, context!!) + val functionWithPipes = module.dfs { it.name == "||" } + assertNotNull(functionWithPipes, "Failed to find a page for a function named ||") + assertEquals(lp.resolve(functionWithPipes), "[root]/-test/[124][124].html") + } + } + } + + @ParameterizedTest + @MethodSource + fun runEscapeTestForCharacter(data: TestData) { + testInline( + """ + |/src/main/kotlin/basic/Test.kt + | + |class Test { + | fun `${data.tested}`() { } + |} + """.trimMargin(), + configuration + ) { + var context: DokkaContext? = null + pluginsSetupStage = { + context = it + } + + pagesGenerationStage = { module -> + val lp = DokkaLocationProvider(module, context!!) + val functionWithPipes = module.dfs { it.name == "${data.tested}" } + assertNotNull(functionWithPipes, "Failed to find a page for a function named ${data.tested}") + assertEquals(lp.resolve(functionWithPipes), "[root]/-test/${data.expectedReplacement}.html") + } + } + } + + data class TestData(val tested: Char, val expectedReplacement: String) + + companion object TestDataSources { + @JvmStatic + fun runEscapeTestForCharacter(): List = listOf( + '|' to "[124]", + '>' to "[62]", + '<' to "[60]", + '*' to "[42]", + ':' to "[58]", + '"' to "[34]", + '?' to "[63]", + '%' to "[37]" + ).map { + TestData(it.first, it.second) + } + } +} -- cgit