fix(generator): use single underscore in kebab to snake case conversion#93
fix(generator): use single underscore in kebab to snake case conversion#936d7a merged 1 commit intolibrasn:mainfrom DavidLeeds:leeds/no-double-underscore
Conversation
Addresses the case where "Kebab-Case" was converted to "kebab__case". After the change, we get "kebab_case". issue: #88
6d7a
left a comment
There was a problem hiding this comment.
Unfortunately, this can lead to problematic edge cases. Consider the hypothetical ASN.1 type:
TestType ::= SEQUENCE {
doner-kebab BOOLEAN,
doner_kebab INTEGER
}
If we do not have a name transformation that retains distinction between - and _, the bindings for the type above will not compile. However, given that this is such an outrageously exotic edge case, I'd be up for introducing a config parameter to the Rasn backend, so that the user can decide how to handle name transformation.
|
@6d7a this is a valid concern, but I noted that the snake case conversion already makes no guarantees that the output will be unique for similar inputs. The following four existing test cases output the same result: assert_eq!(generator.to_rust_snake_case("HelloWorld"), "hello_world");
assert_eq!(generator.to_rust_snake_case("helloWorld"), "hello_world");
assert_eq!(generator.to_rust_snake_case("hello-world"), "hello_world");
assert_eq!(generator.to_rust_snake_case("HelloWORLD"), "hello_world");My change simply makes the outlier case consistent with the established behavior. If schemas are using minor whitespace and punctuation changes to differentiate definitions, perhaps the code generator will be the forcing function to drive more responsible naming decisions. |
6d7a
left a comment
There was a problem hiding this comment.
My bad, a valid fix indeed. Thank you and sorry for the confusion.
Extends to_rust_snake_case() to detect acronym-end boundaries when an uppercase letter is followed by a lowercase letter and preceded by another uppercase letter. This correctly handles acronym-prefixed names: PEDefinitions -> pe_definitions (was: pedefinitions) SGP32Definitions -> sgp32_definitions (was: sgp32definitions) RSPDefinitions -> rsp_definitions (was: rspdefinitions) EUICCInfo1 -> euicc_info1 (was: euiccinfo1) Extends the fix from PR librasn#93 (librasn#88) which handled double-underscores in kebab-case names but missed acronym boundaries.
Addresses the case where "Kebab-Case" was converted to "kebab__case". After the change, we get "kebab_case".
issue: #88