Provide String.commonPrefixWith and String.commonSuffixWith methods.

Char.isHighSurrogate and Char.isLowSurrogate now available in js-stdlib too.
This commit is contained in:
Ilya Gorbunov
2015-04-03 21:35:56 +03:00
parent 70cc7fbf1f
commit 7cac6e3c5e
5 changed files with 129 additions and 9 deletions
+33
View File
@@ -70,6 +70,39 @@ class StringTest {
assertFalse("".endsWith('a'))
}
test fun commonPrefix() {
assertEquals("", "".commonPrefixWith(""))
assertEquals("", "any".commonPrefixWith(""))
assertEquals("", "".commonPrefixWith("any"))
assertEquals("", "some".commonPrefixWith("any"))
assertEquals("an", "annual".commonPrefixWith("any"))
assertEquals("an", "annual".commonPrefixWith("Any", ignoreCase = true))
assertEquals("", "annual".commonPrefixWith("Any", ignoreCase = false))
// surrogate pairs
val dth54 = "\uD83C\uDC58" // domino tile horizontal 5-4
val dth55 = "\uD83C\uDC59" // domino tile horizontal 5-5
assertEquals("", dth54.commonPrefixWith(dth55))
assertEquals(dth54, "$dth54$dth54".commonPrefixWith("$dth54$dth55"))
}
test fun commonSuffix() {
assertEquals("", "".commonSuffixWith(""))
assertEquals("", "any".commonSuffixWith(""))
assertEquals("", "".commonSuffixWith("any"))
assertEquals("", "some".commonSuffixWith("any"))
assertEquals("ly", "yearly".commonSuffixWith("monthly"))
assertEquals("strö", "strö".commonSuffixWith("BISTRÖ", ignoreCase = true))
assertEquals("", "yearly".commonSuffixWith("HARDLY", ignoreCase = false))
// surrogate pairs
val dth54 = "\uD83C\uDC58" // domino tile horizontal 5-4
val kimono = "\uD83D\uDC58" // kimono
assertEquals("", dth54.commonSuffixWith(kimono))
assertEquals("$dth54", "d$dth54".commonSuffixWith("s$dth54"))
}
test fun capitalize() {
assertEquals("A", "A".capitalize())
assertEquals("A", "a".capitalize())