Skip to content

Commit

Permalink
Add missing underscores for PascalCase enum values #4837
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomameli authored and Renato Mameli committed May 7, 2024
1 parent dec8a43 commit 06eaab2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ public String toEnumVarName(String value, String datatype) {
}

// string
String var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT);
String var = underscore(value.replaceAll("\\W+", "_")).toUpperCase(Locale.ROOT);
if (var.matches("\\d.*")) {
var = "_" + var;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public void toEnumVarNameShouldNotResultInSingleUnderscore() throws Exception {
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("==", "String"), "u");
}

@Test
public void toEnumVarNameAddUnderscoresIfValueIsPascalCase() {
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("OnlyCamelCase", "String"), "ONLY_CAMEL_CASE");
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("WithNumber1", "String"), "WITH_NUMBER1");
Assert.assertEquals(fakeJavaCodegen.toEnumVarName("_LeadingUnderscore", "String"), "_LEADING_UNDERSCORE");
}

@Test
public void toVarNameShouldAvoidOverloadingGetClassMethod() throws Exception {
Assert.assertEquals(fakeJavaCodegen.toVarName("class"), "propertyClass");
Expand Down

0 comments on commit 06eaab2

Please sign in to comment.