Phase 4: add structure, folding, and references

This commit is contained in:
hgranthorner
2026-08-04 14:49:03 -04:00
parent bb54639ce5
commit c4e1d92c9a
16 changed files with 826 additions and 14 deletions

View File

@@ -0,0 +1,65 @@
package dev.hgh.jai.editor
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import dev.hgh.jai.lexer.JaiTokenTypes
class JaiFoldingBuilderTest : BasePlatformTestCase() {
fun testFoldsMultilineBlocksAndComments() {
val text =
"""
main :: () {
value := 1;
}
/* a comment
* with two lines
*/
""".trimIndent()
val file = myFixture.configureByText("folding.jai", text)
val descriptors = JaiFoldingBuilder().buildFoldRegions(file, myFixture.editor.document, quick = false)
val foldedText =
descriptors.map { descriptor ->
text.substring(descriptor.range.startOffset, descriptor.range.endOffset)
}
assertEquals(2, descriptors.size)
assertTrue(foldedText.any { it.contains("value := 1;") })
assertTrue(foldedText.any { it.contains("with two lines") })
}
fun testFoldsNestedCommentsAndHereStrings() {
val text =
"""
/* outer comment
/* nested comment */
still in the outer comment
*/
body :: #string END
raw here-string text
END;
""".trimIndent()
val file = myFixture.configureByText("literals.jai", text)
val builder = JaiFoldingBuilder()
val descriptors = builder.buildFoldRegions(file, myFixture.editor.document, quick = false)
val foldedText =
descriptors.map { descriptor ->
text.substring(descriptor.range.startOffset, descriptor.range.endOffset)
}
assertEquals(2, descriptors.size)
assertTrue(foldedText.any { it.contains("nested comment") })
assertTrue(foldedText.any { it.contains("raw here-string text") })
val hereString = descriptors.first { it.element.elementType == JaiTokenTypes.HERE_STRING }
assertEquals("#string …", builder.getPlaceholderText(hereString.element))
}
fun testDoesNotFoldSingleLineRegions() {
val text = "main :: () { value := 1; } /* one line */"
val file = myFixture.configureByText("single-line.jai", text)
val descriptors = JaiFoldingBuilder().buildFoldRegions(file, myFixture.editor.document, quick = false)
assertEmpty(descriptors.toList())
}
}