Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(generator): use single underscore in kebab to snake case conversion #93

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

DavidLeeds
Copy link
Contributor

Addresses the case where "Kebab-Case" was converted to "kebab__case". After the change, we get "kebab_case".

issue: #88

Addresses the case where "Kebab-Case" was converted to
"kebab__case". After the change, we get "kebab_case".

issue: librasn#88
Copy link
Member

@6d7a 6d7a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DavidLeeds
Copy link
Contributor Author

DavidLeeds commented Mar 7, 2025

@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.

Copy link
Member

@6d7a 6d7a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, a valid fix indeed. Thank you and sorry for the confusion.

@6d7a 6d7a merged commit 4c4c019 into librasn:main Mar 7, 2025
1 check passed
@DavidLeeds DavidLeeds deleted the leeds/no-double-underscore branch March 8, 2025 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants