66 lines
2.3 KiB
Kotlin
66 lines
2.3 KiB
Kotlin
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())
|
|
}
|
|
}
|