diff --git a/lib/scala/pkg/src/main/scala/org/enso/pkg/validation/NameValidation.scala b/lib/scala/pkg/src/main/scala/org/enso/pkg/validation/NameValidation.scala index 71d48812cb..4416186c4d 100644 --- a/lib/scala/pkg/src/main/scala/org/enso/pkg/validation/NameValidation.scala +++ b/lib/scala/pkg/src/main/scala/org/enso/pkg/validation/NameValidation.scala @@ -19,7 +19,8 @@ object NameValidation { else name val startingWithUppercase = starting.capitalize val onlyAlphanumeric = startingWithUppercase.filter(isAllowedNameCharacter) - toUpperSnakeCase(onlyAlphanumeric) + + onlyAlphanumeric } /** Validate the project name. @@ -39,8 +40,6 @@ object NameValidation { ListSet(invalidCharacters: _*) ) ) - } else if (name != toUpperSnakeCase(name)) { - Left(InvalidNameError.ShouldBeUpperSnakeCase(toUpperSnakeCase(name))) } else { Right(name) } @@ -54,33 +53,4 @@ object NameValidation { char.isLetterOrDigit || char == '_' } - /** Takes a name containing letters, digits, and `_` characters and makes it - * a proper `Upper_Snake_Case` name. - * - * @param string the input string - * @return the transformed string - */ - private def toUpperSnakeCase(string: String): String = { - val beginMarker = '#' - val chars = string.toList - val charPairs = (beginMarker :: chars).zip(chars) - charPairs - .map { case (previous, current) => - if (previous == beginMarker) { - current.toString - } else if (previous.isLower && current.isUpper) { - s"_$current" - } else if (previous.isLetter && current.isDigit) { - s"_$current" - } else if (previous == '_' && current == '_') { - "" - } else if (previous.isDigit && current.isLetter) { - s"_${current.toUpper}" - } else { - current.toString - } - } - .mkString("") - } - } diff --git a/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala b/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala index a4145f9bb1..3d57d12f40 100644 --- a/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala +++ b/lib/scala/pkg/src/test/scala/org/enso/pkg/ConfigSpec.scala @@ -55,10 +55,10 @@ class ConfigSpec } "only require the name and use defaults for everything else" in { - val parsed = Config.fromYaml("name: FooBar").get - parsed.name shouldEqual "FooBar" + val parsed = Config.fromYaml("name: fooBar").get + parsed.name shouldEqual "fooBar" parsed.normalizedName shouldEqual None - parsed.moduleName shouldEqual "Foo_Bar" + parsed.moduleName shouldEqual "FooBar" parsed.edition shouldBe empty } diff --git a/lib/scala/pkg/src/test/scala/org/enso/pkg/NameSanitizationSpec.scala b/lib/scala/pkg/src/test/scala/org/enso/pkg/NameSanitizationSpec.scala index d544e544fc..2ee77272c4 100644 --- a/lib/scala/pkg/src/test/scala/org/enso/pkg/NameSanitizationSpec.scala +++ b/lib/scala/pkg/src/test/scala/org/enso/pkg/NameSanitizationSpec.scala @@ -12,13 +12,14 @@ class NameSanitizationSpec extends AnyWordSpec with Matchers { "sanitize the name of the project" in { normalizeName("My_Project") shouldEqual "My_Project" - normalizeName("My___Project") shouldEqual "My_Project" - normalizeName("myProject") shouldEqual "My_Project" - normalizeName("myPro??^ject123") shouldEqual "My_Project_123" - normalizeName("???%$6543lib") shouldEqual "Project_6543_Lib" - normalizeName("MyProject™") shouldEqual "My_Project" + normalizeName("My___Project") shouldEqual "My___Project" + normalizeName("myProject") shouldEqual "MyProject" + normalizeName("myPro??^ject123") shouldEqual "MyProject123" + normalizeName("???%$6543lib") shouldEqual "Project_6543lib" + normalizeName("MyProject™") shouldEqual "MyProject" normalizeName("$$$$") shouldEqual "Project" normalizeName("$$42$$") shouldEqual "Project_42" + normalizeName("AoC_1") shouldEqual "AoC_1" normalizeName("\uD83D\uDE80") shouldEqual "Project" normalizeName("\uD83D\uDE80_\uD83D\uDE0A") shouldEqual "Project" normalizeName("\uD83D\uDE80_\uD83D\uDE0A__") shouldEqual "Project" @@ -29,12 +30,8 @@ class NameSanitizationSpec extends AnyWordSpec with Matchers { validateName("My") shouldEqual Right("My") validateName("My_Project") shouldEqual Right("My_Project") validateName("") shouldEqual Left(InvalidNameError.Empty) - validateName("My___Project") shouldEqual Left( - InvalidNameError.ShouldBeUpperSnakeCase("My_Project") - ) - validateName("FooBar") shouldEqual Left( - InvalidNameError.ShouldBeUpperSnakeCase("Foo_Bar") - ) + validateName("My___Project") shouldEqual Right("My___Project") + validateName("FooBar") shouldEqual Right("FooBar") validateName("myProject") shouldEqual Left( InvalidNameError.ShouldStartWithCapitalLetter )