Add samples for joinTo
KT-20357
This commit is contained in:
@@ -311,6 +311,17 @@ class Collections {
|
||||
assertPrints(moreFrequencies, "{o=1, t=4, f=2, s=2, e=2, n=1}")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun joinTo() {
|
||||
val sb = StringBuilder("An existing string and a list: ")
|
||||
val numbers = listOf(1, 2, 3)
|
||||
assertPrints(numbers.joinTo(sb, prefix = "[", postfix = "]").toString(), "An existing string and a list: [1, 2, 3]")
|
||||
|
||||
val lotOfNumbers: Iterable<Int> = 1..100
|
||||
val firstNumbers = StringBuilder("First five numbers: ")
|
||||
assertPrints(lotOfNumbers.joinTo(firstNumbers, limit = 5).toString(), "First five numbers: 1, 2, 3, 4, 5, ...")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun joinToString() {
|
||||
val numbers = listOf(1, 2, 3, 4, 5, 6)
|
||||
|
||||
Reference in New Issue
Block a user