diff options
author | Aurimas Liutikas <aurimas@google.com> | 2020-07-13 19:41:03 -0700 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-07-15 13:26:16 +0200 |
commit | 0c848be52c90cc1136d9ccbcd55b9a290bc7b58b (patch) | |
tree | 598559b9187963e00e13d763078e289805e406f7 /plugins/mathjax | |
parent | 543155602b233639753fd5973a23b730e021d431 (diff) | |
download | dokka-0c848be52c90cc1136d9ccbcd55b9a290bc7b58b.tar.gz dokka-0c848be52c90cc1136d9ccbcd55b9a290bc7b58b.tar.bz2 dokka-0c848be52c90cc1136d9ccbcd55b9a290bc7b58b.zip |
Add a basic mathjax test
Diffstat (limited to 'plugins/mathjax')
-rw-r--r-- | plugins/mathjax/build.gradle.kts | 9 | ||||
-rw-r--r-- | plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt | 85 |
2 files changed, 94 insertions, 0 deletions
diff --git a/plugins/mathjax/build.gradle.kts b/plugins/mathjax/build.gradle.kts index 142e7dc4..e570de46 100644 --- a/plugins/mathjax/build.gradle.kts +++ b/plugins/mathjax/build.gradle.kts @@ -1,5 +1,14 @@ import org.jetbrains.registerDokkaArtifactPublication +dependencies { + testImplementation("org.jsoup:jsoup:1.12.1") + testImplementation(project(":plugins:base")) + testImplementation(project(":plugins:base:test-utils")) + testImplementation(project(":test-tools")) + testImplementation(kotlin("test-junit")) + testImplementation(project(":kotlin-analysis")) +} + registerDokkaArtifactPublication("mathjaxPlugin") { artifactId = "mathjax-plugin" } diff --git a/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt b/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt new file mode 100644 index 00000000..33269ce7 --- /dev/null +++ b/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt @@ -0,0 +1,85 @@ +package mathjaxTest + +import org.jetbrains.dokka.mathjax.MathjaxPlugin +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jsoup.Jsoup +import org.junit.jupiter.api.Test +import utils.TestOutputWriterPlugin + +class MathjaxPluginTest : AbstractCoreTest() { + @Test + fun basicMathjaxTest() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + val source = + """ + |/src/main/kotlin/test/Test.kt + |package example + | /** + | * {@usesMathJax} + | * + | * <p>\(\alpha_{out} = \alpha_{dst}\)</p> + | * <p>\(C_{out} = C_{dst}\)</p> + | */ + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin, MathjaxPlugin()) + ) { + renderingStage = { + _, _ -> Jsoup + .parse(writerPlugin.writer.contents["root/example.html"]) + .head() + .select("link, script") + .let { + val link = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" + assert(it.`is`("[href=$link], [src=$link]")) + } + } + } + } + + @Test + fun basicNoMathjaxTest() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + val source = + """ + |/src/main/kotlin/test/Test.kt + |package example + | /** + | * <p>\(\alpha_{out} = \alpha_{dst}\)</p> + | * <p>\(C_{out} = C_{dst}\)</p> + | */ + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin, MathjaxPlugin()) + ) { + renderingStage = { + _, _ -> Jsoup + .parse(writerPlugin.writer.contents["root/example.html"]) + .head() + .select("link, script") + .let { + val link = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" + assert(!it.`is`("[href=$link], [src=$link]")) + } + } + } + } +} |