Skip to content

Commit

Permalink
Fixed String#toTitleCase(), added tests for methods inside StringExte…
Browse files Browse the repository at this point in the history
…nsions, version bump
  • Loading branch information
mrapplexz committed May 29, 2019
1 parent 1e2b573 commit 2e0f94b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/commonMain/kotlin/net/pearx/kasechange/CaseFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]. */
Expand Down
69 changes: 69 additions & 0 deletions src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt
Original file line number Diff line number Diff line change
@@ -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())
}
}

0 comments on commit 2e0f94b

Please sign in to comment.