diff --git a/gradle.properties b/gradle.properties index 49355ac..eb30037 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ #Common Stuff -projectVersion=1.0.4 -projectChangelog=Added 'name' to POMs +projectVersion=1.0.5 +projectChangelog=Fixed String#toTitleCase(), added tests for methods inside StringExtensions projectDescription=Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case kotlinVersion=1.3.31 githubReleaseVersion=2.2.8 diff --git a/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt b/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt index df60c5a..cd69d7d 100644 --- a/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt +++ b/src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt @@ -71,4 +71,9 @@ enum class CaseFormat(private val wordUppercase: Boolean, private val wordSplitt * Joins [words] using this case format and returns the result. */ fun format(vararg words: String) = format(words.asIterable()) + + /** + * Converts a string to this [CaseFormat] using the word splitting rules defined in [splitToWords] + */ + fun format(string: String) = format(string.splitToWords()) } \ No newline at end of file diff --git a/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt b/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt index ee6ddfb..25a9430 100644 --- a/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt +++ b/src/commonMain/kotlin/net/pearx/kasechange/StringExtensions.kt @@ -10,7 +10,7 @@ package net.pearx.kasechange /** * Converts a string to specific [caseFormat] using the word splitting rules defined in [splitToWords]. */ -fun String.toCase(caseFormat: CaseFormat) = caseFormat.format(splitToWords()) +fun String.toCase(caseFormat: CaseFormat) = caseFormat.format(this) /** Converts a string to SCREAMING_SNAKE_CASE using the word splitting rules defined in [splitToWords]. */ fun String.toScreamingSnakeCase() = toCase(CaseFormat.UPPER_UNDERSCORE) @@ -27,7 +27,7 @@ fun String.toKebabCase() = toCase(CaseFormat.LOWER_HYPHEN) /** Converts a string to UPPER SPACE CASE using the word splitting rules defined in [splitToWords]. */ fun String.toUpperSpaceCase() = toCase(CaseFormat.UPPER_SPACE) /** Converts a string to Title Case using the word splitting rules defined in [splitToWords]. */ -fun String.toTitleCase() = toCase(CaseFormat.UPPER_SPACE) +fun String.toTitleCase() = toCase(CaseFormat.CAPITALIZED_SPACE) /** Converts a string to lower space case using the word splitting rules defined in [splitToWords]. */ fun String.toLowerSpaceCase() = toCase(CaseFormat.LOWER_SPACE) /** Converts a string to UPPER.DOT.CASE using the word splitting rules defined in [splitToWords]. */ diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt new file mode 100644 index 0000000..fa736a9 --- /dev/null +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt @@ -0,0 +1,69 @@ +/* + * Copyright © 2019, PearX Team + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package net.pearx.kasechange.test + +import net.pearx.kasechange.* +import kotlin.test.Test +import kotlin.test.assertEquals + +class ComplexTest { + @Test + fun testCamel() { + assertEquals("someString", "Some String".toCamelCase()) + } + + @Test + fun testPascal() { + assertEquals("SomeString", "Some String".toPascalCase()) + } + + @Test + fun testSnake() { + assertEquals("some_string", "Some String".toSnakeCase()) + } + + @Test + fun testScreamingSnake() { + assertEquals("SOME_STRING", "Some String".toScreamingSnakeCase()) + } + + @Test + fun testKebab() { + assertEquals("some-string", "Some String".toKebabCase()) + } + + @Test + fun testTrain() { + assertEquals("SOME-STRING", "Some String".toTrainCase()) + } + + @Test + fun testLowerSpace() { + assertEquals("some string", "Some String".toLowerSpaceCase()) + } + + @Test + fun testUpperSpace() { + assertEquals("SOME STRING", "Some String".toUpperSpaceCase()) + } + + @Test + fun testTitle() { + assertEquals("Some String", "some string".toTitleCase()) + } + + @Test + fun testDot() { + assertEquals("some.string", "Some String".toDotCase()) + } + + @Test + fun testDotUpper() { + assertEquals("SOME.STRING", "Some String".toUpperDotCase()) + } +} \ No newline at end of file