diff options
author | HampusM <hampus@hampusmat.com> | 2022-10-24 21:30:52 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-10-24 21:32:19 +0200 |
commit | 17fb8ef17d140db1dc887220113f18e6fde79bef (patch) | |
tree | 332b679b99df521cc8a0ca0e2f28383a186cfdb7 /src/castable_factory/threadsafe.rs | |
parent | dcc7c8877813b452392e49ffc4e5b1df08b40487 (diff) |
test: add castable factory unit tests
Diffstat (limited to 'src/castable_factory/threadsafe.rs')
-rw-r--r-- | src/castable_factory/threadsafe.rs | 38 |
1 files changed, 31 insertions, 7 deletions
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 })); } } |