added String?.orElse() to match Collection?.orElse()

This commit is contained in:
James Strachan
2012-03-05 22:12:12 +00:00
parent b37a41ea30
commit 5b419e7f2d
3 changed files with 14 additions and 2 deletions
@@ -18,11 +18,12 @@ package stdlib.testall;
import junit.framework.TestSuite;
import test.collections.*;
import test.string.*;
/**
*/
public class CollectionTestAllTest {
public static TestSuite suite() {
return new TestSuite(CollectionTest.class, MapTest.class);
return new TestSuite(StringTest.class, CollectionTest.class, MapTest.class);
}
}
+3
View File
@@ -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.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 ?: ""
+9 -1
View File
@@ -1,4 +1,4 @@
package testString
package test.string
import kotlin.io.*
import kotlin.test.*
@@ -25,4 +25,12 @@ class StringTest() : TestCase() {
sum += (c.toInt() - '0'.toInt())
assertTrue(sum == 14)
}
fun testOrEmpty() {
val s: String? = "hey"
val ns: String? = null
assertEquals("hey", s.orEmpty())
assertEquals("", ns.orEmpty())
}
}