aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/mathjax/build.gradle.kts9
-rw-r--r--plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt85
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]"))
+ }
+ }
+ }
+ }
+}