stdlib: Introduced Array<T>?.orEmpty() in JVM-stdlib
This commit is contained in:
committed by
Andrey Breslav
parent
73ca75cc0b
commit
da5164acd8
@@ -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] }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user