Skip to content

Instantly share code, notes, and snippets.

@CodeSandwich
Created June 21, 2018 18:22
Show Gist options
  • Save CodeSandwich/e2b600a9bef58b1d52626f35e60426ae to your computer and use it in GitHub Desktop.
Save CodeSandwich/e2b600a9bef58b1d52626f35e60426ae to your computer and use it in GitHub Desktop.
#![cfg_attr(test, feature(proc_macro, proc_macro_mod))]
#[cfg(test)]
extern crate mocktopus;
#[cfg(test)]
use mocktopus::macros::*;
#[cfg(test)]
use mocktopus::mocking::*;
pub struct Node<'a>(Option<&'a Node<'a>>);
#[cfg_attr(test, mockable)]
impl<'a> Node<'a> {
pub fn call_next(&self) {
match self.0 {
Some(node) => node.call_next(),
None => (),
}
}
}
#[test]
fn it_works() {
let mut call_count = 0;
let inner = Node(None);
let node = Node(Some(&inner));
unsafe {
Node::call_next.mock_raw(|node| {
if ::std::ptr::eq(node, &inner) {
call_count += 1;
};
MockResult::Continue((node,))
})
}
node.call_next();
assert_eq!(1, call_count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment