Add samples for joinTo

KT-20357
This commit is contained in:
gzoritchak
2018-02-11 15:25:35 +01:00
committed by ilya-g
parent 40e3159463
commit f790635b30
11 changed files with 79 additions and 36 deletions
@@ -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)