-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tribune-core/src/test/kotlin/com/sksamuel/tribune/core/booleans/BooleanTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sksamuel.tribune.core.booleans | ||
|
||
import com.sksamuel.tribune.core.Parser | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class BooleanTest : FunSpec() { | ||
init { | ||
test("parser should support String -> Boolean") { | ||
val p = Parser<String>().toBoolean() | ||
p.parse("foo").getOrNull() shouldBe false | ||
p.parse("true").getOrNull() shouldBe true | ||
p.parse("false").getOrNull() shouldBe false | ||
} | ||
|
||
test("parser should support String -> Boolean using strict mode") { | ||
val p = Parser<String>().toBooleanStrict { "not a boolean" } | ||
p.parse("foo").leftOrNull() shouldBe listOf("not a boolean") | ||
p.parse("true").getOrNull() shouldBe true | ||
p.parse("false").getOrNull() shouldBe false | ||
} | ||
|
||
test("parser should support String -> Boolean? using strict mode or null") { | ||
val p = Parser<String>().toBooleanStrictOrNull() | ||
p.parse("foo").getOrNull() shouldBe null | ||
p.parse("true").getOrNull() shouldBe true | ||
p.parse("false").getOrNull() shouldBe false | ||
} | ||
} | ||
} |