Skip to content

Commit

Permalink
Fix extra underscore when snake case is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kzwang committed Dec 3, 2024
1 parent 2603477 commit be13628
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ object CodeGeneratorUtils {
if (type == Character.LOWERCASE_LETTER.toInt() && currentType == Character.UPPERCASE_LETTER.toInt()) {
val newTokenStart = pos - 1
if (newTokenStart != tokenStart) {
list.add(String(c, tokenStart, newTokenStart - tokenStart))
val part = String(c, tokenStart, newTokenStart - tokenStart)
if (part != "_") {
list.add(part)
}
tokenStart = newTokenStart
}
} else {
list.add(String(c, tokenStart, pos - tokenStart))
val part = String(c, tokenStart, pos - tokenStart)
if (part != "_") {
list.add(part)
}
tokenStart = pos
}
currentType = type
}
list.add(String(c, tokenStart, c.size - tokenStart))
val part = String(c, tokenStart, c.size - tokenStart)
if (part != "_") {
list.add(part)
}
return list.toTypedArray()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2037,8 +2037,9 @@ class CodeGenTest {
assertThat(type.typeSpecs[0].fieldSpecs).extracting("name").containsExactly("TYPE_NAME", "People", "Friends")
}

@Test
fun generateConstantsForQueryInputArguments() {
@ParameterizedTest
@ValueSource(booleans = [true, false])
fun generateConstantsForQueryInputArguments(snakeCaseEnabled: Boolean) {
val schema = """
type Query {
shows(titleFilter: String,moveFilter: MovieFilter): [Show]
Expand All @@ -2059,11 +2060,13 @@ class CodeGenTest {
val result = CodeGen(
CodeGenConfig(
schemas = setOf(schema),
packageName = basePackageName
packageName = basePackageName,
snakeCaseConstantNames = snakeCaseEnabled
)
).generate()
val type = result.javaConstants[0].typeSpec
assertThat(type.typeSpecs).extracting("name").containsExactly("QUERY", "SHOW", "MOVIEFILTER")
val movieFilterName = if (snakeCaseEnabled) "MOVIE_FILTER" else "MOVIEFILTER"
assertThat(type.typeSpecs).extracting("name").containsExactly("QUERY", "SHOW", movieFilterName)
assertThat(type.typeSpecs[0].typeSpecs).extracting("name").containsExactly("SHOWS_INPUT_ARGUMENT")
assertThat(type.typeSpecs[0].typeSpecs[0].fieldSpecs).extracting("name")
.containsExactly("TitleFilter", "MoveFilter")
Expand Down

0 comments on commit be13628

Please sign in to comment.