summaryrefslogtreecommitdiff
path: root/macros/src/mock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/mock.rs')
-rw-r--r--macros/src/mock.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/macros/src/mock.rs b/macros/src/mock.rs
index 2ac27e5..9aa03f4 100644
--- a/macros/src/mock.rs
+++ b/macros/src/mock.rs
@@ -144,7 +144,8 @@ impl ToTokens for Mock
{
Self {
#(
- #expectations_field_idents: ::std::collections::HashMap::new()
+ #expectations_field_idents:
+ ::std::collections::HashMap::new()
),*
}
}
@@ -182,7 +183,7 @@ impl ToTokens for ExpectationsField
quote! {
#field_ident: ::std::collections::HashMap<
Vec<::ridicule::__private::type_id::TypeID>,
- #expectation_ident<#(#generic_args),*>
+ ::std::collections::VecDeque<#expectation_ident<#(#generic_args),*>>
>
}
.to_tokens(tokens);
@@ -238,12 +239,21 @@ fn create_mock_function(
#(::ridicule::__private::type_id::TypeID::of::<#type_param_idents>()),*
];
- let expectation = self
+ let func_expectations = self
.#expectations_field
.get(&ids)
.expect(concat!(
"No expectation found for function ",
stringify!(#func_ident)
+ ));
+
+ let expectation = func_expectations
+ .iter()
+ .skip_while(|expectation| expectation.is_exhausted())
+ .next()
+ .expect(concat!(
+ "No expectation found for function ",
+ stringify!(#func_ident)
))
.with_generic_params::<#(#type_param_idents,)*>();
@@ -318,10 +328,15 @@ fn create_expect_function(
#expectation::<#(#type_param_idents),*>::new()
.strip_generic_params();
- self.#expectations_field.insert(ids.clone(), expectation);
+ let func_expectations = self
+ .#expectations_field
+ .entry(ids.clone())
+ .or_insert_with(::std::collections::VecDeque::new);
+
+ func_expectations.push_back(expectation);
- self.#expectations_field
- .get_mut(&ids)
+ func_expectations
+ .back_mut()
.unwrap()
.with_generic_params_mut()
}})