From dfdc8cf549f616ccb085e34c7d5329db426f7d23 Mon Sep 17 00:00:00 2001 From: RedNesto Date: Mon, 12 Aug 2024 20:12:27 +0200 Subject: [PATCH] Add mods.toml documentation tests --- .../forge/ModsTomlDocumentationTest.kt | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/test/kotlin/platform/forge/ModsTomlDocumentationTest.kt diff --git a/src/test/kotlin/platform/forge/ModsTomlDocumentationTest.kt b/src/test/kotlin/platform/forge/ModsTomlDocumentationTest.kt new file mode 100644 index 000000000..d7441797a --- /dev/null +++ b/src/test/kotlin/platform/forge/ModsTomlDocumentationTest.kt @@ -0,0 +1,151 @@ +/* + * Minecraft Development for IntelliJ + * + * https://mcdev.io/ + * + * Copyright (C) 2024 minecraft-dev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, version 3.0 only. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.demonwav.mcdev.platform.forge + +import com.demonwav.mcdev.toml.platform.forge.ModsTomlDocumentationProvider +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import com.intellij.util.application +import org.intellij.lang.annotations.Language +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +@DisplayName("Mods Toml Documentation Tests") +class ModsTomlDocumentationTest : BasePlatformTestCase() { + + @BeforeEach + override fun setUp() { + super.setUp() + } + + @AfterEach + override fun tearDown() { + super.tearDown() + } + + private fun doTestDoc( + @Language("TOML") modsToml: String, + expectedDoc: String + ) { + myFixture.configureByText("mods.toml", modsToml) + + application.runReadAction { + val originalElement = myFixture.elementAtCaret + val provider = ModsTomlDocumentationProvider() + val element = provider.getCustomDocumentationElement( + myFixture.editor, + myFixture.file, + originalElement, + myFixture.caretOffset + ) ?: originalElement + + val doc = provider.generateDoc(element, originalElement) + assertNotNull(doc) + assertSameLines(expectedDoc, doc!!) + } + } + + private fun doTestCompletionDoc( + @Language("TOML") modsToml: String, + lookupString: String, + expectedDoc: String + ) { + myFixture.configureByText("mods.toml", modsToml) + + val lookupElements = myFixture.completeBasic() + val licenseElement = lookupElements.find { it.lookupString == lookupString } + assertNotNull(licenseElement) + + val obj = licenseElement!!.`object` + assertNotNull(obj) + + val documentationProvider = ModsTomlDocumentationProvider() + val docElement = documentationProvider.getDocumentationElementForLookupItem(psiManager, obj, null) + assertNotNull(docElement) + + val doc = documentationProvider.generateDoc(docElement!!, null) + assertNotNull(doc) + assertSameLines(expectedDoc, doc!!) + } + + @Test + @DisplayName("Root Key Documentation") + fun rootKeyDocumentation() { + doTestDoc( + "license='MIT'", + "
The license for you mod. This is mandatory metadata and allows for" + + " easier comprehension of your redistributive properties.
Review your options at" + + " choosealicense.com. All rights reserved is the default" + + " copyright stance, and is thus the default here.
" + ) + } + + @Test + @DisplayName("Mods Header Documentation") + fun modsHeaderDocumentation() { + doTestDoc( + "[[mods]]", + "
A list of mods - how many allowed here is determined by the individual" + + " mod loader
" + ) + } + + @Test + @DisplayName("Mod Key Documentation") + fun modKeyDocumentation() { + doTestDoc( + """ + [[mods]] + version="1.0" + """.trimIndent(), + "
The version number of the mod - there's a few well known variables usable here or" + + " just hardcode it.
\${file.jarVersion} will substitute the value of the Implementation-Version" + + " as read from the mod's JAR file metadata
" + ) + } + + @Test + @DisplayName("Dependency Key Documentation") + fun dependencyKeyDocumentation() { + doTestDoc( + """ + [[dependencies."${'$'}{mod_id}"]] + ordering="NONE" + """.trimIndent(), + "
An ordering relationship for the dependency - BEFORE or AFTER required if" + + " the relationship is not mandatory.
" + ) + } + + @Test + @DisplayName("Root Key Lookup Element Documentation") + fun rootKeyLookupElementDocumentation() { + doTestCompletionDoc( + "", + "license", + "
The license for you mod. This is mandatory metadata and allows for" + + " easier comprehension of your redistributive properties.
Review your options at" + + " choosealicense.com. All rights reserved is the default" + + " copyright stance, and is thus the default here.
" + ) + } +}