removed unnecessary getOrElse(value) method as we can use ?: (which is neater!) though shame it doesn't work for lazy values, passing a function body which is invoked if the value is not null
This commit is contained in:
@@ -8,24 +8,37 @@ class GetOrElseTest() : TestSupport() {
|
||||
val v2: String? = null
|
||||
|
||||
fun testDefaultValue() {
|
||||
assertEquals("hello", v1.getOrElse("bar"))
|
||||
assertEquals("hello", v1?: "bar")
|
||||
|
||||
expect("hello") {
|
||||
v1.getOrElse("bar")
|
||||
v1?: "bar"
|
||||
}
|
||||
}
|
||||
|
||||
fun testDefaultValueOnNull() {
|
||||
assertEquals("bar", v2.getOrElse("bar"))
|
||||
assertEquals("bar", v2?: "bar")
|
||||
|
||||
expect("bar") {
|
||||
v2.getOrElse("bar")
|
||||
v2?: "bar"
|
||||
}
|
||||
}
|
||||
|
||||
/** TODO not supported yet?
|
||||
|
||||
fun testLazyDefaultValue() {
|
||||
var counter = 0
|
||||
|
||||
assertEquals("hello", v1?: { counter++; "bar"})
|
||||
assertEquals(counter, 0, "counter should not be incremented yet")
|
||||
|
||||
assertEquals("bar", v2?: { counter++; "bar"})
|
||||
assertEquals(counter, 1, "counter should be incremented in the default function")
|
||||
}
|
||||
*/
|
||||
|
||||
fun testLazyDefaultValueUsingMethod() {
|
||||
var counter = 0
|
||||
|
||||
assertEquals("hello", v1.getOrElse{ counter++; "bar"})
|
||||
assertEquals(counter, 0, "counter should not be incremented yet")
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ class DomBuilderTest() : TestSupport() {
|
||||
addElement("grandChild") {
|
||||
cssClass = "tiny"
|
||||
addText("Hello World!")
|
||||
// TODO support neater syntax sugar for adding text?
|
||||
// += "Hello World!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import std.*
|
||||
import std.dom.*
|
||||
import stdhack.test.*
|
||||
import org.w3c.dom.*
|
||||
import std.dom.toXmlString
|
||||
|
||||
class DomTest() : TestSupport() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user