1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package org.the_jk.cleversync
import com.google.common.truth.Truth.assertThat
import org.junit.Test
class StringUtilsTest {
@Test
fun splitEmpty() {
assertThat(StringUtils.split("", '.', keepEmpty = true)).containsExactly("")
assertThat(StringUtils.split("", '.', keepEmpty = false)).isEmpty()
}
@Test
fun splitSanity() {
assertThat(StringUtils.split("a.bb.a", '.')).containsExactly("a", "bb", "a").inOrder()
assertThat(StringUtils.split(".a.bb.a", '.', keepEmpty = true)).containsExactly("", "a", "bb", "a").inOrder()
assertThat(StringUtils.split(".a.bb.a", '.', keepEmpty = false)).containsExactly("a", "bb", "a").inOrder()
assertThat(StringUtils.split(".a.bb.a.", '.', keepEmpty = true))
.containsExactly("", "a", "bb", "a", "").inOrder()
assertThat(StringUtils.split(".a.bb.a.", '.', keepEmpty = false)).containsExactly("a", "bb", "a").inOrder()
}
@Test
fun splitDouble() {
assertThat(StringUtils.split("foo..bar", '.', keepEmpty = true)).containsExactly("foo", "", "bar").inOrder()
assertThat(StringUtils.split("foo..bar", '.', keepEmpty = false)).containsExactly("foo", "bar").inOrder()
}
@Test
fun splitLimit() {
assertThat(StringUtils.split("a.bb.a", '.', limit = 1)).containsExactly("a.bb.a")
assertThat(StringUtils.split("a.bb.a", '.', limit = 2)).containsExactly("a", "bb.a").inOrder()
assertThat(StringUtils.split("a.bb.a", '.', limit = 3)).containsExactly("a", "bb", "a").inOrder()
assertThat(StringUtils.split("a.bb.a.", '.', limit = 3, keepEmpty = true))
.containsExactly("a", "bb", "a.").inOrder()
assertThat(StringUtils.split("a.bb.a.", '.', limit = 3, keepEmpty = false))
.containsExactly("a", "bb", "a").inOrder()
assertThat(StringUtils.split("a.bb.a", '.', limit = 1000)).containsExactly("a", "bb", "a").inOrder()
}
}
|