Skip to content

Commit

Permalink
Fix to use $crate in path macros (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya authored Sep 6, 2023
1 parent 84f10f4 commit 688564d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/struct_path_macro.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#[macro_export]
macro_rules! path {
($($x:tt)*) => {{
struct_path::path!($($x)*).to_string()
$crate::struct_path::path!($($x)*).to_string()
}};
}

#[macro_export]
macro_rules! paths {
($($x:tt)*) => {{
struct_path::paths!($($x)*).iter().map(|s| s.to_string()).collect::<Vec<String>>()
$crate::struct_path::paths!($($x)*).iter().map(|s| s.to_string()).collect::<Vec<String>>()
}};
}

#[macro_export]
macro_rules! path_camel_case {
($($x:tt)*) => {{
struct_path::path!($($x)*;case="camel").to_string()
$crate::struct_path::path!($($x)*;case="camel").to_string()
}};
}

#[macro_export]
macro_rules! paths_camel_case {
($($x:tt)*) => {{
struct_path::paths!($($x)*;case="camel").into_iter().map(|s| s.to_string()).collect::<Vec<String>>()
$crate::struct_path::paths!($($x)*;case="camel").into_iter().map(|s| s.to_string()).collect::<Vec<String>>()
}}
}
50 changes: 50 additions & 0 deletions tests/macro_path_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#[test]
fn test_ambiguous_path_macro() {
struct MyTestStructure {
some_id: String,
some_num: u64,
}
assert_eq!(firestore::path!(MyTestStructure::some_id), "some_id");
assert_eq!(
firestore::paths!(MyTestStructure::{some_id, some_num}),
vec!["some_id".to_string(), "some_num".to_string()]
);
assert_eq!(
firestore::path_camel_case!(MyTestStructure::some_id),
"someId"
);
assert_eq!(
firestore::paths_camel_case!(MyTestStructure::{some_id, some_num}),
vec!["someId".to_string(), "someNum".to_string()]
);
}

mod struct_path {
#[macro_export]
macro_rules! path {
() => {
unreachable!()
};
}

#[macro_export]
macro_rules! paths {
($($x:tt)*) => {{
unreachable!()
}};
}

#[macro_export]
macro_rules! path_camel_case {
($($x:tt)*) => {{
unreachable!()
}};
}

#[macro_export]
macro_rules! paths_camel_case {
($($x:tt)*) => {{
unreachable!()
}};
}
}

0 comments on commit 688564d

Please sign in to comment.