diff options
Diffstat (limited to 'src/castable_factory')
-rw-r--r-- | src/castable_factory/blocking.rs | 36 | ||||
-rw-r--r-- | src/castable_factory/threadsafe.rs | 38 |
2 files changed, 60 insertions, 14 deletions
diff --git a/src/castable_factory/blocking.rs b/src/castable_factory/blocking.rs index 5dc12e5..9ef9864 100644 --- a/src/castable_factory/blocking.rs +++ b/src/castable_factory/blocking.rs @@ -78,20 +78,42 @@ mod tests { use super::*; + #[derive(Debug, PartialEq, Eq)] + struct Bacon + { + heal_amount: u32, + } + #[test] fn can_call() { - #[derive(Debug, PartialEq, Eq)] - struct Bacon - { - heal_amount: u32, - } + let castable_factory = + CastableFactory::new(&|heal_amount| TransientPtr::new(Bacon { heal_amount })); + let output = castable_factory.call((27,)); + + assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 27 })); + } + + #[test] + fn can_call_mut() + { + let mut castable_factory = + CastableFactory::new(&|heal_amount| TransientPtr::new(Bacon { heal_amount })); + + let output = castable_factory.call_mut((103,)); + + assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 103 })); + } + + #[test] + fn can_call_once() + { let castable_factory = CastableFactory::new(&|heal_amount| TransientPtr::new(Bacon { heal_amount })); - let output = castable_factory(27); + let output = castable_factory.call_once((19,)); - assert_eq!(output, Box::new(Bacon { heal_amount: 27 })); + assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 19 })); } } diff --git a/src/castable_factory/threadsafe.rs b/src/castable_factory/threadsafe.rs index 84e15b9..8f9c072 100644 --- a/src/castable_factory/threadsafe.rs +++ b/src/castable_factory/threadsafe.rs @@ -91,21 +91,45 @@ mod tests { use super::*; + #[derive(Debug, PartialEq, Eq)] + struct Bacon + { + heal_amount: u32, + } + #[test] fn can_call() { - #[derive(Debug, PartialEq, Eq)] - struct Bacon - { - heal_amount: u32, - } + let castable_factory = ThreadsafeCastableFactory::new(&|heal_amount| { + TransientPtr::new(Bacon { heal_amount }) + }); + + let output = castable_factory.call((27,)); + assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 27 })); + } + + #[test] + fn can_call_mut() + { + let mut castable_factory = ThreadsafeCastableFactory::new(&|heal_amount| { + TransientPtr::new(Bacon { heal_amount }) + }); + + let output = castable_factory.call_mut((1092,)); + + assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 1092 })); + } + + #[test] + fn can_call_once() + { let castable_factory = ThreadsafeCastableFactory::new(&|heal_amount| { TransientPtr::new(Bacon { heal_amount }) }); - let output = castable_factory(27); + let output = castable_factory.call_once((547,)); - assert_eq!(output, Box::new(Bacon { heal_amount: 27 })); + assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 547 })); } } |