Strict version of String.toBoolean() #KT-42071
This commit is contained in:
@@ -467,4 +467,30 @@ class Strings {
|
||||
assertFalse("Kotlin".contentEquals(stringBuilder))
|
||||
assertTrue("Kotlin".contentEquals(stringBuilder, ignoreCase = true))
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toBooleanStrict() {
|
||||
assertPrints("true".toBooleanStrict(), "true")
|
||||
assertFails { "True".toBooleanStrict() }
|
||||
assertFails { "TRUE".toBooleanStrict() }
|
||||
|
||||
assertPrints("false".toBooleanStrict(), "false")
|
||||
assertFails { "False".toBooleanStrict() }
|
||||
assertFails { "FALSE".toBooleanStrict() }
|
||||
|
||||
assertFails { "abc".toBooleanStrict() }
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toBooleanStrictOrNull() {
|
||||
assertPrints("true".toBooleanStrictOrNull(), "true")
|
||||
assertPrints("True".toBooleanStrictOrNull(), "null")
|
||||
assertPrints("TRUE".toBooleanStrictOrNull(), "null")
|
||||
|
||||
assertPrints("false".toBooleanStrictOrNull(), "false")
|
||||
assertPrints("False".toBooleanStrictOrNull(), "null")
|
||||
assertPrints("FALSE".toBooleanStrictOrNull(), "null")
|
||||
|
||||
assertPrints("abc".toBooleanStrictOrNull(), "null")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user