diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2020-09-16 15:49:24 +0200 |
---|---|---|
committer | Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> | 2020-09-24 10:57:56 +0200 |
commit | fb75185dee2184c380dcf9330e93b73b33539f99 (patch) | |
tree | ae381a3e95b33be1c53a54e5db3bd36c4f2de501 /plugins/base/src/test | |
parent | e32bca66e1bf25690fcc54c44cbae367959feb6d (diff) | |
download | dokka-fb75185dee2184c380dcf9330e93b73b33539f99.tar.gz dokka-fb75185dee2184c380dcf9330e93b73b33539f99.tar.bz2 dokka-fb75185dee2184c380dcf9330e93b73b33539f99.zip |
Escape special characters in file names
Diffstat (limited to 'plugins/base/src/test')
-rw-r--r-- | plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt | 96 |
1 files changed, 88 insertions, 8 deletions
diff --git a/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt index 89161080..6426c0e1 100644 --- a/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt +++ b/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt @@ -2,21 +2,26 @@ 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() { - @Test - fun `#644 same directory for module and package`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/") - } +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 @@ -38,4 +43,79 @@ class DefaultLocationProviderTest: AbstractCoreTest() { } } } + + @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<TestData> = listOf( + '|' to "[124]", + '>' to "[62]", + '<' to "[60]", + '*' to "[42]", + ':' to "[58]", + '"' to "[34]", + '?' to "[63]", + '%' to "[37]" + ).map { + TestData(it.first, it.second) + } + } } |