diff --git a/src/main/scala/casing/Casing.scala b/src/main/scala/casing/Casing.scala index 7d500e8..f44bf8b 100644 --- a/src/main/scala/casing/Casing.scala +++ b/src/main/scala/casing/Casing.scala @@ -2,24 +2,24 @@ package casing import scala.util.matching.Regex -protected class Casing { +class Casing { // finds a lower char followed by an upper char and returns them as capture groups // e.g. fooBar -> foo, Bar - private val LOWER_UPPER_REGEX: Regex = "([\\p{Ll}])(\\p{Lu})".r + private val LOWER_UPPER_REGEX: Regex = "(\\p{Ll})(\\p{Lu})".r // finds an upper char followed by and upper and lower char and return them as capture groups // e.g. FOOBar -> FOO, Bar - private val UPPER_UPPER_LOWER_REGEX: Regex = "(\\p{Lu})([\\p{Lu}][\\p{Ll}])".r + private val UPPER_UPPER_LOWER_REGEX: Regex = "(\\p{Lu})(\\p{Lu}\\p{Ll})".r // finds a number followed by a letter and returns them as capture groups private val NUMBER_LETTER_REGEX: Regex = "(\\d)(\\p{L})".r // finds a letter followed by a number and returns them as capture groups private val LETTER_NUMBER_REGEX: Regex = "(\\p{L})(\\d)".r // finds all non-alphanumeric characters (including non-ASCII) private val NON_ALPHANUMERIC_REGEXP: Regex = "[^\\p{L}\\d]+".r - // use a null character as a delimeter - private val DELIMETER = "\u0000" + // use a null character as a delimiter + private val DELIMITER = "\u0000" // a regex replacement value that will be used to replace the matched value with - // the first capture group followed by a delimeter and the second capture group - private val REPLACEMENT_SEPARATOR: String = s"$$1$DELIMETER$$2" + // the first capture group followed by a delimiter and the second capture group + private val REPLACEMENT_SEPARATOR: String = s"$$1$DELIMITER$$2" def caseSplit(input: String, options: SplitOptions = SplitOptions()): Seq[String] = { var result = input @@ -32,9 +32,9 @@ protected class Casing { .replaceAll(LETTER_NUMBER_REGEX.pattern.pattern(), REPLACEMENT_SEPARATOR) } - result = result.replaceAll(NON_ALPHANUMERIC_REGEXP.pattern.pattern(), DELIMETER) + result = result.replaceAll(NON_ALPHANUMERIC_REGEXP.pattern.pattern(), DELIMITER) - result.split(DELIMETER).filter(_.nonEmpty) + result.split(DELIMITER).filter(_.nonEmpty) } // foo bar -> fooBar diff --git a/src/main/scala/example/Example.scala b/src/main/scala/casing/Example.scala similarity index 90% rename from src/main/scala/example/Example.scala rename to src/main/scala/casing/Example.scala index 719001c..7a02d9d 100644 --- a/src/main/scala/example/Example.scala +++ b/src/main/scala/casing/Example.scala @@ -1,6 +1,6 @@ import casing._ -object Example extends App { +private object Example extends App { println(camelCase("foo_bar")) // fooBar println(pascalCase("foo bar")) // FooBar println(snakeCase("fooBar")) // foo_bar diff --git a/src/test/scala/casing/CasingTest.scala b/src/test/scala/casing/CasingTest.scala index 5793c2d..4e57094 100644 --- a/src/test/scala/casing/CasingTest.scala +++ b/src/test/scala/casing/CasingTest.scala @@ -1,6 +1,7 @@ +package casing + import minitest._ -import casing.test.TestUtils.expect -import casing._ +import casing.TestUtils.expect object CasingTest extends SimpleTestSuite { test("split") { @@ -47,8 +48,8 @@ object CasingTest extends SimpleTestSuite { test("isCamelCase") { assert(isCamelCase("fooBar")) - assert(isCamelCase("FooBar") == false) - assert(isCamelCase("foo_bar") == false) + assert(!isCamelCase("FooBar")) + assert(!isCamelCase("foo_bar")) } test("PascalCase") { @@ -58,8 +59,8 @@ object CasingTest extends SimpleTestSuite { test("isPascalCase") { assert(isPascalCase("FooBar")) - assert(isPascalCase("fooBar") == false) - assert(isPascalCase("foo_bar") == false) + assert(!isPascalCase("fooBar")) + assert(!isPascalCase("foo_bar")) } test("snake_case") { @@ -74,8 +75,8 @@ object CasingTest extends SimpleTestSuite { test("isSnakeCase") { assert(isSnakeCase("foo_bar")) - assert(isSnakeCase("fooBar") == false) - assert(isSnakeCase("FOO_BAR") == false) + assert(!isSnakeCase("fooBar")) + assert(!isSnakeCase("FOO_BAR")) } test("CONSTANT_CASE") { @@ -90,8 +91,8 @@ object CasingTest extends SimpleTestSuite { test("isConstantCase") { assert(isConstantCase("FOO_BAR")) - assert(isConstantCase("fooBar") == false) - assert(isConstantCase("foo_bar") == false) + assert(!isConstantCase("fooBar")) + assert(!isConstantCase("foo_bar")) } test("kebab-case") { @@ -106,8 +107,8 @@ object CasingTest extends SimpleTestSuite { test("isKebabCase") { assert(isKebabCase("foo-bar")) - assert(isKebabCase("FOO-BAR") == false) - assert(isKebabCase("FOO_BAR") == false) - assert(isKebabCase("fooBar") == false) + assert(!isKebabCase("FOO-BAR")) + assert(!isKebabCase("FOO_BAR")) + assert(!isKebabCase("fooBar")) } } diff --git a/src/test/scala/casing/utils.scala b/src/test/scala/casing/TestUtils.scala similarity index 96% rename from src/test/scala/casing/utils.scala rename to src/test/scala/casing/TestUtils.scala index b3df3be..82e3ea7 100644 --- a/src/test/scala/casing/utils.scala +++ b/src/test/scala/casing/TestUtils.scala @@ -1,4 +1,4 @@ -package casing.test +package casing import minitest.api._