Skip to content

Commit

Permalink
fix: handle raw identifier struct field (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt authored Apr 1, 2022
1 parent 619e8b5 commit be5ead2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 55 deletions.
70 changes: 17 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion safe-builder-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ proc-macro = true
[dependencies]
quote = "^1.0"
proc-quote = "0.3.2"
syn = "^1.0"
syn = { version = "^1.0", features = ["parsing"] }
proc-macro2 = "^1.0"
convert_case = "^0.4.0"
3 changes: 2 additions & 1 deletion safe-builder-derive/src/expander.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use convert_case::*;
use quote::*;
use syn::*;
use syn::ext::IdentExt;

fn create_field_type(ident: &Ident) -> Ident {
let name = ident.to_string().to_case(Case::Pascal);
let name = ident.unraw().to_string().to_case(Case::Pascal);
format_ident!("{}Type", name)
}

Expand Down
20 changes: 20 additions & 0 deletions safe-builder/tests/all/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,24 @@ mod tests {
foo
)
}

#[derive(Builder, PartialEq, Debug)]
pub struct RawIdentifier {
id: String,
r#type: String,
}
#[test]
fn raw_identifier_test() {
let raw_ident = RawIdentifier::builder()
.id("1234".to_owned())
.r#type("type".to_owned())
.build();
assert_eq!(
RawIdentifier {
id: "1234".to_owned(),
r#type: "type".to_owned(),
},
raw_ident
)
}
}

0 comments on commit be5ead2

Please sign in to comment.