Skip to content

Commit 6564daa

Browse files
Improve String tests
1 parent 16b09e1 commit 6564daa

File tree

1 file changed

+47
-8
lines changed
  • kotlin-stdlib/common/test/kotlin/com/javiersc/kotlin/stdlib

1 file changed

+47
-8
lines changed

kotlin-stdlib/common/test/kotlin/com/javiersc/kotlin/stdlib/StringsTest.kt

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
@file:Suppress("RedundantExplicitType")
2+
13
package com.javiersc.kotlin.stdlib
24

35
import kotlin.test.Test
46
import kotlin.test.assertFalse
57
import kotlin.test.assertTrue
68

7-
class StringsTest {
9+
internal class StringsTest {
810

911
@Test
1012
fun string_capitalize() {
@@ -20,6 +22,18 @@ class StringsTest {
2022
assertTrue { "HElLo".decapitalize() == "hElLo" }
2123
}
2224

25+
@Test
26+
fun string_not_contain() {
27+
assertFalse { "Hello, World".notContain("Hello") }
28+
assertFalse { "HELLO, World".notContain("hello", ignoreCase = true) }
29+
assertTrue { "Hello, World".notContain("hello") }
30+
assertTrue { "Hello, World".notContain("hello", ignoreCase = false) }
31+
32+
val regex = Regex("[0-9]+")
33+
assertFalse { "Hello, World 1".notContain(regex) }
34+
assertTrue { "Hello, World".notContain(regex) }
35+
}
36+
2337
@Test
2438
fun string_remove() {
2539
assertTrue { "Hello, World".remove("Hello, ") == "World" }
@@ -35,18 +49,31 @@ class StringsTest {
3549
@Test
3650
fun string_isNotNullNorEmpty_and_string_isNotNullNorBlank() {
3751
val nullable: String? = null
38-
val blank = " "
39-
val empty = ""
40-
val notBlank = "Hello, World"
52+
val nullableCharSequence: CharSequence? = null
53+
val blank: String = " "
54+
val blankCharSequence: CharSequence = " "
55+
val empty: String = ""
56+
val emptyCharSequence: CharSequence = ""
57+
val notBlank: String = "Hello, World"
58+
val notBlankCharSequence: CharSequence = "Hello, World"
4159

42-
assertFalse { nullable.isNotNullNorBlank() }
4360
assertFalse { nullable.isNotNullNorEmpty() }
44-
assertFalse { blank.isNotNullNorBlank() }
61+
assertFalse { nullableCharSequence.isNotNullNorEmpty() }
4562
assertTrue { blank.isNotNullNorEmpty() }
46-
assertFalse { empty.isNotNullNorBlank() }
63+
assertTrue { blankCharSequence.isNotNullNorEmpty() }
4764
assertFalse { empty.isNotNullNorEmpty() }
48-
assertTrue { notBlank.isNotNullNorBlank() }
65+
assertFalse { emptyCharSequence.isNotNullNorEmpty() }
4966
assertTrue { notBlank.isNotNullNorEmpty() }
67+
assertTrue { notBlankCharSequence.isNotNullNorEmpty() }
68+
69+
assertFalse { nullable.isNotNullNorBlank() }
70+
assertFalse { nullableCharSequence.isNotNullNorBlank() }
71+
assertFalse { blank.isNotNullNorBlank() }
72+
assertFalse { blankCharSequence.isNotNullNorBlank() }
73+
assertFalse { empty.isNotNullNorBlank() }
74+
assertFalse { emptyCharSequence.isNotNullNorBlank() }
75+
assertTrue { notBlank.isNotNullNorBlank() }
76+
assertTrue { notBlankCharSequence.isNotNullNorBlank() }
5077
}
5178

5279
@Test
@@ -70,5 +97,17 @@ class StringsTest {
7097
assertTrue { "a\nb".endWithNewLine() == "a\nb\n" }
7198
assertTrue { "".endWithNewLine() == "" }
7299
assertTrue { "\n".endWithNewLine() == "\n" }
100+
assertTrue {
101+
"""
102+
|Hello, World
103+
|
104+
"""
105+
.trimMargin()
106+
.endWithNewLine() ==
107+
"""
108+
|Hello, World
109+
|
110+
""".trimMargin()
111+
}
73112
}
74113
}

0 commit comments

Comments
 (0)