From 280a61ad7b74019c7aad8b7306a0dd7cfb11359c Mon Sep 17 00:00:00 2001 From: Botahamec Date: Sun, 12 Jan 2025 15:04:01 -0500 Subject: More unit tests --- src/poisonable.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/poisonable.rs') diff --git a/src/poisonable.rs b/src/poisonable.rs index da7758f..e577ce9 100644 --- a/src/poisonable.rs +++ b/src/poisonable.rs @@ -96,7 +96,7 @@ pub type TryLockPoisonableResult<'flag, 'key, G, Key> = mod tests { use super::*; use crate::lockable::Lockable; - use crate::{Mutex, ThreadKey}; + use crate::{LockCollection, Mutex, ThreadKey}; #[test] fn display_works() { @@ -108,6 +108,24 @@ mod tests { assert_eq!(guard.to_string(), "Hello, world!"); } + #[test] + fn ord_works() { + let key = ThreadKey::get().unwrap(); + let lock1 = Poisonable::new(Mutex::new(1)); + let lock2 = Poisonable::new(Mutex::new(3)); + let lock3 = Poisonable::new(Mutex::new(3)); + let collection = LockCollection::try_new((&lock1, &lock2, &lock3)).unwrap(); + + let guard = collection.lock(key); + let guard1 = guard.0.as_ref().unwrap(); + let guard2 = guard.1.as_ref().unwrap(); + let guard3 = guard.2.as_ref().unwrap(); + assert!(guard1 < guard2); + assert!(guard2 > guard1); + assert!(guard2 == guard3); + assert!(guard1 != guard3); + } + #[test] fn get_ptrs() { let mutex = Mutex::new(5); @@ -118,4 +136,10 @@ mod tests { assert_eq!(lock_ptrs.len(), 1); assert!(std::ptr::addr_eq(lock_ptrs[0], &poisonable.inner)); } + + #[test] + fn new_poisonable_is_not_poisoned() { + let mutex = Poisonable::new(Mutex::new(42)); + assert!(!mutex.is_poisoned()); + } } -- cgit v1.2.3