Skip to content

Commit dfdc8cf

Browse files
committed
Add mods.toml documentation tests
1 parent 0b8b8e4 commit dfdc8cf

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2024 minecraft-dev
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation, version 3.0 only.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.demonwav.mcdev.platform.forge
22+
23+
import com.demonwav.mcdev.toml.platform.forge.ModsTomlDocumentationProvider
24+
import com.intellij.testFramework.fixtures.BasePlatformTestCase
25+
import com.intellij.util.application
26+
import org.intellij.lang.annotations.Language
27+
import org.junit.jupiter.api.AfterEach
28+
import org.junit.jupiter.api.BeforeEach
29+
import org.junit.jupiter.api.DisplayName
30+
import org.junit.jupiter.api.Test
31+
32+
@DisplayName("Mods Toml Documentation Tests")
33+
class ModsTomlDocumentationTest : BasePlatformTestCase() {
34+
35+
@BeforeEach
36+
override fun setUp() {
37+
super.setUp()
38+
}
39+
40+
@AfterEach
41+
override fun tearDown() {
42+
super.tearDown()
43+
}
44+
45+
private fun doTestDoc(
46+
@Language("TOML") modsToml: String,
47+
expectedDoc: String
48+
) {
49+
myFixture.configureByText("mods.toml", modsToml)
50+
51+
application.runReadAction {
52+
val originalElement = myFixture.elementAtCaret
53+
val provider = ModsTomlDocumentationProvider()
54+
val element = provider.getCustomDocumentationElement(
55+
myFixture.editor,
56+
myFixture.file,
57+
originalElement,
58+
myFixture.caretOffset
59+
) ?: originalElement
60+
61+
val doc = provider.generateDoc(element, originalElement)
62+
assertNotNull(doc)
63+
assertSameLines(expectedDoc, doc!!)
64+
}
65+
}
66+
67+
private fun doTestCompletionDoc(
68+
@Language("TOML") modsToml: String,
69+
lookupString: String,
70+
expectedDoc: String
71+
) {
72+
myFixture.configureByText("mods.toml", modsToml)
73+
74+
val lookupElements = myFixture.completeBasic()
75+
val licenseElement = lookupElements.find { it.lookupString == lookupString }
76+
assertNotNull(licenseElement)
77+
78+
val obj = licenseElement!!.`object`
79+
assertNotNull(obj)
80+
81+
val documentationProvider = ModsTomlDocumentationProvider()
82+
val docElement = documentationProvider.getDocumentationElementForLookupItem(psiManager, obj, null)
83+
assertNotNull(docElement)
84+
85+
val doc = documentationProvider.generateDoc(docElement!!, null)
86+
assertNotNull(doc)
87+
assertSameLines(expectedDoc, doc!!)
88+
}
89+
90+
@Test
91+
@DisplayName("Root Key Documentation")
92+
fun rootKeyDocumentation() {
93+
doTestDoc(
94+
"licen<caret>se='MIT'",
95+
"<div class='content'>The license for you mod. This is mandatory metadata and allows for" +
96+
" easier comprehension of your redistributive properties.<br>Review your options at" +
97+
" <a href=\"https://choosealicense.com\">choosealicense.com</a>. All rights reserved is the default" +
98+
" copyright stance, and is thus the default here.</div>"
99+
)
100+
}
101+
102+
@Test
103+
@DisplayName("Mods Header Documentation")
104+
fun modsHeaderDocumentation() {
105+
doTestDoc(
106+
"[[mo<caret>ds]]",
107+
"<div class='content'>A list of mods - how many allowed here is determined by the individual" +
108+
" mod loader</div>"
109+
)
110+
}
111+
112+
@Test
113+
@DisplayName("Mod Key Documentation")
114+
fun modKeyDocumentation() {
115+
doTestDoc(
116+
"""
117+
[[mods]]
118+
ver<caret>sion="1.0"
119+
""".trimIndent(),
120+
"<div class='content'>The version number of the mod - there's a few well known variables usable here or" +
121+
" just hardcode it.<br>\${file.jarVersion} will substitute the value of the Implementation-Version" +
122+
" as read from the mod's JAR file metadata</div>"
123+
)
124+
}
125+
126+
@Test
127+
@DisplayName("Dependency Key Documentation")
128+
fun dependencyKeyDocumentation() {
129+
doTestDoc(
130+
"""
131+
[[dependencies."${'$'}{mod_id}"]]
132+
order<caret>ing="NONE"
133+
""".trimIndent(),
134+
"<div class='content'>An ordering relationship for the dependency - BEFORE or AFTER required if" +
135+
" the relationship is not mandatory.</div>"
136+
)
137+
}
138+
139+
@Test
140+
@DisplayName("Root Key Lookup Element Documentation")
141+
fun rootKeyLookupElementDocumentation() {
142+
doTestCompletionDoc(
143+
"<caret>",
144+
"license",
145+
"<div class='content'>The license for you mod. This is mandatory metadata and allows for" +
146+
" easier comprehension of your redistributive properties.<br>Review your options at" +
147+
" <a href=\"https://choosealicense.com\">choosealicense.com</a>. All rights reserved is the default" +
148+
" copyright stance, and is thus the default here.</div>"
149+
)
150+
}
151+
}

0 commit comments

Comments
 (0)