mirror of
https://github.com/enso-org/enso.git
synced 2024-12-27 18:54:03 +03:00
Do not change project module name to Upper_Snake_Case (#8697)
close #8649 Do not mangle the project module name. Only strip the unsupported characters and make it a valid Enso module identifier.
This commit is contained in:
parent
4b19da4835
commit
5e0a7337d0
@ -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("")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user