Locale-agnostic case conversions by default #KT-43023
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package samples.text
|
||||
|
||||
import samples.*
|
||||
import kotlin.test.*
|
||||
import java.util.*
|
||||
import kotlin.test.*
|
||||
|
||||
class Chars {
|
||||
|
||||
@@ -83,17 +83,41 @@ class Chars {
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toUpperCase() {
|
||||
val chars = listOf('a', 'ω', '1', 'A', '+')
|
||||
val upperCases = chars.map { it.toUpperCase() }
|
||||
assertPrints(upperCases, "[A, Ω, 1, A, +]")
|
||||
fun uppercase() {
|
||||
val chars = listOf('a', 'ω', '1', 'ʼn', 'A', '+', 'ß')
|
||||
val uppercaseChar = chars.map { it.uppercaseChar() }
|
||||
val uppercase = chars.map { it.uppercase() }
|
||||
assertPrints(uppercaseChar, "[A, Ω, 1, ʼn, A, +, ß]")
|
||||
assertPrints(uppercase, "[A, Ω, 1, ʼN, A, +, SS]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toLowerCase() {
|
||||
val chars = listOf('A', 'Ω', '1', 'a', '+')
|
||||
val lowerCases = chars.map { it.toLowerCase() }
|
||||
assertPrints(lowerCases, "[a, ω, 1, a, +]")
|
||||
fun uppercaseLocale() {
|
||||
val chars = listOf('a', '1', 'ʼn', 'A', '+', 'i')
|
||||
val uppercase = chars.map { it.uppercase() }
|
||||
val turkishLocale = Locale.forLanguageTag("tr")
|
||||
val uppercaseTurkish = chars.map { it.uppercase(turkishLocale) }
|
||||
assertPrints(uppercase, "[A, 1, ʼN, A, +, I]")
|
||||
assertPrints(uppercaseTurkish, "[A, 1, ʼN, A, +, İ]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun lowercase() {
|
||||
val chars = listOf('A', 'Ω', '1', 'a', '+', 'İ')
|
||||
val lowercaseChar = chars.map { it.lowercaseChar() }
|
||||
val lowercase = chars.map { it.lowercase() }
|
||||
assertPrints(lowercaseChar, "[a, ω, 1, a, +, i]")
|
||||
assertPrints(lowercase, "[a, ω, 1, a, +, \u0069\u0307]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun lowercaseLocale() {
|
||||
val chars = listOf('A', 'Ω', '1', 'a', '+', 'İ')
|
||||
val lowercase = chars.map { it.lowercase() }
|
||||
val turkishLocale = Locale.forLanguageTag("tr")
|
||||
val lowercaseTurkish = chars.map { it.lowercase(turkishLocale) }
|
||||
assertPrints(lowercase, "[a, ω, 1, a, +, \u0069\u0307]")
|
||||
assertPrints(lowercaseTurkish, "[a, ω, 1, a, +, i]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
@@ -105,10 +129,22 @@ class Chars {
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toTitleCase() {
|
||||
val chars = listOf('a', 'Dž', '1', '+')
|
||||
val titleCases = chars.map { it.toTitleCase() }
|
||||
assertPrints(titleCases, "[A, Dž, 1, +]")
|
||||
fun titlecase() {
|
||||
val chars = listOf('a', 'Dž', 'ʼn', '+', 'ß')
|
||||
val titlecaseChar = chars.map { it.titlecaseChar() }
|
||||
val titlecase = chars.map { it.titlecase() }
|
||||
assertPrints(titlecaseChar, "[A, Dž, ʼn, +, ß]")
|
||||
assertPrints(titlecase, "[A, Dž, ʼN, +, Ss]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun titlecaseLocale() {
|
||||
val chars = listOf('a', 'Dž', 'ʼn', '+', 'ß', 'i')
|
||||
val titlecase = chars.map { it.titlecase() }
|
||||
val turkishLocale = Locale.forLanguageTag("tr")
|
||||
val titlecaseTurkish = chars.map { it.titlecase(turkishLocale) }
|
||||
assertPrints(titlecase, "[A, Dž, ʼN, +, Ss, I]")
|
||||
assertPrints(titlecaseTurkish, "[A, Dž, ʼN, +, Ss, İ]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package samples.text
|
||||
|
||||
import samples.*
|
||||
import java.util.Locale
|
||||
import kotlin.test.*
|
||||
|
||||
class Strings {
|
||||
@@ -17,6 +18,15 @@ class Strings {
|
||||
assertPrints("Abcd".decapitalize(), "abcd")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun replaceFirstChar() {
|
||||
assertPrints("kotlin".replaceFirstChar { it.uppercase() }, "Kotlin")
|
||||
|
||||
val sentence = "Welcome to Kotlin!"
|
||||
val words = sentence.split(' ');
|
||||
assertPrints(words.joinToString(separator = "_") { word -> word.replaceFirstChar { it.lowercase() } }, "welcome_to_kotlin!")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun repeat() {
|
||||
assertPrints("Word".repeat(4), "WordWordWordWord")
|
||||
@@ -205,13 +215,27 @@ class Strings {
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toLowerCase() {
|
||||
assertPrints("Iced frappé!".toLowerCase(), "iced frappé!")
|
||||
fun lowercase() {
|
||||
assertPrints("Iced frappé!".lowercase(), "iced frappé!")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun toUpperCase() {
|
||||
assertPrints("Iced frappé!".toUpperCase(), "ICED FRAPPÉ!")
|
||||
fun lowercaseLocale() {
|
||||
assertPrints("KOTLIN".lowercase(), "kotlin")
|
||||
val turkishLocale = Locale.forLanguageTag("tr")
|
||||
assertPrints("KOTLIN".lowercase(turkishLocale), "kotlın")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun uppercase() {
|
||||
assertPrints("Iced frappé!".uppercase(), "ICED FRAPPÉ!")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun uppercaseLocale() {
|
||||
assertPrints("Kotlin".uppercase(), "KOTLIN")
|
||||
val turkishLocale = Locale.forLanguageTag("tr")
|
||||
assertPrints("Kotlin".uppercase(turkishLocale), "KOTLİN")
|
||||
}
|
||||
|
||||
@Sample
|
||||
|
||||
Reference in New Issue
Block a user