Add samples for joinToString

KT-20357
This commit is contained in:
gzoritchak
2018-02-11 00:16:41 +01:00
committed by ilya-g
parent a36e8c86f1
commit 40e3159463
11 changed files with 113 additions and 0 deletions
@@ -311,6 +311,17 @@ class Collections {
assertPrints(moreFrequencies, "{o=1, t=4, f=2, s=2, e=2, n=1}")
}
@Sample
fun joinToString() {
val numbers = listOf(1, 2, 3, 4, 5, 6)
assertPrints(numbers.joinToString(), "1, 2, 3, 4, 5, 6")
assertPrints(numbers.joinToString(prefix = "[", postfix = "]"), "[1, 2, 3, 4, 5, 6]")
assertPrints(numbers.joinToString(prefix = "<", postfix = ">", separator = ""), "<1•2•3•4•5•6>")
val chars = charArrayOf('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q')
assertPrints(chars.joinToString(limit = 5, truncated = "...!") { it.toUpperCase().toString() }, "A, B, C, D, E, ...!")
}
@Sample
fun chunked() {
val words = "one two three four five six seven eight nine ten".split(' ')