diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatTest.kt deleted file mode 100644 index 59b31be..0000000 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.CaseFormat -import net.pearx.kasechange.formatter.CaseFormatterConfig -import net.pearx.kasechange.formatter.CaseFormatterConfigurable -import net.pearx.kasechange.formatter.format -import kotlin.test.Test -import kotlin.test.assertEquals - -class CaseFormatTest { - @Test - fun testCamel() { - assertEquals("camelMeUpInside", CaseFormat.CAMEL.format("CAMEL", "mE", "Up", "inside")) - } - - @Test - fun testPascal() { - assertEquals("PascalMeUpInside", CaseFormat.CAPITALIZED_CAMEL.format("paSCal", "ME", "up", "INside")) - } - - @Test - fun testSnake() { - assertEquals("snake_me_up_inside", CaseFormat.LOWER_UNDERSCORE.format("SNAKE", "ME", "up", "INside")) - } - - @Test - fun testScreamingSnake() { - assertEquals("DONT_MAKE_ME_SCREAM", CaseFormat.UPPER_UNDERSCORE.format("dont", "mAke", "ME", "scREAM")) - } - - @Test - fun testKebab() { - assertEquals("i-like-kebabs", CaseFormat.LOWER_HYPHEN.format("I", "like", "KEbabs")) - } - - @Test - fun testTrain() { - assertEquals("CHOO-CHOO-MTHRFCKRS", CaseFormat.UPPER_HYPHEN.format("choo", "CHOO", "mthrfckrs")) - } - - @Test - fun testLowerSpace() { - assertEquals("some regular string", CaseFormat.LOWER_SPACE.format("SOME", "regUlar", "STRing")) - } - - @Test - fun testUpperSpace() { - assertEquals("SOME REGULAR STRING", CaseFormat.UPPER_SPACE.format("SOME", "regUlar", "STRing")) - } - - @Test - fun testTitle() { - assertEquals("Some Really Interesting Title", CaseFormat.CAPITALIZED_SPACE.format("somE", "Really", "interesting", "TITLE")) - } - - @Test - fun testDot() { - assertEquals("dot.case.is.fun", CaseFormat.LOWER_DOT.format("dot", "Case", "is", "FUN")) - } - - @Test - fun testDotUpper() { - assertEquals("DOT.CASE.IS.FUN", CaseFormat.UPPER_DOT.format("dot", "Case", "is", "FUN")) - } - - @Test - fun testConfig() { - assertEquals("Config..Allows..More..Options", CaseFormatterConfigurable(CaseFormatterConfig(false, "..", wordCapitalize = true, firstWordCapitalize = true)).format("config", "Allows", "more", "OPTIONS")) - } -} \ No newline at end of file diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt new file mode 100644 index 0000000..d1289e3 --- /dev/null +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/CaseFormatterTest.kt @@ -0,0 +1,71 @@ +package net.pearx.kasechange.test + +import net.pearx.kasechange.CaseFormat +import net.pearx.kasechange.formatter.CaseFormatterConfig +import net.pearx.kasechange.formatter.CaseFormatterConfigurable +import net.pearx.kasechange.formatter.format +import kotlin.test.Test +import kotlin.test.assertEquals + +class CaseFormatterTest { + + @Test + fun testCamel() { + assertEquals("xmlHttpRequestV2Updated", CaseFormat.CAMEL.format("XmL", "http", "reQuEST", "v2", "Updated")) + } + + @Test + fun testPascal() { + assertEquals("XmlHttpRequestV2Updated", CaseFormat.CAPITALIZED_CAMEL.format("xml", "HTTP", "reQuEsT", "v2", "Updated")) + } + + @Test + fun testSnake() { + assertEquals("xml_http_request_v2_updated", CaseFormat.LOWER_UNDERSCORE.format("XML", "htTp", "REQUEST", "V2", "updated")) + } + + @Test + fun testScreamingSnake() { + assertEquals("XML_HTTP_REQUEST_V2_UPDATED", CaseFormat.UPPER_UNDERSCORE.format("xml", "HTTP", "reQUEst", "v2", "updated")) + } + + @Test + fun testKebab() { + assertEquals("xml-http-request-v2-updated", CaseFormat.LOWER_HYPHEN.format("XML", "http", "reQuEST", "V2", "Updated")) + } + + @Test + fun testTrain() { + assertEquals("XML-HTTP-REQUEST-V2-UPDATED", CaseFormat.UPPER_HYPHEN.format("XML", "http", "reQuEST", "V2", "Updated")) + } + + @Test + fun testLowerSpace() { + assertEquals("xml http request v2 updated", CaseFormat.LOWER_SPACE.format("XML", "http", "reQuEST", "V2", "Updated")) + } + + @Test + fun testUpperSpace() { + assertEquals("XML HTTP REQUEST V2 UPDATED", CaseFormat.UPPER_SPACE.format("XmL", "http", "reQuEST", "v2", "Updated")) + } + + @Test + fun testTitle() { + assertEquals("Xml Http Request V2 Updated", CaseFormat.CAPITALIZED_SPACE.format("XmL", "http", "reQuEST", "v2", "Updated")) + } + + @Test + fun testDot() { + assertEquals("xml.http.request.v2.updated", CaseFormat.LOWER_DOT.format("XML", "http", "reQuEST", "V2", "Updated")) + } + + @Test + fun testDotUpper() { + assertEquals("XML.HTTP.REQUEST.V2.UPDATED", CaseFormat.UPPER_DOT.format("xml", "HTTP", "reQUEst", "v2", "updated")) + } + + @Test + fun testConfig() { + assertEquals("Xml**Http**Request**V2**Updated", CaseFormatterConfigurable(CaseFormatterConfig(false, "**", wordCapitalize = true, firstWordCapitalize = true)).format("XmL", "http", "REQUEST", "v2", "uPDated")) + } +} \ No newline at end of file diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt index a727dc4..055554f 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/ComplexTest.kt @@ -1,75 +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 net.pearx.kasechange.formatter.CaseFormatterConfig +import net.pearx.kasechange.formatter.CaseFormatterConfigurable import kotlin.test.Test import kotlin.test.assertEquals class ComplexTest { @Test fun testCamel() { - assertEquals("someStringWith123Numbers", "Some String With 123 Numbers".toCamelCase()) + assertEquals("xmlHttpRequestV2Updated", "xml_http_request_v2_updated".toCamelCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testPascal() { - assertEquals("SomeStringWith123Numbers", "Some String With 123 Numbers".toPascalCase()) + assertEquals("XmlHttpRequestV2Updated", "xml_http_request_v2_updated".toPascalCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testSnake() { - assertEquals("some_string_with_123_numbers", "Some String With 123 Numbers".toSnakeCase()) + assertEquals("xml_http_request_v2_updated", "XML_HTTP_REQUEST_V2_UPDATED".toSnakeCase(CaseFormat.UPPER_UNDERSCORE)) } @Test fun testScreamingSnake() { - assertEquals("SOME_STRING_WITH_123_NUMBERS", "Some String With 123 Numbers".toScreamingSnakeCase()) + assertEquals("XML_HTTP_REQUEST_V2_UPDATED", "xml_http_request_v2_updated".toScreamingSnakeCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testKebab() { - assertEquals("some-string-with-123-numbers", "Some String With 123 Numbers".toKebabCase()) + assertEquals("xml-http-request-v2-updated", "xml_http_request_v2_updated".toKebabCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testTrain() { - assertEquals("SOME-STRING-WITH-123-NUMBERS", "Some String With 123 Numbers".toTrainCase()) + assertEquals("XML-HTTP-REQUEST-V2-UPDATED", "xml_http_request_v2_updated".toTrainCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testLowerSpace() { - assertEquals("some string with 123 numbers", "Some String With 123 Numbers".toLowerSpaceCase()) + assertEquals("xml http request v2 updated", "xml_http_request_v2_updated".toLowerSpaceCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testUpperSpace() { - assertEquals("SOME STRING WITH 123 NUMBERS", "Some String With 123 Numbers".toUpperSpaceCase()) + assertEquals("XML HTTP REQUEST V2 UPDATED", "xml_http_request_v2_updated".toUpperSpaceCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testTitle() { - assertEquals("Some String With 123 Numbers", "some string with 123 numbers".toTitleCase()) + assertEquals("Xml Http Request V2 Updated", "xml_http_request_v2_updated".toTitleCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testDot() { - assertEquals("some.string.with.123.numbers", "Some String With 123 Numbers".toDotCase()) + assertEquals("xml.http.request.v2.updated", "xml_http_request_v2_updated".toDotCase(CaseFormat.LOWER_UNDERSCORE)) } @Test fun testDotUpper() { - assertEquals("SOME.STRING.WITH.123.NUMBERS", "Some String With 123 Numbers".toUpperDotCase()) + assertEquals("XML.HTTP.REQUEST.V2.UPDATED", "xml_http_request_v2_updated".toUpperDotCase(CaseFormat.LOWER_UNDERSCORE)) } @Test - fun testConfig() { - assertEquals("Some..String..With..123..Numbers", "Some String With 123 Numbers".toCase(CaseFormatterConfig(false, "..", wordCapitalize = true, firstWordCapitalize = true))) + fun testMulti1() { + assertEquals("My**Xml**Request**V2**Updated", "MY XML-REQUEST.V2_UPDATED".toCase(CaseFormatterConfig(false, "**", wordCapitalize = true, firstWordCapitalize = true), universalWordSplitter(false))) } } \ No newline at end of file diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/SplitToWordsTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/SplitToWordsTest.kt deleted file mode 100644 index 06f4021..0000000 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/SplitToWordsTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.UNIVERSAL_WORD_SPLITTER -import kotlin.test.Test -import kotlin.test.assertEquals - -class SplitToWordsTest { - @Test - fun testSplittingCharacters() { - assertEquals(listOf("snake", "case"), UNIVERSAL_WORD_SPLITTER.splitToWords("snake_case")) - assertEquals(listOf("kebab", "case"), UNIVERSAL_WORD_SPLITTER.splitToWords("kebab-case")) - assertEquals(listOf("space", "case"), UNIVERSAL_WORD_SPLITTER.splitToWords("space case")) - assertEquals(listOf("some", "util", "random"), UNIVERSAL_WORD_SPLITTER.splitToWords("some-util_random")) - assertEquals(listOf("java", "util", "Arrays"), UNIVERSAL_WORD_SPLITTER.splitToWords("java.util.Arrays")) - } - - @Test - fun testLetterCase() { - assertEquals(listOf("camel", "Cased", "String"), UNIVERSAL_WORD_SPLITTER.splitToWords("camelCasedString")) - assertEquals(listOf("Pascal", "Cased", "String"), UNIVERSAL_WORD_SPLITTER.splitToWords("PascalCasedString")) - assertEquals(listOf("XML", "Http", "Request"), UNIVERSAL_WORD_SPLITTER.splitToWords("XMLHttpRequest")) - assertEquals(listOf("Simple", "XML", "Http", "Request"), UNIVERSAL_WORD_SPLITTER.splitToWords("SimpleXMLHttpRequest")) - assertEquals(listOf("XMLHTTP"), UNIVERSAL_WORD_SPLITTER.splitToWords("XMLHTTP")) - assertEquals(listOf("S", "Class", "C"), UNIVERSAL_WORD_SPLITTER.splitToWords("SClassC")) - assertEquals(listOf("XML", "Http", "Request", "JSON"), UNIVERSAL_WORD_SPLITTER.splitToWords("XMLHttpRequestJSON")) - assertEquals(listOf("U", "Int", "32", "Value"), UNIVERSAL_WORD_SPLITTER.splitToWords("UInt32Value")) - } -} \ No newline at end of file diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt index 4ced87e..c6f0654 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitter2Test.kt @@ -57,17 +57,17 @@ class UniversalWordSplitter2Test { @Test fun testTitle() { - assertEquals(listOf("XML", "Request", "V2", "Updated"), "XML Request V2 Updated".splitToWords(universalWordSplitter(false))) + assertEquals(listOf("XML", "Http", "Request", "V2", "Updated"), "XML Http Request V2 Updated".splitToWords(universalWordSplitter(false))) } @Test fun testDot() { - assertEquals(listOf("xml", "request", "v2", "updated"), "xml.request.v2.updated".splitToWords(universalWordSplitter(false))) + assertEquals(listOf("xml", "http", "request", "v2", "updated"), "xml.http.request.v2.updated".splitToWords(universalWordSplitter(false))) } @Test fun testDotUpper() { - assertEquals(listOf("XML", "REQUEST", "V2", "UPDATED"), "XML.REQUEST.V2.UPDATED".splitToWords(universalWordSplitter(false))) + assertEquals(listOf("XML", "HTTP", "REQUEST", "V2", "UPDATED"), "XML.HTTP.REQUEST.V2.UPDATED".splitToWords(universalWordSplitter(false))) } @Test diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt index 4140856..d438db2 100644 --- a/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/UniversalWordSplitterTest.kt @@ -7,8 +7,6 @@ package net.pearx.kasechange.test -import net.pearx.kasechange.formatter.CaseFormatterConfig -import net.pearx.kasechange.toCase import net.pearx.kasechange.splitToWords import kotlin.test.Test import kotlin.test.assertEquals diff --git a/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt b/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt new file mode 100644 index 0000000..ec61cfa --- /dev/null +++ b/src/commonTest/kotlin/net/pearx/kasechange/test/WordSplitterTest.kt @@ -0,0 +1,70 @@ +package net.pearx.kasechange.test + +import net.pearx.kasechange.CaseFormat +import net.pearx.kasechange.splitToWords +import net.pearx.kasechange.splitter.WordSplitter +import net.pearx.kasechange.splitter.WordSplitterConfig +import kotlin.test.Test +import kotlin.test.assertEquals + +class WordSplitterTest { + @Test + fun testCamel() { + assertEquals(listOf("xml", "Http", "Request", "V2", "Updated"), "xmlHttpRequestV2Updated".splitToWords(CaseFormat.CAMEL)) + } + + @Test + fun testPascal() { + assertEquals(listOf("XML", "Http", "Request", "V2", "Updated"), "XMLHttpRequestV2Updated".splitToWords(CaseFormat.CAPITALIZED_CAMEL)) + } + + @Test + fun testSnake() { + assertEquals(listOf("xml", "http", "request", "v2", "updated"), "xml_http_request_v2_updated".splitToWords(CaseFormat.LOWER_UNDERSCORE)) + } + + @Test + fun testScreamingSnake() { + assertEquals(listOf("XML", "HTTP", "REQUEST", "V2", "UPDATED"), "XML_HTTP_REQUEST_V2_UPDATED".splitToWords(CaseFormat.UPPER_UNDERSCORE)) + } + + @Test + fun testKebab() { + assertEquals(listOf("xml", "http", "request", "v2", "updated"), "xml-http-request-v2-updated".splitToWords(CaseFormat.LOWER_HYPHEN)) + } + + @Test + fun testTrain() { + assertEquals(listOf("XML", "HTTP", "REQUEST", "V2", "UPDATED"), "XML-HTTP-REQUEST-V2-UPDATED".splitToWords(CaseFormat.UPPER_HYPHEN)) + } + + @Test + fun testLowerSpace() { + assertEquals(listOf("xml", "http", "request", "v2", "updated"), "xml http request v2 updated".splitToWords(CaseFormat.LOWER_SPACE)) + } + + @Test + fun testUpperSpace() { + assertEquals(listOf("XML", "HTTP", "REQUEST", "V2", "UPDATED"), "XML HTTP REQUEST V2 UPDATED".splitToWords(CaseFormat.UPPER_SPACE)) + } + + @Test + fun testTitle() { + assertEquals(listOf("XML", "Request", "V2", "Updated"), "XML Request V2 Updated".splitToWords(CaseFormat.CAPITALIZED_SPACE)) + } + + @Test + fun testDot() { + assertEquals(listOf("xml", "request", "v2", "updated"), "xml.request.v2.updated".splitToWords(CaseFormat.LOWER_DOT)) + } + + @Test + fun testDotUpper() { + assertEquals(listOf("XML", "REQUEST", "V2", "UPDATED"), "XML.REQUEST.V2.UPDATED".splitToWords(CaseFormat.UPPER_DOT)) + } + + @Test + fun testConfig() { + assertEquals(listOf("xml", "Request", "V2", "Updated"), "xml*Request*V2*Updated".splitToWords(WordSplitterConfig(boundaries = setOf('*')))) + } +} \ No newline at end of file