Phase 4: add structure, folding, and references
This commit is contained in:
65
src/test/kotlin/dev/hgh/jai/editor/JaiFoldingBuilderTest.kt
Normal file
65
src/test/kotlin/dev/hgh/jai/editor/JaiFoldingBuilderTest.kt
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user