#KT-8708 migrate tests to new trimIdent() and prependIndent
This commit is contained in:
@@ -1018,8 +1018,8 @@ class SmartEnterTest : JetLightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
fun doFunTest(before: String, after: String) {
|
fun doFunTest(before: String, after: String) {
|
||||||
fun String.withFunContext(): String {
|
fun String.withFunContext(): String {
|
||||||
val bodyText = "//----${this.trimIndent()}//----"
|
val bodyText = "//----\n${this.trimIndent()}\n//----"
|
||||||
val withIndent = bodyText.split("\n").map { " $it" }.joinToString(separator = "\n")
|
val withIndent = bodyText.prependIndent(" ")
|
||||||
|
|
||||||
return "fun method() {\n${withIndent}\n}"
|
return "fun method() {\n${withIndent}\n}"
|
||||||
}
|
}
|
||||||
@@ -1041,32 +1041,4 @@ class SmartEnterTest : JetLightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
private fun String.removeFirstEmptyLines() = this.split("\n").dropWhile { it.isEmpty() }.joinToString(separator = "\n")
|
private fun String.removeFirstEmptyLines() = this.split("\n").dropWhile { it.isEmpty() }.joinToString(separator = "\n")
|
||||||
|
|
||||||
deprecated("use kotlin.trimIndent instead")
|
|
||||||
private fun String.trimIndent(): String {
|
|
||||||
val lines = split('\n')
|
|
||||||
|
|
||||||
val firstNonEmpty = lines.firstOrNull { !it.trim().isEmpty() }
|
|
||||||
if (firstNonEmpty == null) {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
val trimmedPrefix = firstNonEmpty.takeWhile { ch -> ch.isWhitespace() }
|
|
||||||
if (trimmedPrefix.isEmpty()) {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines.map { line ->
|
|
||||||
if (line.trim().isEmpty()) {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!line.startsWith(trimmedPrefix)) {
|
|
||||||
throw IllegalArgumentException(
|
|
||||||
"""Invalid line "$line", ${trimmedPrefix.length()} whitespace character are expected""")
|
|
||||||
}
|
|
||||||
|
|
||||||
line.substring(trimmedPrefix.length())
|
|
||||||
}
|
|
||||||
}.joinToString(separator = "\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,33 +139,4 @@ public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJava
|
|||||||
private fun createKotlinFile(text: String): JetFile {
|
private fun createKotlinFile(text: String): JetFile {
|
||||||
return myFixture.configureByText("converterTestFile.kt", text) as JetFile
|
return myFixture.configureByText("converterTestFile.kt", text) as JetFile
|
||||||
}
|
}
|
||||||
|
|
||||||
deprecated("use kotlin.trimIndent instead")
|
|
||||||
private fun String.trimIndent(): String {
|
|
||||||
val lines = split('\n')
|
|
||||||
|
|
||||||
val firstNonEmpty = lines.firstOrNull { !it.trim().isEmpty() }
|
|
||||||
if (firstNonEmpty == null) {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
val trimmedPrefix = firstNonEmpty.takeWhile { ch -> ch.isWhitespace() }
|
|
||||||
if (trimmedPrefix.isEmpty()) {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines.map { line ->
|
|
||||||
if (line.trim().isEmpty()) {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!line.startsWith(trimmedPrefix)) {
|
|
||||||
throw IllegalArgumentException(
|
|
||||||
"""Invalid line "$line", ${trimmedPrefix.length()} whitespace character are expected""")
|
|
||||||
}
|
|
||||||
|
|
||||||
line.substring(trimmedPrefix.length())
|
|
||||||
}
|
|
||||||
}.joinToString(separator = "\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user