diff options
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/expectation.rs | 16 | ||||
-rw-r--r-- | macros/src/mock.rs | 27 |
2 files changed, 37 insertions, 6 deletions
diff --git a/macros/src/expectation.rs b/macros/src/expectation.rs index a6d181f..4095278 100644 --- a/macros/src/expectation.rs +++ b/macros/src/expectation.rs @@ -402,6 +402,22 @@ impl ToTokens for Expectation } } + impl #boundless_impl_generics #ident #ty_generics { + fn is_exhausted(&self) -> bool { + if let ::ridicule::__private::CallCountExpectation::Times(times) = + self.call_cnt_expectation + { + if times == self.call_cnt.load( + ::std::sync::atomic::Ordering::Relaxed + ) { + return true; + } + } + + false + } + } + impl #boundless_impl_generics Drop for #ident #ty_generics { fn drop(&mut self) { 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() }}) |