Skip to content

Commit

Permalink
Added test for upper/lower on nuls
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Dec 30, 2023
1 parent 7ed0594 commit 179a31d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tribune-core/src/test/kotlin/com/sksamuel/tribune/core/strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,23 @@ class StringTest : FunSpec() {
p.parse("abcd") shouldBe Foo("ABCD").right()
}

test("uppercaseOrNull") {
val p = Parser<String?>().toUppercase().mapIfNotNull { Foo(it) }
p.parse("abcd") shouldBe Foo("ABCD").right()
p.parse(null) shouldBe Either.Right(null)
}

test("lowercase") {
val p = Parser<String>().toLowercase().map { Foo(it) }
p.parse("ABCD") shouldBe Foo("abcd").right()
}

test("lowercase or null") {
val p = Parser<String?>().toLowercase().mapIfNotNull { Foo(it) }
p.parse("ABCD") shouldBe Foo("abcd").right()
p.parse(null) shouldBe Either.Right(null)
}

test("strip") {
val p = Parser<String>().strip(charArrayOf('a', 'b'))
p.parse("aaccbb") shouldBe "cc".right()
Expand Down

0 comments on commit 179a31d

Please sign in to comment.