diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-25 11:58:16 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-25 11:58:16 +0100 |
commit | aef63bfecb7731c0307cc65eab0b9a06b8a7363d (patch) | |
tree | 8455d54be4fd4008ac593fae5e9e9608198a61b5 /macros/src/mock.rs | |
parent | 96a13690f8552386bb183ebc01418774047ebbfc (diff) |
feat: add argument matching
Diffstat (limited to 'macros/src/mock.rs')
-rw-r--r-- | macros/src/mock.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/macros/src/mock.rs b/macros/src/mock.rs index 9aa03f4..4d040a9 100644 --- a/macros/src/mock.rs +++ b/macros/src/mock.rs @@ -226,6 +226,22 @@ fn create_mock_function( }) .collect::<Vec<_>>(); + let typed_args = item_method + .sig + .inputs + .iter() + .filter_map(|fn_arg| match fn_arg { + FnArg::Typed(arg) => { + let Pat::Ident(pat_ident) = arg.pat.as_ref() else { + return None; + }; + + Some(pat_ident.ident.clone()) + } + FnArg::Receiver(_) => None, + }) + .collect::<Vec<_>>(); + let expectations_field = format_ident!("{func_ident}_expectations"); ImplItemMethod { @@ -257,6 +273,8 @@ fn create_mock_function( )) .with_generic_params::<#(#type_param_idents,)*>(); + expectation.check_predicates(#(&#typed_args),*); + (expectation.get_returning())(#(#args),*) } }) |