Introduce a deprecated StringBuilder.append(CharArray, Int, Int) in Common #KT-52336
This commit is contained in:
committed by
Space
parent
faedd76b32
commit
0db9326105
@@ -41,6 +41,10 @@ public fun kotlin.text.StringBuilder.append(vararg value: kotlin.Any?): kotlin.t
|
||||
|
||||
public fun kotlin.text.StringBuilder.append(vararg value: kotlin.String?): kotlin.text.StringBuilder
|
||||
|
||||
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use appendRange instead.", replaceWith = kotlin.ReplaceWith(expression = "this.appendRange(str, offset, offset + len)", imports = {}))
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun kotlin.text.StringBuilder.append(str: kotlin.CharArray, offset: kotlin.Int, len: kotlin.Int): kotlin.text.StringBuilder
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun kotlin.text.Appendable.appendLine(): kotlin.text.Appendable
|
||||
|
||||
@@ -41,6 +41,10 @@ public fun kotlin.text.StringBuilder.append(vararg value: kotlin.Any?): kotlin.t
|
||||
|
||||
public fun kotlin.text.StringBuilder.append(vararg value: kotlin.String?): kotlin.text.StringBuilder
|
||||
|
||||
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use appendRange instead.", replaceWith = kotlin.ReplaceWith(expression = "this.appendRange(str, offset, offset + len)", imports = {}))
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun kotlin.text.StringBuilder.append(str: kotlin.CharArray, offset: kotlin.Int, len: kotlin.Int): kotlin.text.StringBuilder
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun kotlin.text.Appendable.appendLine(): kotlin.text.Appendable
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package test.text
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class StringBuilderJVMTest {
|
||||
// KT-52336
|
||||
// Tests that the deprecated Common StringBuilder.append(CharArray, Int, Int) does not affect JVM target.
|
||||
@Test
|
||||
fun deprecatedAppend() {
|
||||
val chars = charArrayOf('a', 'b', 'c', 'd')
|
||||
val sb = StringBuilder()
|
||||
sb.append(chars, 1, 2)
|
||||
assertEquals("bc", sb.toString())
|
||||
}
|
||||
}
|
||||
@@ -437,6 +437,12 @@ public fun StringBuilder.append(vararg value: Any?): StringBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
// KT-52336
|
||||
@Deprecated("Use appendRange instead.", ReplaceWith("this.appendRange(str, offset, offset + len)"), level = DeprecationLevel.ERROR)
|
||||
@kotlin.internal.InlineOnly
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
public inline fun StringBuilder.append(str: CharArray, offset: Int, len: Int): StringBuilder = throw NotImplementedError()
|
||||
|
||||
/** Appends a line feed character (`\n`) to this StringBuilder. */
|
||||
@SinceKotlin("1.4")
|
||||
@kotlin.internal.InlineOnly
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package test.text
|
||||
|
||||
import test.testOnJvm
|
||||
import kotlin.random.Random
|
||||
import kotlin.test.*
|
||||
import kotlin.text.*
|
||||
@@ -32,6 +33,23 @@ class StringBuilderTest {
|
||||
})
|
||||
}
|
||||
|
||||
// KT-52336
|
||||
@Test
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
fun deprecatedAppend() {
|
||||
val chars = charArrayOf('a', 'b', 'c', 'd')
|
||||
val sb = StringBuilder()
|
||||
testOnJvm {
|
||||
sb.append(chars, 1, 2) // Should fail after KT-15220 gets fixed
|
||||
assertEquals("bc", sb.toString())
|
||||
}
|
||||
if (sb.isEmpty()) {
|
||||
assertFailsWith<NotImplementedError> {
|
||||
sb.append(chars, 1, 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun asCharSequence() {
|
||||
val original = "Some test string"
|
||||
val sb = StringBuilder(original)
|
||||
|
||||
Reference in New Issue
Block a user