From 0c848be52c90cc1136d9ccbcd55b9a290bc7b58b Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Mon, 13 Jul 2020 19:41:03 -0700 Subject: Add a basic mathjax test --- .../mathjax/src/test/kotlin/MathjaxPluginTest.kt | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt (limited to 'plugins/mathjax/src/test') 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} + | * + | *

\(\alpha_{out} = \alpha_{dst}\)

+ | *

\(C_{out} = C_{dst}\)

+ | */ + """.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 + | /** + | *

\(\alpha_{out} = \alpha_{dst}\)

+ | *

\(C_{out} = C_{dst}\)

+ | */ + """.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]")) + } + } + } + } +} -- cgit From c2b2f62dbce00e927214416cba33653048582443 Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Tue, 14 Jul 2020 09:16:40 -0700 Subject: Add fixes so the test actually passes --- plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt | 2 +- .../mathjax/src/test/kotlin/MathjaxPluginTest.kt | 28 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'plugins/mathjax/src/test') diff --git a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt index 9e6ed965..63699585 100644 --- a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt +++ b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt @@ -15,7 +15,7 @@ class MathjaxPlugin : DokkaPlugin() { } private const val ANNOTATION = "usesMathJax" -private const val LIB_PATH = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" +internal const val LIB_PATH = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" object MathjaxTransformer : PageTransformer { override fun invoke(input: RootPageNode) = input.transformContentPagesTree { diff --git a/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt b/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt index 33269ce7..4a4ada23 100644 --- a/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt +++ b/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt @@ -1,5 +1,6 @@ package mathjaxTest +import org.jetbrains.dokka.mathjax.LIB_PATH import org.jetbrains.dokka.mathjax.MathjaxPlugin import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jsoup.Jsoup @@ -8,7 +9,7 @@ import utils.TestOutputWriterPlugin class MathjaxPluginTest : AbstractCoreTest() { @Test - fun basicMathjaxTest() { + fun noMathjaxTest() { val configuration = dokkaConfiguration { sourceSets { sourceSet { @@ -21,11 +22,9 @@ class MathjaxPluginTest : AbstractCoreTest() { |/src/main/kotlin/test/Test.kt |package example | /** - | * {@usesMathJax} - | * - | *

\(\alpha_{out} = \alpha_{dst}\)

- | *

\(C_{out} = C_{dst}\)

+ | * Just a regular kdoc | */ + | fun test(): String = "" """.trimIndent() val writerPlugin = TestOutputWriterPlugin() testInline( @@ -35,19 +34,18 @@ class MathjaxPluginTest : AbstractCoreTest() { ) { renderingStage = { _, _ -> Jsoup - .parse(writerPlugin.writer.contents["root/example.html"]) + .parse(writerPlugin.writer.contents["root/example/test.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]")) + assert(!it.`is`("[href=$LIB_PATH], [src=$LIB_PATH]")) } } } } @Test - fun basicNoMathjaxTest() { + fun usingMathjaxTest() { val configuration = dokkaConfiguration { sourceSets { sourceSet { @@ -60,9 +58,12 @@ class MathjaxPluginTest : AbstractCoreTest() { |/src/main/kotlin/test/Test.kt |package example | /** - | *

\(\alpha_{out} = \alpha_{dst}\)

- | *

\(C_{out} = C_{dst}\)

+ | * @usesMathJax + | * + | * \(\alpha_{out} = \alpha_{dst}\) + | * \(C_{out} = C_{dst}\) | */ + | fun test(): String = "" """.trimIndent() val writerPlugin = TestOutputWriterPlugin() testInline( @@ -72,12 +73,11 @@ class MathjaxPluginTest : AbstractCoreTest() { ) { renderingStage = { _, _ -> Jsoup - .parse(writerPlugin.writer.contents["root/example.html"]) + .parse(writerPlugin.writer.contents["root/example/test.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]")) + assert(it.`is`("[href=$LIB_PATH], [src=$LIB_PATH]")) } } } -- cgit