Created
June 21, 2018 18:22
-
-
Save CodeSandwich/e2b600a9bef58b1d52626f35e60426ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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