Unify Regex.split behavior in JVM, JS regarding empty match delimiters

Rewrite split implementation for JVM

#KT-21049
This commit is contained in:
Ilya Gorbunov
2018-08-08 19:28:12 +03:00
parent 85af1f5d38
commit 5412227380
2 changed files with 35 additions and 1 deletions
+18
View File
@@ -203,6 +203,24 @@ class RegexTest {
}
@Test fun splitByEmptyMatch() {
val input = "test"
val emptyMatch = "".toRegex()
assertEquals(input.split(""), input.split(emptyMatch))
assertEquals(input.split("", limit = 3), input.split(emptyMatch, limit = 3))
assertEquals("".split(""), "".split(emptyMatch))
val emptyMatchBeforeT = "(?=t)".toRegex()
assertEquals(listOf("", "tes", "t"), input.split(emptyMatchBeforeT))
assertEquals(listOf("", "test"), input.split(emptyMatchBeforeT, limit = 2))
assertEquals(listOf("", "tee"), "tee".split(emptyMatchBeforeT))
}
}