IDEA-365427 [spring] MongoDB: properly filter places where to inject the JSON language

(cherry picked from commit cb151ce0e325ab1167fe838dba86f26027e2032d)

IJ-CR-152398

GitOrigin-RevId: e7d6cb58f70287aa2c96163728c56f95a1f14765
This commit is contained in:
Daniil Tsarev
2025-01-07 11:02:18 +01:00
committed by intellij-monorepo-bot
parent 85c788540a
commit 698ddc0afc

View File

@@ -17,7 +17,6 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.testFramework.UsefulTestCase
import junit.framework.TestCase
import org.junit.Assert
import org.junit.Assert.*
import java.util.*
@@ -71,13 +70,26 @@ class InjectionTestFixture(private val javaFixture: CodeInsightTestFixture) {
while (expected.isNotEmpty()) {
val (text, injectedLanguage) = expected.pop()
val found = (foundInjections.find { (psi, file) -> psi.text == text && file.language.id == injectedLanguage }
?: Assert.fail(
?: fail(
"no injection '$text' -> '$injectedLanguage' were found, remains: ${foundInjections.joinToString { (psi, file) -> "'${psi.text}' -> '${file.language}'" }} "))
foundInjections.remove(found)
}
}
}
fun assertNotInjected(vararg notExpectedInjections: InjectionAssertionData) {
runReadAction {
val notExpected = notExpectedInjections.toCollection(LinkedList())
val foundInjections = getAllInjections().toCollection(LinkedList())
while (notExpected.isNotEmpty()) {
val (text, injectedLanguage) = notExpected.pop()
val matchingInjection = foundInjections.find { (psi, psiFile) -> psi.text == text && psiFile.language.id == injectedLanguage }
if (matchingInjection != null) fail("not expected injection '$text' -> '$injectedLanguage' is found")
}
}
}
fun openInFragmentEditor(): EditorTestFixture {
val quickEditHandler = QuickEditAction().invokeImpl(javaFixture.project, topLevelEditor, topLevelFile)
return openInFragmentEditor(quickEditHandler)