Refactoring replace trimMargin() with trimIndent(). This is preparation for injection bootstrapping in tests.

This commit is contained in:
Nikolay Krasko
2016-04-21 19:43:01 +03:00
parent a6d129b006
commit 8eda5e0ea5
3 changed files with 111 additions and 111 deletions
@@ -40,7 +40,7 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
}
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",
InjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
@@ -57,7 +57,7 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
}
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.",
InjectLanguageAction().isAvailable(project, myFixture.editor, myFixture.file))
@@ -66,12 +66,12 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
protected fun doRemoveInjectionTest(before: String, after: String) {
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))
UnInjectLanguageAction.invokeImpl(project, myFixture.editor, myFixture.file)
myFixture.checkResult(after.trimMargin())
myFixture.checkResult(after.trimIndent())
}
protected fun doFileReferenceInjectTest(before: String, after: String) {
@@ -84,9 +84,9 @@ abstract class AbstractInjectionTest : KotlinLightCodeInsightFixtureTestCase() {
configuration.isSourceModificationAllowed = true
try {
myFixture.configureByText("${getTestName(true)}.kt", before.trimMargin())
myFixture.configureByText("${getTestName(true)}.kt", before.trimIndent())
InjectLanguageAction.invokeImpl(project, myFixture.editor, myFixture.file, injectable)
myFixture.checkResult(after.trimMargin())
myFixture.checkResult(after.trimIndent())
}
finally {
configuration.isSourceModificationAllowed = allowed
@@ -46,7 +46,7 @@ class KotlinInjectionTest : AbstractInjectionTest() {
fun testInjectionOnJavaPredefinedMethodWithAnnotation() = assertInjectionPresent(
"""
|val test1 = java.util.regex.Pattern.compile("<caret>pattern")
val test1 = java.util.regex.Pattern.compile("<caret>pattern")
""",
RegExpLanguage.INSTANCE.id,
unInjectShouldBePresent = false
@@ -65,7 +65,7 @@ class KotlinInjectionTest : AbstractInjectionTest() {
assertInjectionPresent(
"""
|val stringBuilder = StringBuilder().replace(0, 0, "<caret><html></html>")
val stringBuilder = StringBuilder().replace(0, 0, "<caret><html></html>")
""",
HTMLLanguage.INSTANCE.id,
unInjectShouldBePresent = false
@@ -78,133 +78,133 @@ class KotlinInjectionTest : AbstractInjectionTest() {
fun testInjectionWithCommentOnProperty() = assertInjectionPresent(
"""
|//language=file-reference
|val test = "<caret>simple"
//language=file-reference
val test = "<caret>simple"
""")
fun testInjectionWithUsageOnReceiverWithRuntime() = assertInjectionPresent(
"""
|val test = "<caret>some"
|fun foo() = test.toRegex()
val test = "<caret>some"
fun foo() = test.toRegex()
""",
languageId = RegExpLanguage.INSTANCE.id, unInjectShouldBePresent = false)
fun testInjectionWithUsageInParameterWithRuntime() = assertInjectionPresent(
"""
|val test = "<caret>some"
|fun foo() = Regex(test)
val test = "<caret>some"
fun foo() = Regex(test)
""",
languageId = RegExpLanguage.INSTANCE.id, unInjectShouldBePresent = false)
fun testNoInjectionThoughSeveralAssignmentsWithRuntime() = assertNoInjection(
"""
|val first = "<caret>some"
|val test = first
|fun foo() = Regex(test)
val first = "<caret>some"
val test = first
fun foo() = Regex(test)
""")
fun testInjectionWithMultipleCommentsOnFun() = assertInjectionPresent(
"""
|// Some comment
|// Other comment
|//language=file-reference
|fun test() = "<caret>simple"
// Some comment
// Other comment
//language=file-reference
fun test() = "<caret>simple"
""")
fun testInjectionWithAnnotationOnPropertyWithAnnotation() = assertInjectionPresent(
"""
|@org.intellij.lang.annotations.Language("file-reference")
|val test = "<caret>simple"
@org.intellij.lang.annotations.Language("file-reference")
val test = "<caret>simple"
""")
fun testInjectWithCommentOnProperty() = doFileReferenceInjectTest(
"""
|val test = "<caret>simple"
val test = "<caret>simple"
""",
"""
|//language=file-reference
|val test = "simple"
//language=file-reference
val test = "simple"
"""
)
fun testInjectWithCommentOnCommentedProperty() = doFileReferenceInjectTest(
"""
|// Hello
|val test = "<caret>simple"
// Hello
val test = "<caret>simple"
""",
"""
|// Hello
|//language=file-reference
|val test = "simple"
// Hello
//language=file-reference
val test = "simple"
"""
)
fun testInjectWithCommentOnPropertyWithKDoc() = doFileReferenceInjectTest(
"""
|/**
| * Hi
| */
|val test = "<caret>simple"
/**
* Hi
*/
val test = "<caret>simple"
""",
"""
|/**
| * Hi
| */
|//language=file-reference
|val test = "<caret>simple"
/**
* Hi
*/
//language=file-reference
val test = "<caret>simple"
"""
)
fun testInjectWithCommentOnExpression() = doFileReferenceInjectTest(
"""
|fun test() {
| "<caret>"
|}
fun test() {
"<caret>"
}
""",
"""
|fun test() {
| //language=file-reference
| "<caret>"
|}
fun test() {
//language=file-reference
"<caret>"
}
"""
)
fun testInjectWithCommentOnDeepExpression() = doFileReferenceInjectTest(
"""
|fun test() {
| "" + "<caret>"
|}
fun test() {
"" + "<caret>"
}
""",
"""
|fun test() {
| "" + "<caret>"
|}
fun test() {
"" + "<caret>"
}
"""
)
fun testInjectOnPropertyWithAnnotation() = doFileReferenceInjectTest(
"""
|val test = "<caret>simple"
val test = "<caret>simple"
""",
"""
|import org.intellij.lang.annotations.Language
|
|@Language("file-reference")
|val test = "simple"
import org.intellij.lang.annotations.Language
@Language("file-reference")
val test = "simple"
"""
)
fun testInjectWithOnExpressionWithAnnotation() = doFileReferenceInjectTest(
"""
|fun test() {
| "<caret>"
|}
fun test() {
"<caret>"
}
""",
"""
|fun test() {
| //language=file-reference
| "<caret>"
|}
fun test() {
//language=file-reference
"<caret>"
}
"""
)
@@ -212,91 +212,91 @@ class KotlinInjectionTest : AbstractInjectionTest() {
fun testRemoveInjectionWithAnnotation() = doRemoveInjectionTest(
"""
|import org.intellij.lang.annotations.Language
|
|@Language("file-reference")
|val test = "<caret>simple"
import org.intellij.lang.annotations.Language
@Language("file-reference")
val test = "<caret>simple"
""",
"""
|import org.intellij.lang.annotations.Language
|
|val test = "simple"
import org.intellij.lang.annotations.Language
val test = "simple"
"""
)
// TODO: Doesn't work. UnInjectionLanguageAction is not enabled because of absent LanguageInjectionSupport.INJECTOR_SUPPORT user data.
// fun testRemoveInjectionFromOneLineFunWithAnnotation() = doRemoveInjectionTest(
// """
// |import org.intellij.lang.annotations.Language
// |
// |@Language("HTML") fun template(): String = "<caret><html></html>"
// import org.intellij.lang.annotations.Language
//
// @Language("HTML") fun template(): String = "<caret><html></html>"
// """,
// """
// |import org.intellij.lang.annotations.Language
// |
// |fun template(): String = "<caret><html></html>"
// import org.intellij.lang.annotations.Language
//
// fun template(): String = "<caret><html></html>"
// """
// )
// fun testRemoveInjectionOnQualifiedNameWithAnnotation() = doRemoveInjectionTest(
// """
// |import org.intellij.lang.annotations.Language
// |
// |@Language("RegExp")
// |val s = java.util.regex.Pattern.compile("Hi")
// import org.intellij.lang.annotations.Language
//
// @Language("RegExp")
// 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(
"""
|//language=file-reference
|val test = "<caret>simple"
//language=file-reference
val test = "<caret>simple"
""",
"""
|val test = "simple"
val test = "simple"
"""
)
fun testRemoveInjectionWithCommentNotFirst() = doRemoveInjectionTest(
"""
|// Some comment. To do a language injection, add a line comment language=some instruction.
|// language=file-reference
|val test = "<caret>simple"
// Some comment. To do a language injection, add a line comment language=some instruction.
// language=file-reference
val test = "<caret>simple"
""",
"""
|// Some comment. To do a language injection, add a line comment language=some instruction.
|val test = "simple"
// Some comment. To do a language injection, add a line comment language=some instruction.
val test = "simple"
"""
)
fun testRemoveInjectionWithCommentAfterKDoc() = doRemoveInjectionTest(
"""
|/**Property*/
|// language=file-reference
|val test = "<caret>simple"
/**Property*/
// language=file-reference
val test = "<caret>simple"
""",
"""
|/**Property*/
|val test = "simple"
/**Property*/
val test = "simple"
"""
)
fun testRemoveInjectionWithCommentInExpression() = doRemoveInjectionTest(
"""
|fun test() {
| // This is my favorite part
| // language=RegExp
| "<caret>something"
|}
fun test() {
// This is my favorite part
// language=RegExp
"<caret>something"
}
""",
"""
|fun test() {
| // This is my favorite part
| "something"
|}
fun test() {
// This is my favorite part
"something"
}
"""
)
}
@@ -22,42 +22,42 @@ import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescrip
class KotlinStdlibInjectionTest : AbstractInjectionTest() {
fun testOnRegex0() = assertInjectionPresent(
"""
|val test1 = kotlin.text.Regex("<caret>some")
val test1 = kotlin.text.Regex("<caret>some")
""",
RegExpLanguage.INSTANCE.id
)
fun testOnRegex1() = assertInjectionPresent(
"""
|val test1 = kotlin.text.Regex("<caret>some", RegexOption.COMMENTS)
val test1 = kotlin.text.Regex("<caret>some", RegexOption.COMMENTS)
""",
RegExpLanguage.INSTANCE.id
)
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
)
fun testToRegex0() = assertInjectionPresent(
"""
|val test = "hi<caret>".toRegex()
val test = "hi<caret>".toRegex()
""",
RegExpLanguage.INSTANCE.id
)
fun testToRegex1() = assertInjectionPresent(
"""
|val test = "hi<caret>".toRegex(RegexOption.CANON_EQ)
val test = "hi<caret>".toRegex(RegexOption.CANON_EQ)
""",
RegExpLanguage.INSTANCE.id
)
fun testToRegex2() = assertInjectionPresent(
"""
|val test = "hi<caret>".toRegex(setOf(RegexOption.LITERAL))
val test = "hi<caret>".toRegex(setOf(RegexOption.LITERAL))
""",
RegExpLanguage.INSTANCE.id
)