6fda0816f3
this method helps save computation time when the developer knows or have a good educated guess about the size of the generated string and have to use control structures while filling the string builder Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com> Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
23 lines
437 B
Kotlin
23 lines
437 B
Kotlin
package test.text
|
|
|
|
import kotlin.*
|
|
import kotlin.test.*
|
|
import org.junit.Test as test
|
|
|
|
class StringBuilderJVMTest() {
|
|
|
|
@test fun stringBuildWithInitialCapacity() {
|
|
val s = buildString(123) {
|
|
assertEquals(123, capacity())
|
|
}
|
|
}
|
|
|
|
@test fun getAndSetChar() {
|
|
val sb = StringBuilder("abc")
|
|
sb[1] = 'z'
|
|
|
|
assertEquals("azc", sb.toString())
|
|
assertEquals('c', sb[2])
|
|
}
|
|
}
|