stdlib: Introduced Array<T>?.orEmpty() in JVM-stdlib

This commit is contained in:
Denis Zharkov
2014-11-04 12:01:18 +04:00
committed by Andrey Breslav
parent 73ca75cc0b
commit da5164acd8
2 changed files with 17 additions and 0 deletions
@@ -197,4 +197,18 @@ class ArraysJVMTest {
expect(3000000000000) { longArray(1000000000000, 2000000000000).sum() }
expect(3.0.toFloat()) { floatArray(1.0.toFloat(), 2.0.toFloat()).sum() }
}
test fun orEmptyNull() {
val x: Array<String>? = null
val xArray: Array<String> = x.orEmpty()
expect(0) { xArray.size }
}
test fun orEmptyNotNull() {
val x: Array<String>? = array("1", "2")
val xArray: Array<String> = x.orEmpty()
expect(2) { xArray.size }
expect("1") { xArray[0] }
expect("2") { xArray[1] }
}
}