Assert the PSI wiring the ParserDefinition unblocked
JaiFileTypeTest could previously only check the virtual file's type, because
without a ParserDefinition the PSI file fell back to plain text. It now asserts
the PSI file is a JaiFile in the Jai language and that JaiParserDefinition is the
registered definition - the wiring every PSI-dependent feature needs.
Also records the in-memory-fixture flake ('Cannot create child file at /src') as
infrastructure, with the note that JaiCorpusParserTest sidesteps it by using
PsiFileFactory directly.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package dev.hgh.jai
|
||||
|
||||
import com.intellij.lang.LanguageParserDefinitions
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||
import dev.hgh.jai.psi.JaiFile
|
||||
import dev.hgh.jai.psi.JaiParserDefinition
|
||||
|
||||
/**
|
||||
* Verifies plugin.xml wiring: the `.jai` extension resolves to our file type and
|
||||
@@ -24,12 +27,24 @@ class JaiFileTypeTest : BasePlatformTestCase() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The *virtual* file already resolves to our type. The PSI file's language stays
|
||||
* plain text until a ParserDefinition is registered (phase 3) — asserting that here
|
||||
* would be asserting the platform's fallback, not our wiring.
|
||||
* Before phase 3 this could only assert the *virtual* file's type, because
|
||||
* without a `ParserDefinition` the PSI file fell back to plain text. Now that
|
||||
* `JaiParserDefinition` is registered, the PSI file itself is a [JaiFile] — which
|
||||
* is what every PSI-dependent feature (structure view, folding, references)
|
||||
* relies on.
|
||||
*/
|
||||
fun testVirtualFileUsesJaiFileType() {
|
||||
fun testJaiFileProducesJaiPsi() {
|
||||
val file = myFixture.configureByText("sample.jai", "main :: () { }")
|
||||
assertEquals(JaiFileType, file.virtualFile.fileType)
|
||||
assertEquals(JaiLanguage, file.language)
|
||||
assertTrue("expected a JaiFile, got ${file.javaClass.name}", file is JaiFile)
|
||||
}
|
||||
|
||||
fun testParserDefinitionIsRegisteredForJai() {
|
||||
val definition = LanguageParserDefinitions.INSTANCE.forLanguage(JaiLanguage)
|
||||
assertTrue(
|
||||
"plugin.xml must register our parser definition, got $definition",
|
||||
definition is JaiParserDefinition,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user