String.split(Pattern, limit) now treats limit differently: 0 means no limit is specified, but trailing empty elements are not stripped; -1 and other negative values are not allowed.

This commit is contained in:
Ilya Gorbunov
2015-04-06 21:00:34 +03:00
parent b1255cf95b
commit fb5a3a771c
2 changed files with 18 additions and 1 deletions
@@ -59,6 +59,17 @@ class StringJVMTest {
assertEquals(s, list[0])
}
test fun testSplitByPattern() {
val s = "ab1cd2def3"
val isDigit = "\\d".toRegex()
assertEquals(listOf("ab", "cd", "def", ""), s.split(isDigit))
assertEquals(listOf("ab", "cd", "def3"), s.split(isDigit, 3))
fails {
s.split(isDigit, -1)
}
}
test fun repeat() {
fails{ "foo".repeat(-1) }
assertEquals("", "foo".repeat(0))