diff options
Diffstat (limited to 'macros/src/mock_input.rs')
-rw-r--r-- | macros/src/mock_input.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/macros/src/mock_input.rs b/macros/src/mock_input.rs new file mode 100644 index 0000000..379c342 --- /dev/null +++ b/macros/src/mock_input.rs @@ -0,0 +1,51 @@ +use syn::parse::{Parse, ParseStream}; +use syn::{braced, Ident, Token, TraitItem, TypePath, WhereClause}; + +pub struct MockInput +{ + pub mock: Ident, + pub mocked_trait: TypePath, + pub items: Vec<TraitItem>, +} + +impl Parse for MockInput +{ + fn parse(input: ParseStream) -> Result<Self, syn::Error> + { + let mock = input.parse()?; + + let _generics = input.parse::<Option<WhereClause>>()?; + + let _braced_content; + + let _brace = braced!(_braced_content in input); + + input.parse::<Token![impl]>()?; + + let mocked_trait = input.parse()?; + + input.parse::<Token![for]>()?; + + let impl_target = input.parse::<Ident>()?; + + if impl_target != mock { + return Err(input.error("Expected this to be the mock")); + } + + let content; + + braced!(content in input); + + let mut items = Vec::new(); + + while !content.is_empty() { + items.push(content.parse()?); + } + + Ok(Self { + mock, + mocked_trait, + items, + }) + } +} |