Refactoring replace trimMargin() with trimIndent(). This is preparation for injection bootstrapping in tests.
This commit is contained in:
@@ -40,7 +40,7 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun assertInjectionPresent(text: String, languageId: String? = null, unInjectShouldBePresent: Boolean = true) {
|
protected fun assertInjectionPresent(text: String, languageId: String? = null, unInjectShouldBePresent: Boolean = true) {
|
||||||
myFixture.configureByText("${getTestName(true)}.kt", text.trimMargin())
|
myFixture.configureByText("${getTestName(true)}.kt", text.trimIndent())
|
||||||
|
|
||||||
TestCase.assertFalse("Injection action is available. There's probably no injection at caret place",
|
TestCase.assertFalse("Injection action is available. There's probably no injection at caret place",
|
||||||
InjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
|
InjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
|
||||||
@@ -57,7 +57,7 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun assertNoInjection(text: String) {
|
protected fun assertNoInjection(text: String) {
|
||||||
myFixture.configureByText("${getTestName(true)}.kt", text.trimMargin())
|
myFixture.configureByText("${getTestName(true)}.kt", text.trimIndent())
|
||||||
|
|
||||||
TestCase.assertTrue("Injection action is not available. There's probably some injection but nothing was expected.",
|
TestCase.assertTrue("Injection action is not available. There's probably some injection but nothing was expected.",
|
||||||
InjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
|
InjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
|
||||||
@@ -66,12 +66,12 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
protected fun doRemoveInjectionTest(before: String, after: String) {
|
protected fun doRemoveInjectionTest(before: String, after: String) {
|
||||||
myFixture.setCaresAboutInjection(false)
|
myFixture.setCaresAboutInjection(false)
|
||||||
|
|
||||||
myFixture.configureByText("${getTestName(true)}.kt", before.trimMargin())
|
myFixture.configureByText("${getTestName(true)}.kt", before.trimIndent())
|
||||||
|
|
||||||
TestCase.assertTrue(UnInjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
|
TestCase.assertTrue(UnInjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
|
||||||
UnInjectLanguageAction.invokeImpl(project, myFixture.editor, myFixture.file)
|
UnInjectLanguageAction.invokeImpl(project, myFixture.editor, myFixture.file)
|
||||||
|
|
||||||
myFixture.checkResult(after.trimMargin())
|
myFixture.checkResult(after.trimIndent())
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun doFileReferenceInjectTest(before: String, after: String) {
|
protected fun doFileReferenceInjectTest(before: String, after: String) {
|
||||||
@@ -84,9 +84,9 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
configuration.isSourceModificationAllowed = true
|
configuration.isSourceModificationAllowed = true
|
||||||
try {
|
try {
|
||||||
myFixture.configureByText("${getTestName(true)}.kt", before.trimMargin())
|
myFixture.configureByText("${getTestName(true)}.kt", before.trimIndent())
|
||||||
InjectLanguageAction.invokeImpl(project, myFixture.editor, myFixture.file, injectable)
|
InjectLanguageAction.invokeImpl(project, myFixture.editor, myFixture.file, injectable)
|
||||||
myFixture.checkResult(after.trimMargin())
|
myFixture.checkResult(after.trimIndent())
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
configuration.isSourceModificationAllowed = allowed
|
configuration.isSourceModificationAllowed = allowed
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class KotlinInjectionTest : AbstractInjectionTest() {
|
|||||||
|
|
||||||
fun testInjectionOnJavaPredefinedMethodWithAnnotation() = assertInjectionPresent(
|
fun testInjectionOnJavaPredefinedMethodWithAnnotation() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test1 = java.util.regex.Pattern.compile("<caret>pattern")
|
val test1 = java.util.regex.Pattern.compile("<caret>pattern")
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id,
|
RegExpLanguage.INSTANCE.id,
|
||||||
unInjectShouldBePresent = false
|
unInjectShouldBePresent = false
|
||||||
@@ -65,7 +65,7 @@ class KotlinInjectionTest : AbstractInjectionTest() {
|
|||||||
|
|
||||||
assertInjectionPresent(
|
assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val stringBuilder = StringBuilder().replace(0, 0, "<caret><html></html>")
|
val stringBuilder = StringBuilder().replace(0, 0, "<caret><html></html>")
|
||||||
""",
|
""",
|
||||||
HTMLLanguage.INSTANCE.id,
|
HTMLLanguage.INSTANCE.id,
|
||||||
unInjectShouldBePresent = false
|
unInjectShouldBePresent = false
|
||||||
@@ -78,133 +78,133 @@ class KotlinInjectionTest : AbstractInjectionTest() {
|
|||||||
|
|
||||||
fun testInjectionWithCommentOnProperty() = assertInjectionPresent(
|
fun testInjectionWithCommentOnProperty() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|//language=file-reference
|
//language=file-reference
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""")
|
""")
|
||||||
|
|
||||||
fun testInjectionWithUsageOnReceiverWithRuntime() = assertInjectionPresent(
|
fun testInjectionWithUsageOnReceiverWithRuntime() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test = "<caret>some"
|
val test = "<caret>some"
|
||||||
|fun foo() = test.toRegex()
|
fun foo() = test.toRegex()
|
||||||
""",
|
""",
|
||||||
languageId = RegExpLanguage.INSTANCE.id, unInjectShouldBePresent = false)
|
languageId = RegExpLanguage.INSTANCE.id, unInjectShouldBePresent = false)
|
||||||
|
|
||||||
fun testInjectionWithUsageInParameterWithRuntime() = assertInjectionPresent(
|
fun testInjectionWithUsageInParameterWithRuntime() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test = "<caret>some"
|
val test = "<caret>some"
|
||||||
|fun foo() = Regex(test)
|
fun foo() = Regex(test)
|
||||||
""",
|
""",
|
||||||
languageId = RegExpLanguage.INSTANCE.id, unInjectShouldBePresent = false)
|
languageId = RegExpLanguage.INSTANCE.id, unInjectShouldBePresent = false)
|
||||||
|
|
||||||
fun testNoInjectionThoughSeveralAssignmentsWithRuntime() = assertNoInjection(
|
fun testNoInjectionThoughSeveralAssignmentsWithRuntime() = assertNoInjection(
|
||||||
"""
|
"""
|
||||||
|val first = "<caret>some"
|
val first = "<caret>some"
|
||||||
|val test = first
|
val test = first
|
||||||
|fun foo() = Regex(test)
|
fun foo() = Regex(test)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
fun testInjectionWithMultipleCommentsOnFun() = assertInjectionPresent(
|
fun testInjectionWithMultipleCommentsOnFun() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|// Some comment
|
// Some comment
|
||||||
|// Other comment
|
// Other comment
|
||||||
|//language=file-reference
|
//language=file-reference
|
||||||
|fun test() = "<caret>simple"
|
fun test() = "<caret>simple"
|
||||||
""")
|
""")
|
||||||
|
|
||||||
fun testInjectionWithAnnotationOnPropertyWithAnnotation() = assertInjectionPresent(
|
fun testInjectionWithAnnotationOnPropertyWithAnnotation() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|@org.intellij.lang.annotations.Language("file-reference")
|
@org.intellij.lang.annotations.Language("file-reference")
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""")
|
""")
|
||||||
|
|
||||||
fun testInjectWithCommentOnProperty() = doFileReferenceInjectTest(
|
fun testInjectWithCommentOnProperty() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|//language=file-reference
|
//language=file-reference
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testInjectWithCommentOnCommentedProperty() = doFileReferenceInjectTest(
|
fun testInjectWithCommentOnCommentedProperty() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|// Hello
|
// Hello
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|// Hello
|
// Hello
|
||||||
|//language=file-reference
|
//language=file-reference
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testInjectWithCommentOnPropertyWithKDoc() = doFileReferenceInjectTest(
|
fun testInjectWithCommentOnPropertyWithKDoc() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|/**
|
/**
|
||||||
| * Hi
|
* Hi
|
||||||
| */
|
*/
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|/**
|
/**
|
||||||
| * Hi
|
* Hi
|
||||||
| */
|
*/
|
||||||
|//language=file-reference
|
//language=file-reference
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testInjectWithCommentOnExpression() = doFileReferenceInjectTest(
|
fun testInjectWithCommentOnExpression() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| "<caret>"
|
"<caret>"
|
||||||
|}
|
}
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| //language=file-reference
|
//language=file-reference
|
||||||
| "<caret>"
|
"<caret>"
|
||||||
|}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testInjectWithCommentOnDeepExpression() = doFileReferenceInjectTest(
|
fun testInjectWithCommentOnDeepExpression() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| "" + "<caret>"
|
"" + "<caret>"
|
||||||
|}
|
}
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| "" + "<caret>"
|
"" + "<caret>"
|
||||||
|}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testInjectOnPropertyWithAnnotation() = doFileReferenceInjectTest(
|
fun testInjectOnPropertyWithAnnotation() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
|
|
|
||||||
|@Language("file-reference")
|
@Language("file-reference")
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testInjectWithOnExpressionWithAnnotation() = doFileReferenceInjectTest(
|
fun testInjectWithOnExpressionWithAnnotation() = doFileReferenceInjectTest(
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| "<caret>"
|
"<caret>"
|
||||||
|}
|
}
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| //language=file-reference
|
//language=file-reference
|
||||||
| "<caret>"
|
"<caret>"
|
||||||
|}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -212,91 +212,91 @@ class KotlinInjectionTest : AbstractInjectionTest() {
|
|||||||
|
|
||||||
fun testRemoveInjectionWithAnnotation() = doRemoveInjectionTest(
|
fun testRemoveInjectionWithAnnotation() = doRemoveInjectionTest(
|
||||||
"""
|
"""
|
||||||
|import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
|
|
|
||||||
|@Language("file-reference")
|
@Language("file-reference")
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
|
|
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Doesn't work. UnInjectionLanguageAction is not enabled because of absent LanguageInjectionSupport.INJECTOR_SUPPORT user data.
|
// TODO: Doesn't work. UnInjectionLanguageAction is not enabled because of absent LanguageInjectionSupport.INJECTOR_SUPPORT user data.
|
||||||
// fun testRemoveInjectionFromOneLineFunWithAnnotation() = doRemoveInjectionTest(
|
// fun testRemoveInjectionFromOneLineFunWithAnnotation() = doRemoveInjectionTest(
|
||||||
// """
|
// """
|
||||||
// |import org.intellij.lang.annotations.Language
|
// import org.intellij.lang.annotations.Language
|
||||||
// |
|
//
|
||||||
// |@Language("HTML") fun template(): String = "<caret><html></html>"
|
// @Language("HTML") fun template(): String = "<caret><html></html>"
|
||||||
// """,
|
// """,
|
||||||
// """
|
// """
|
||||||
// |import org.intellij.lang.annotations.Language
|
// import org.intellij.lang.annotations.Language
|
||||||
// |
|
//
|
||||||
// |fun template(): String = "<caret><html></html>"
|
// fun template(): String = "<caret><html></html>"
|
||||||
// """
|
// """
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// fun testRemoveInjectionOnQualifiedNameWithAnnotation() = doRemoveInjectionTest(
|
// fun testRemoveInjectionOnQualifiedNameWithAnnotation() = doRemoveInjectionTest(
|
||||||
// """
|
// """
|
||||||
// |import org.intellij.lang.annotations.Language
|
// import org.intellij.lang.annotations.Language
|
||||||
// |
|
//
|
||||||
// |@Language("RegExp")
|
// @Language("RegExp")
|
||||||
// |val s = java.util.regex.Pattern.compile("Hi")
|
// val s = java.util.regex.Pattern.compile("Hi")
|
||||||
// """,
|
// """,
|
||||||
// """
|
// """
|
||||||
// |val test1 = java.util.regex.Pattern.compile("Hi")
|
// val test1 = java.util.regex.Pattern.compile("Hi")
|
||||||
// """
|
// """
|
||||||
// )
|
// )
|
||||||
|
|
||||||
fun testRemoveInjectionWithComment() = doRemoveInjectionTest(
|
fun testRemoveInjectionWithComment() = doRemoveInjectionTest(
|
||||||
"""
|
"""
|
||||||
|//language=file-reference
|
//language=file-reference
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testRemoveInjectionWithCommentNotFirst() = doRemoveInjectionTest(
|
fun testRemoveInjectionWithCommentNotFirst() = doRemoveInjectionTest(
|
||||||
"""
|
"""
|
||||||
|// Some comment. To do a language injection, add a line comment language=some instruction.
|
// Some comment. To do a language injection, add a line comment language=some instruction.
|
||||||
|// language=file-reference
|
// language=file-reference
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|// Some comment. To do a language injection, add a line comment language=some instruction.
|
// Some comment. To do a language injection, add a line comment language=some instruction.
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testRemoveInjectionWithCommentAfterKDoc() = doRemoveInjectionTest(
|
fun testRemoveInjectionWithCommentAfterKDoc() = doRemoveInjectionTest(
|
||||||
"""
|
"""
|
||||||
|/**Property*/
|
/**Property*/
|
||||||
|// language=file-reference
|
// language=file-reference
|
||||||
|val test = "<caret>simple"
|
val test = "<caret>simple"
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|/**Property*/
|
/**Property*/
|
||||||
|val test = "simple"
|
val test = "simple"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testRemoveInjectionWithCommentInExpression() = doRemoveInjectionTest(
|
fun testRemoveInjectionWithCommentInExpression() = doRemoveInjectionTest(
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| // This is my favorite part
|
// This is my favorite part
|
||||||
| // language=RegExp
|
// language=RegExp
|
||||||
| "<caret>something"
|
"<caret>something"
|
||||||
|}
|
}
|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
|fun test() {
|
fun test() {
|
||||||
| // This is my favorite part
|
// This is my favorite part
|
||||||
| "something"
|
"something"
|
||||||
|}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -22,42 +22,42 @@ import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescrip
|
|||||||
class KotlinStdlibInjectionTest : AbstractInjectionTest() {
|
class KotlinStdlibInjectionTest : AbstractInjectionTest() {
|
||||||
fun testOnRegex0() = assertInjectionPresent(
|
fun testOnRegex0() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test1 = kotlin.text.Regex("<caret>some")
|
val test1 = kotlin.text.Regex("<caret>some")
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id
|
RegExpLanguage.INSTANCE.id
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testOnRegex1() = assertInjectionPresent(
|
fun testOnRegex1() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test1 = kotlin.text.Regex("<caret>some", RegexOption.COMMENTS)
|
val test1 = kotlin.text.Regex("<caret>some", RegexOption.COMMENTS)
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id
|
RegExpLanguage.INSTANCE.id
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testOnRegex2() = assertInjectionPresent(
|
fun testOnRegex2() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test1 = kotlin.text.Regex("<caret>some", setOf(RegexOption.COMMENTS))
|
val test1 = kotlin.text.Regex("<caret>some", setOf(RegexOption.COMMENTS))
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id
|
RegExpLanguage.INSTANCE.id
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testToRegex0() = assertInjectionPresent(
|
fun testToRegex0() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test = "hi<caret>".toRegex()
|
val test = "hi<caret>".toRegex()
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id
|
RegExpLanguage.INSTANCE.id
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testToRegex1() = assertInjectionPresent(
|
fun testToRegex1() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test = "hi<caret>".toRegex(RegexOption.CANON_EQ)
|
val test = "hi<caret>".toRegex(RegexOption.CANON_EQ)
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id
|
RegExpLanguage.INSTANCE.id
|
||||||
)
|
)
|
||||||
|
|
||||||
fun testToRegex2() = assertInjectionPresent(
|
fun testToRegex2() = assertInjectionPresent(
|
||||||
"""
|
"""
|
||||||
|val test = "hi<caret>".toRegex(setOf(RegexOption.LITERAL))
|
val test = "hi<caret>".toRegex(setOf(RegexOption.LITERAL))
|
||||||
""",
|
""",
|
||||||
RegExpLanguage.INSTANCE.id
|
RegExpLanguage.INSTANCE.id
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user