added String?.orElse() to match Collection?.orElse()
This commit is contained in:
@@ -18,11 +18,12 @@ package stdlib.testall;
|
|||||||
|
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import test.collections.*;
|
import test.collections.*;
|
||||||
|
import test.string.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class CollectionTestAllTest {
|
public class CollectionTestAllTest {
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
return new TestSuite(CollectionTest.class, MapTest.class);
|
return new TestSuite(StringTest.class, CollectionTest.class, MapTest.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,3 +162,6 @@ inline fun String.subSequence(beginIndex : Int, endIndex : Int) = (this as java.
|
|||||||
inline fun String.toLowerCase(locale : java.util.Locale) = (this as java.lang.String).toLowerCase(locale).sure()
|
inline fun String.toLowerCase(locale : java.util.Locale) = (this as java.lang.String).toLowerCase(locale).sure()
|
||||||
|
|
||||||
inline fun String.toUpperCase(locale : java.util.Locale) = (this as java.lang.String).toUpperCase(locale).sure()
|
inline fun String.toUpperCase(locale : java.util.Locale) = (this as java.lang.String).toUpperCase(locale).sure()
|
||||||
|
|
||||||
|
/** Returns the string if it is not null or the empty string if its null */
|
||||||
|
inline fun String?.orEmpty(): String = this ?: ""
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package testString
|
package test.string
|
||||||
|
|
||||||
import kotlin.io.*
|
import kotlin.io.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
@@ -25,4 +25,12 @@ class StringTest() : TestCase() {
|
|||||||
sum += (c.toInt() - '0'.toInt())
|
sum += (c.toInt() - '0'.toInt())
|
||||||
assertTrue(sum == 14)
|
assertTrue(sum == 14)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testOrEmpty() {
|
||||||
|
val s: String? = "hey"
|
||||||
|
val ns: String? = null
|
||||||
|
|
||||||
|
assertEquals("hey", s.orEmpty())
|
||||||
|
assertEquals("", ns.orEmpty())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user