Skip to content

Commit

Permalink
Merge pull request #93 from DavidLeeds/leeds/no-double-underscore
Browse files Browse the repository at this point in the history
fix(generator): use single underscore in kebab to snake case conversion
  • Loading branch information
6d7a authored Mar 7, 2025
2 parents c8218df + 6e9d195 commit 4c4c019
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 6 additions & 6 deletions rasn-compiler-tests/tests/parameterization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ e2e_pdu! {
#[non_exhaustive]
pub struct A2XPC5FlowBitRates {
#[rasn(identifier = "a2X-GuaranteedFlowBitRate")]
pub a2_x__guaranteed_flow_bit_rate: bool,
pub a2_x_guaranteed_flow_bit_rate: bool,
#[rasn(identifier = "iE-Extensions")]
pub i_e__extensions: Option<A2XPC5FlowBitRatesIEExtensions>,
pub i_e_extensions: Option<A2XPC5FlowBitRatesIEExtensions>,
}
impl A2XPC5FlowBitRates {
pub fn new(
a2_x__guaranteed_flow_bit_rate: bool,
i_e__extensions: Option<A2XPC5FlowBitRatesIEExtensions>,
a2_x_guaranteed_flow_bit_rate: bool,
i_e_extensions: Option<A2XPC5FlowBitRatesIEExtensions>,
) -> Self {
Self {
a2_x__guaranteed_flow_bit_rate,
i_e__extensions,
a2_x_guaranteed_flow_bit_rate,
i_e_extensions,
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions rasn-compiler/src/generator/rasn/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ impl Rasn {
while let Some(c) = peekable.next() {
if c.is_lowercase() || c == '_' || c.is_numeric() {
lowercase.push(c);
if peekable.peek().map_or(false, |next| next.is_uppercase()) {
if c != '_' && peekable.peek().map_or(false, |next| next.is_uppercase()) {
lowercase.push('_');
}
} else {
Expand Down Expand Up @@ -1140,10 +1140,7 @@ impl Rasn {
let input = input.drain(..).fold(String::new(), |mut acc, c| {
if acc.is_empty() && c.is_lowercase() {
acc.push(c.to_ascii_uppercase());
} else if acc.ends_with(|last: char| last == '_') && c.is_uppercase() {
acc.pop();
acc.push(c);
} else if acc.ends_with(|last: char| last == '_') {
} else if acc.ends_with('_') {
acc.pop();
acc.push(c.to_ascii_uppercase());
} else {
Expand Down Expand Up @@ -1499,7 +1496,7 @@ is_recursive: false,
assert_eq!(generator.to_rust_snake_case("hello-world"), "hello_world");
assert_eq!(generator.to_rust_snake_case("HELLOWORLD"), "helloworld");
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("HELLO-WORLD"), "hello_world");
assert_eq!(generator.to_rust_snake_case("struct"), "r_struct");
assert_eq!(generator.to_rust_snake_case("STRUCT"), "r_struct");
}
Expand Down

0 comments on commit 4c4c019

Please sign in to comment.