blob: 82675e6fdb8cf0cd19b0bd3276a3b6662b12408c [file] [log] [blame]
// vim: tw=80
#![deny(warnings)]
use mockall::*;
#[derive(Clone)]
struct NonCopy(u32);
// A struct with a definition like this:
// pub struct ExtGenericStruct<T: Clone> {
// _x: i16
// }
// impl<T: Clone> ExtGenericStruct<T> {
// fn foo(&self, _x: T) -> T {
// 42
// }
// }
// Could be mocked like this:
mock!{
pub ExtGenericStruct<T: Clone + 'static> {
fn foo(&self, x: T) -> T;
}
}
#[test]
#[allow(clippy::redundant_clone)]
fn returning() {
let mut mock = MockExtGenericStruct::<NonCopy>::new();
// An explicit .clone() is required so as not to return by move
mock.expect_foo()
.returning(|x| x.clone());
assert_eq!(5, mock.foo(NonCopy(5)).0);
}