From fd5b6786d29d056ff0721a59435b50005f13f05c Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 9 Oct 2022 20:41:09 +0200 Subject: test: add more unit tests --- src/castable_factory/blocking.rs | 23 +++++++++++++++++++++++ src/castable_factory/threadsafe.rs | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'src/castable_factory') diff --git a/src/castable_factory/blocking.rs b/src/castable_factory/blocking.rs index 5ff4db0..5dc12e5 100644 --- a/src/castable_factory/blocking.rs +++ b/src/castable_factory/blocking.rs @@ -72,3 +72,26 @@ where ReturnInterface: 'static + ?Sized, { } + +#[cfg(test)] +mod tests +{ + use super::*; + + #[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(27); + + assert_eq!(output, Box::new(Bacon { heal_amount: 27 })); + } +} diff --git a/src/castable_factory/threadsafe.rs b/src/castable_factory/threadsafe.rs index 08c5ecf..84e15b9 100644 --- a/src/castable_factory/threadsafe.rs +++ b/src/castable_factory/threadsafe.rs @@ -85,3 +85,27 @@ where ReturnInterface: 'static + ?Sized, { } + +#[cfg(test)] +mod tests +{ + use super::*; + + #[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(27); + + assert_eq!(output, Box::new(Bacon { heal_amount: 27 })); + } +} -- cgit v1.2.3-18-g5258