-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
src/test/kotlin/platform/forge/ModsTomlDocumentationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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( | ||
"licen<caret>se='MIT'", | ||
"<div class='content'>The license for you mod. This is mandatory metadata and allows for" + | ||
" easier comprehension of your redistributive properties.<br>Review your options at" + | ||
" <a href=\"https://choosealicense.com\">choosealicense.com</a>. All rights reserved is the default" + | ||
" copyright stance, and is thus the default here.</div>" | ||
) | ||
} | ||
|
||
@Test | ||
@DisplayName("Mods Header Documentation") | ||
fun modsHeaderDocumentation() { | ||
doTestDoc( | ||
"[[mo<caret>ds]]", | ||
"<div class='content'>A list of mods - how many allowed here is determined by the individual" + | ||
" mod loader</div>" | ||
) | ||
} | ||
|
||
@Test | ||
@DisplayName("Mod Key Documentation") | ||
fun modKeyDocumentation() { | ||
doTestDoc( | ||
""" | ||
[[mods]] | ||
ver<caret>sion="1.0" | ||
""".trimIndent(), | ||
"<div class='content'>The version number of the mod - there's a few well known variables usable here or" + | ||
" just hardcode it.<br>\${file.jarVersion} will substitute the value of the Implementation-Version" + | ||
" as read from the mod's JAR file metadata</div>" | ||
) | ||
} | ||
|
||
@Test | ||
@DisplayName("Dependency Key Documentation") | ||
fun dependencyKeyDocumentation() { | ||
doTestDoc( | ||
""" | ||
[[dependencies."${'$'}{mod_id}"]] | ||
order<caret>ing="NONE" | ||
""".trimIndent(), | ||
"<div class='content'>An ordering relationship for the dependency - BEFORE or AFTER required if" + | ||
" the relationship is not mandatory.</div>" | ||
) | ||
} | ||
|
||
@Test | ||
@DisplayName("Root Key Lookup Element Documentation") | ||
fun rootKeyLookupElementDocumentation() { | ||
doTestCompletionDoc( | ||
"<caret>", | ||
"license", | ||
"<div class='content'>The license for you mod. This is mandatory metadata and allows for" + | ||
" easier comprehension of your redistributive properties.<br>Review your options at" + | ||
" <a href=\"https://choosealicense.com\">choosealicense.com</a>. All rights reserved is the default" + | ||
" copyright stance, and is thus the default here.</div>" | ||
) | ||
} | ||
} |