moved the stdlib tests into the same directory as the stdlib, so it works a bit better with maven support in IDEA
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package test.standard
|
||||
|
||||
import kotlin.*
|
||||
import kotlin.test.*
|
||||
import junit.framework.TestCase
|
||||
|
||||
class GetOrElseTest() : TestCase() {
|
||||
val v1: String? = "hello"
|
||||
val v2: String? = null
|
||||
var counter = 0
|
||||
|
||||
fun testDefaultValue() {
|
||||
assertEquals("hello", v1?: "bar")
|
||||
|
||||
expect("hello") {
|
||||
v1?: "bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun testDefaultValueOnNull() {
|
||||
assertEquals("bar", v2?: "bar")
|
||||
|
||||
expect("bar") {
|
||||
v2?: "bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateBar(): String {
|
||||
counter++
|
||||
return "bar"
|
||||
}
|
||||
|
||||
fun testLazyDefaultValue() {
|
||||
counter = 0
|
||||
|
||||
assertEquals("hello", v1?: calculateBar())
|
||||
assertEquals(counter, 0, "counter should not be incremented yet")
|
||||
|
||||
assertEquals("bar", v2?: calculateBar())
|
||||
assertEquals(counter, 1, "counter should be incremented in the default function")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user