diff --git a/coding/sources/codecs/extended/EnumJSONTransformation.kt b/coding/sources/codecs/extended/EnumJSONTransformation.kt index bb00997..f463796 100644 --- a/coding/sources/codecs/extended/EnumJSONTransformation.kt +++ b/coding/sources/codecs/extended/EnumJSONTransformation.kt @@ -14,10 +14,12 @@ sealed class EnumJSONTransformation { enum class Case { lowerCamelCase, + `lower-kebab-case`, lower_snake_case, lowercase, `lowercase words`, UpperCamelCase, + `UPPER-KEBAB-CASE`, UPPER_SNAKE_CASE, UPPERCASE, `UPPERCASE WORDS` @@ -36,10 +38,12 @@ internal fun Case?.convert(string: String) = when (this) { null -> string Case.lowerCamelCase -> string.words().mapIndexed(::wordToLowerCamelCase).joinToString(separator = "") + Case.`lower-kebab-case` -> string.words().joinToString(separator = "-").toLowerCase() Case.lower_snake_case -> string.words().joinToString(separator = "_").toLowerCase() Case.lowercase -> string.toLowerCase() Case.`lowercase words` -> string.words().joinToString(separator = " ").toLowerCase() Case.UpperCamelCase -> string.words().joinToString(separator = "") { it.camelize() } + Case.`UPPER-KEBAB-CASE` -> string.words().joinToString(separator = "-").toUpperCase() Case.UPPER_SNAKE_CASE -> string.words().joinToString(separator = "_").toUpperCase() Case.UPPERCASE -> string.toUpperCase() Case.`UPPERCASE WORDS` -> string.words().joinToString(separator = " ").toUpperCase() diff --git a/coding/tests/sources/codecs/EnumJSONCodecTest.kt b/coding/tests/sources/codecs/EnumJSONCodecTest.kt index 6534642..e97363a 100644 --- a/coding/tests/sources/codecs/EnumJSONCodecTest.kt +++ b/coding/tests/sources/codecs/EnumJSONCodecTest.kt @@ -12,10 +12,12 @@ internal object EnumJSONCodecTest { "name" to mapOf( null to listOf( "lowerCamelCase123", + "lower-kebab-case123", "lower_snake_case123", "lowercase123", "lowercase words 123", "UpperCamelCase123", + "UPPER-KEBAB-CASE123", "UPPER_SNAKE_CASE123", "UPPERCASE123", "UPPERCASE WORDS 123", @@ -23,21 +25,38 @@ internal object EnumJSONCodecTest { ), Case.lowerCamelCase to listOf( "lowerCamelCase123", + "lowerKebabCase123", "lowerSnakeCase123", "lowercase123", "lowercaseWords123", "upperCamelCase123", + "upperKebabCase123", "upperSnakeCase123", "uppercase123", "uppercaseWords123", "0SomeSpacesUpperCaseWtfSnakesAreComingIn123Abc123JustHtmlXmlXmlJsonCodec1_0" ), + Case.`lower-kebab-case` to listOf( + "lower-camel-case-123", + "lower-kebab-case-123", + "lower-snake-case-123", + "lowercase-123", + "lowercase-words-123", + "upper-camel-case-123", + "upper-kebab-case-123", + "upper-snake-case-123", + "uppercase-123", + "uppercase-words-123", + "0-some-spaces-upper-case-wtf-snakes-are-coming-in-123-abc-123-just-html-xml-xml-json-codec-1_0" + ), Case.lower_snake_case to listOf( "lower_camel_case_123", + "lower_kebab_case_123", "lower_snake_case_123", "lowercase_123", "lowercase_words_123", "upper_camel_case_123", + "upper_kebab_case_123", "upper_snake_case_123", "uppercase_123", "uppercase_words_123", @@ -45,10 +64,12 @@ internal object EnumJSONCodecTest { ), Case.lowercase to listOf( "lowercamelcase123", + "lower-kebab-case123", "lower_snake_case123", "lowercase123", "lowercase words 123", "uppercamelcase123", + "upper-kebab-case123", "upper_snake_case123", "uppercase123", "uppercase words 123", @@ -56,10 +77,12 @@ internal object EnumJSONCodecTest { ), Case.`lowercase words` to listOf( "lower camel case 123", + "lower kebab case 123", "lower snake case 123", "lowercase 123", "lowercase words 123", "upper camel case 123", + "upper kebab case 123", "upper snake case 123", "uppercase 123", "uppercase words 123", @@ -67,21 +90,38 @@ internal object EnumJSONCodecTest { ), Case.UpperCamelCase to listOf( "LowerCamelCase123", + "LowerKebabCase123", "LowerSnakeCase123", "Lowercase123", "LowercaseWords123", "UpperCamelCase123", + "UpperKebabCase123", "UpperSnakeCase123", "Uppercase123", "UppercaseWords123", "0SomeSpacesUpperCaseWtfSnakesAreComingIn123Abc123JustHtmlXmlXmlJsonCodec1_0" ), + Case.`UPPER-KEBAB-CASE` to listOf( + "LOWER-CAMEL-CASE-123", + "LOWER-KEBAB-CASE-123", + "LOWER-SNAKE-CASE-123", + "LOWERCASE-123", + "LOWERCASE-WORDS-123", + "UPPER-CAMEL-CASE-123", + "UPPER-KEBAB-CASE-123", + "UPPER-SNAKE-CASE-123", + "UPPERCASE-123", + "UPPERCASE-WORDS-123", + "0-SOME-SPACES-UPPER-CASE-WTF-SNAKES-ARE-COMING-IN-123-ABC-123-JUST-HTML-XML-XML-JSON-CODEC-1_0" + ), Case.UPPER_SNAKE_CASE to listOf( "LOWER_CAMEL_CASE_123", + "LOWER_KEBAB_CASE_123", "LOWER_SNAKE_CASE_123", "LOWERCASE_123", "LOWERCASE_WORDS_123", "UPPER_CAMEL_CASE_123", + "UPPER_KEBAB_CASE_123", "UPPER_SNAKE_CASE_123", "UPPERCASE_123", "UPPERCASE_WORDS_123", @@ -89,10 +129,12 @@ internal object EnumJSONCodecTest { ), Case.UPPERCASE to listOf( "LOWERCAMELCASE123", + "LOWER-KEBAB-CASE123", "LOWER_SNAKE_CASE123", "LOWERCASE123", "LOWERCASE WORDS 123", "UPPERCAMELCASE123", + "UPPER-KEBAB-CASE123", "UPPER_SNAKE_CASE123", "UPPERCASE123", "UPPERCASE WORDS 123", @@ -100,10 +142,12 @@ internal object EnumJSONCodecTest { ), Case.`UPPERCASE WORDS` to listOf( "LOWER CAMEL CASE 123", + "LOWER KEBAB CASE 123", "LOWER SNAKE CASE 123", "LOWERCASE 123", "LOWERCASE WORDS 123", "UPPER CAMEL CASE 123", + "UPPER KEBAB CASE 123", "UPPER SNAKE CASE 123", "UPPERCASE 123", "UPPERCASE WORDS 123", @@ -113,10 +157,12 @@ internal object EnumJSONCodecTest { "toString" to mapOf( null to listOf( "lowerCamelCase123.toString()", + "lower-kebab-case123.toString()", "lower_snake_case123.toString()", "lowercase123.toString()", "lowercase words 123.toString()", "UpperCamelCase123.toString()", + "UPPER-KEBAB-CASE123.toString()", "UPPER_SNAKE_CASE123.toString()", "UPPERCASE123.toString()", "UPPERCASE WORDS 123.toString()", @@ -124,21 +170,38 @@ internal object EnumJSONCodecTest { ), Case.lowerCamelCase to listOf( "lowerCamelCase123ToString", + "lowerKebabCase123ToString", "lowerSnakeCase123ToString", "lowercase123ToString", "lowercaseWords123ToString", "upperCamelCase123ToString", + "upperKebabCase123ToString", "upperSnakeCase123ToString", "uppercase123ToString", "uppercaseWords123ToString", "0SomeSpacesUpperCaseWtfSnakesAreComingIn123Abc123JustHtmlXmlXmlJsonCodec1.0ToString" ), + Case.`lower-kebab-case` to listOf( + "lower-camel-case-123-to-string", + "lower-kebab-case-123-to-string", + "lower-snake-case-123-to-string", + "lowercase-123-to-string", + "lowercase-words-123-to-string", + "upper-camel-case-123-to-string", + "upper-kebab-case-123-to-string", + "upper-snake-case-123-to-string", + "uppercase-123-to-string", + "uppercase-words-123-to-string", + "0-some-spaces-upper-case-wtf-snakes-are-coming-in-123-abc-123-just-html-xml-xml-json-codec-1.0-to-string" + ), Case.lower_snake_case to listOf( "lower_camel_case_123_to_string", + "lower_kebab_case_123_to_string", "lower_snake_case_123_to_string", "lowercase_123_to_string", "lowercase_words_123_to_string", "upper_camel_case_123_to_string", + "upper_kebab_case_123_to_string", "upper_snake_case_123_to_string", "uppercase_123_to_string", "uppercase_words_123_to_string", @@ -146,10 +209,12 @@ internal object EnumJSONCodecTest { ), Case.lowercase to listOf( "lowercamelcase123.tostring()", + "lower-kebab-case123.tostring()", "lower_snake_case123.tostring()", "lowercase123.tostring()", "lowercase words 123.tostring()", "uppercamelcase123.tostring()", + "upper-kebab-case123.tostring()", "upper_snake_case123.tostring()", "uppercase123.tostring()", "uppercase words 123.tostring()", @@ -157,10 +222,12 @@ internal object EnumJSONCodecTest { ), Case.`lowercase words` to listOf( "lower camel case 123 to string", + "lower kebab case 123 to string", "lower snake case 123 to string", "lowercase 123 to string", "lowercase words 123 to string", "upper camel case 123 to string", + "upper kebab case 123 to string", "upper snake case 123 to string", "uppercase 123 to string", "uppercase words 123 to string", @@ -168,21 +235,38 @@ internal object EnumJSONCodecTest { ), Case.UpperCamelCase to listOf( "LowerCamelCase123ToString", + "LowerKebabCase123ToString", "LowerSnakeCase123ToString", "Lowercase123ToString", "LowercaseWords123ToString", "UpperCamelCase123ToString", + "UpperKebabCase123ToString", "UpperSnakeCase123ToString", "Uppercase123ToString", "UppercaseWords123ToString", "0SomeSpacesUpperCaseWtfSnakesAreComingIn123Abc123JustHtmlXmlXmlJsonCodec1.0ToString" ), + Case.`UPPER-KEBAB-CASE` to listOf( + "LOWER-CAMEL-CASE-123-TO-STRING", + "LOWER-KEBAB-CASE-123-TO-STRING", + "LOWER-SNAKE-CASE-123-TO-STRING", + "LOWERCASE-123-TO-STRING", + "LOWERCASE-WORDS-123-TO-STRING", + "UPPER-CAMEL-CASE-123-TO-STRING", + "UPPER-KEBAB-CASE-123-TO-STRING", + "UPPER-SNAKE-CASE-123-TO-STRING", + "UPPERCASE-123-TO-STRING", + "UPPERCASE-WORDS-123-TO-STRING", + "0-SOME-SPACES-UPPER-CASE-WTF-SNAKES-ARE-COMING-IN-123-ABC-123-JUST-HTML-XML-XML-JSON-CODEC-1.0-TO-STRING" + ), Case.UPPER_SNAKE_CASE to listOf( "LOWER_CAMEL_CASE_123_TO_STRING", + "LOWER_KEBAB_CASE_123_TO_STRING", "LOWER_SNAKE_CASE_123_TO_STRING", "LOWERCASE_123_TO_STRING", "LOWERCASE_WORDS_123_TO_STRING", "UPPER_CAMEL_CASE_123_TO_STRING", + "UPPER_KEBAB_CASE_123_TO_STRING", "UPPER_SNAKE_CASE_123_TO_STRING", "UPPERCASE_123_TO_STRING", "UPPERCASE_WORDS_123_TO_STRING", @@ -190,10 +274,12 @@ internal object EnumJSONCodecTest { ), Case.UPPERCASE to listOf( "LOWERCAMELCASE123.TOSTRING()", + "LOWER-KEBAB-CASE123.TOSTRING()", "LOWER_SNAKE_CASE123.TOSTRING()", "LOWERCASE123.TOSTRING()", "LOWERCASE WORDS 123.TOSTRING()", "UPPERCAMELCASE123.TOSTRING()", + "UPPER-KEBAB-CASE123.TOSTRING()", "UPPER_SNAKE_CASE123.TOSTRING()", "UPPERCASE123.TOSTRING()", "UPPERCASE WORDS 123.TOSTRING()", @@ -201,10 +287,12 @@ internal object EnumJSONCodecTest { ), Case.`UPPERCASE WORDS` to listOf( "LOWER CAMEL CASE 123 TO STRING", + "LOWER KEBAB CASE 123 TO STRING", "LOWER SNAKE CASE 123 TO STRING", "LOWERCASE 123 TO STRING", "LOWERCASE WORDS 123 TO STRING", "UPPER CAMEL CASE 123 TO STRING", + "UPPER KEBAB CASE 123 TO STRING", "UPPER SNAKE CASE 123 TO STRING", "UPPERCASE 123 TO STRING", "UPPERCASE WORDS 123 TO STRING", @@ -335,10 +423,12 @@ internal object EnumJSONCodecTest { @Suppress("EnumEntryName") private enum class Example { lowerCamelCase123, + `lower-kebab-case123`, lower_snake_case123, lowercase123, `lowercase words 123`, UpperCamelCase123, + `UPPER-KEBAB-CASE123`, UPPER_SNAKE_CASE123, UPPERCASE123, `UPPERCASE WORDS 123`, @@ -359,10 +449,12 @@ internal object EnumJSONCodecTest { override fun toString() = when (this) { lowerCamelCase123 -> "lowerCamelCase123.toString()" + `lower-kebab-case123` -> "lower-kebab-case123.toString()" lower_snake_case123 -> "lower_snake_case123.toString()" lowercase123 -> "lowercase123.toString()" `lowercase words 123` -> "lowercase words 123.toString()" UpperCamelCase123 -> "UpperCamelCase123.toString()" + `UPPER-KEBAB-CASE123` -> "UPPER-KEBAB-CASE123.toString()" UPPER_SNAKE_CASE123 -> "UPPER_SNAKE_CASE123.toString()" UPPERCASE123 -> "UPPERCASE123.toString()" `UPPERCASE WORDS 123` -> "UPPERCASE WORDS 123.toString()"