Updated samples
This commit is contained in:
parent
6bd3b29dce
commit
4096e37e84
|
@ -4,7 +4,7 @@ import atomictest.*
|
|||
|
||||
class Level(
|
||||
val range: IntRange,
|
||||
private var level: Int = range.start
|
||||
private var level: Int = range.first
|
||||
) {
|
||||
init {
|
||||
require(level in range) {
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
// ExceptionHandling/CaptureImplementation.kt
|
||||
package exceptionhandling
|
||||
import atomictest.eq
|
||||
import atomictest.CapturedException
|
||||
|
||||
fun capture(f: () -> Unit): String = // [1]
|
||||
try { // [2]
|
||||
fun capture(f: () -> Unit): CapturedException =
|
||||
try { // [1]
|
||||
f()
|
||||
"Error: Expected an exception" // [3]
|
||||
} catch (e: Throwable) { // [4]
|
||||
"${e::class.simpleName}: ${e.message}"
|
||||
CapturedException(null, // [2]
|
||||
"[Error]: Expected an exception")
|
||||
} catch (e: Throwable) { // [3]
|
||||
CapturedException(e::class,
|
||||
if (e.message != null) ": ${e.message}"
|
||||
else "")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
|
@ -16,5 +19,5 @@ fun main() {
|
|||
} eq "Exception: !!!"
|
||||
capture {
|
||||
1
|
||||
} eq "Error: Expected an exception"
|
||||
} eq "[Error]: Expected an exception"
|
||||
}
|
|
@ -1,6 +1,19 @@
|
|||
// NothingType/ListOfNothing.kt
|
||||
import atomictest.eq
|
||||
|
||||
fun main() {
|
||||
val none: Nothing? = null
|
||||
|
||||
var nullableString: String? = null // [1]
|
||||
nullableString = "abc"
|
||||
nullableString eq "abc"
|
||||
nullableString = none
|
||||
nullableString eq null
|
||||
|
||||
val nullableInt: Int? = none
|
||||
nullableInt eq null
|
||||
|
||||
val listNone: List<Nothing?> = listOf(null)
|
||||
val ints: List<Int?> = listOf(null) // [4]
|
||||
ints eq listNone
|
||||
}
|
Loading…
Reference in New Issue