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/key.rs | |
| parent | 0140f58043a2a00312d31907253cc718985e1e6c (diff) | |
Unit testing
Diffstat (limited to 'src/key.rs')
| -rw-r--r-- | src/key.rs | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -83,7 +83,7 @@ impl ThreadKey { } /// A dumb lock that's just a wrapper for an [`AtomicBool`]. -#[derive(Debug, Default)] +#[derive(Default)] struct KeyCell { is_locked: Cell<bool>, } @@ -101,3 +101,26 @@ impl KeyCell { self.is_locked.set(false); } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn thread_key_returns_some_on_first_call() { + assert!(ThreadKey::get().is_some()); + } + + #[test] + fn thread_key_returns_none_on_second_call() { + let key = ThreadKey::get(); + assert!(ThreadKey::get().is_none()); + drop(key); + } + + #[test] + fn dropping_thread_key_allows_reobtaining() { + drop(ThreadKey::get()); + assert!(ThreadKey::get().is_some()) + } +} |
