diff options
Diffstat (limited to 'src/collection/boxed.rs')
| -rw-r--r-- | src/collection/boxed.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs index b0d1e3b..c359098 100644 --- a/src/collection/boxed.rs +++ b/src/collection/boxed.rs @@ -532,3 +532,37 @@ where self.into_iter() } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::{Mutex, ThreadKey}; + + #[test] + fn non_duplicates_allowed() { + let mutex1 = Mutex::new(0); + let mutex2 = Mutex::new(1); + assert!(BoxedLockCollection::try_new([&mutex1, &mutex2]).is_some()) + } + + #[test] + fn duplicates_not_allowed() { + let mutex1 = Mutex::new(0); + assert!(BoxedLockCollection::try_new([&mutex1, &mutex1]).is_none()) + } + + #[test] + fn works_in_collection() { + let key = ThreadKey::get().unwrap(); + let mutex1 = Mutex::new(0); + let mutex2 = Mutex::new(1); + let collection = + BoxedLockCollection::try_new(BoxedLockCollection::try_new([&mutex1, &mutex2]).unwrap()) + .unwrap(); + + let guard = collection.lock(key); + assert!(mutex1.is_locked()); + assert!(mutex2.is_locked()); + drop(guard); + } +} |
