aboutsummaryrefslogtreecommitdiff
path: root/kotlin-plugin/src/test/kotlin/moe/nea
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-10-30 00:00:54 +0100
committerLinnea Gräf <nea@nea.moe>2024-10-30 00:00:54 +0100
commit410f6a0dd1e5288df7c3fc90bd3937a97b2e6385 (patch)
treecc3db28a82d28dd59528aa3580878cf4fff8980a /kotlin-plugin/src/test/kotlin/moe/nea
downloadmcautotranslations-410f6a0dd1e5288df7c3fc90bd3937a97b2e6385.tar.gz
mcautotranslations-410f6a0dd1e5288df7c3fc90bd3937a97b2e6385.tar.bz2
mcautotranslations-410f6a0dd1e5288df7c3fc90bd3937a97b2e6385.zip
Init
Diffstat (limited to 'kotlin-plugin/src/test/kotlin/moe/nea')
-rw-r--r--kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/TestTemplateReplacement.kt40
-rw-r--r--kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/compile_utils.kt33
2 files changed, 73 insertions, 0 deletions
diff --git a/kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/TestTemplateReplacement.kt b/kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/TestTemplateReplacement.kt
new file mode 100644
index 0000000..b4a7f18
--- /dev/null
+++ b/kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/TestTemplateReplacement.kt
@@ -0,0 +1,40 @@
+@file:OptIn(ExperimentalCompilerApi::class)
+
+package moe.nea.mcautotranslations
+
+import com.tschuchort.compiletesting.SourceFile
+import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
+import kotlin.test.Test
+
+class TestTemplateReplacement {
+ @Test
+ fun testX() {
+ val dollar = '$'
+ compile(listOf(
+ SourceFile.kotlin(
+ "test.kt",
+ """
+ package moe.nea.translatetest
+
+ data class Text(val text: String)
+ fun tr(key: String, value: String): Text {
+ error("This should not be executed at runtime. Compiler plugin did not run.")
+ }
+
+ fun trResolved(key: String, vararg templateArgs: Any?): Text {
+ return Text("TODO: do a lookup here for $dollar{key} and make use of $dollar{templateArgs.toList()}")
+ }
+
+ fun main() {
+ val test = 20
+ val othertest = "test2"
+
+ println(tr("hi", "aaa$dollar{test}rest$dollar{othertest}end"))
+ println(tr("hello", "just a regular strnig"))
+ println(trResolved("hi", test, othertest))
+ }
+ """.trimIndent()
+ )
+ ))
+ }
+} \ No newline at end of file
diff --git a/kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/compile_utils.kt b/kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/compile_utils.kt
new file mode 100644
index 0000000..48d9c6e
--- /dev/null
+++ b/kotlin-plugin/src/test/kotlin/moe/nea/mcautotranslations/compile_utils.kt
@@ -0,0 +1,33 @@
+@file:OptIn(ExperimentalCompilerApi::class)
+
+package moe.nea.mcautotranslations
+
+import com.tschuchort.compiletesting.JvmCompilationResult
+import com.tschuchort.compiletesting.KotlinCompilation
+import com.tschuchort.compiletesting.SourceFile
+import com.tschuchort.compiletesting.configureKsp
+import moe.nea.mcautotranslations.kotlin.MCAutoTranslationsComponentRegistrar
+import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
+import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
+
+private val DEFAULT_PLUGINS = arrayOf(
+ MCAutoTranslationsComponentRegistrar()
+)
+
+
+fun compile(
+ list: List<SourceFile>,
+ vararg plugins: CompilerPluginRegistrar = DEFAULT_PLUGINS
+): JvmCompilationResult {
+ return KotlinCompilation().apply {
+ sources = list
+ compilerPluginRegistrars = plugins.toList()
+ inheritClassPath = true
+ messageOutputStream = System.out // TODO: capture this output somehow for testing
+ }.compile()
+}
+
+
+
+
+