diff options
| author | Mica White <botahamec@gmail.com> | 2024-12-01 15:28:44 -0500 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-12-01 15:29:19 -0500 |
| commit | 48aaedad542b9c6cbdc85d22517cd0d151f38443 (patch) | |
| tree | b5b197c47476e88b9926852c73a84f24b6497c77 /src/collection/boxed.rs | |
| parent | 0140f58043a2a00312d31907253cc718985e1e6c (diff) | |
Unit testing
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); + } +} |
