summaryrefslogtreecommitdiff
path: root/src/key.rs
diff options
context:
space:
mode:
authorMica White <botahamec@gmail.com>2024-12-01 15:28:44 -0500
committerMica White <botahamec@gmail.com>2024-12-01 15:29:19 -0500
commit48aaedad542b9c6cbdc85d22517cd0d151f38443 (patch)
treeb5b197c47476e88b9926852c73a84f24b6497c77 /src/key.rs
parent0140f58043a2a00312d31907253cc718985e1e6c (diff)
Unit testing
Diffstat (limited to 'src/key.rs')
-rw-r--r--src/key.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/key.rs b/src/key.rs
index 8d46817..654979d 100644
--- a/src/key.rs
+++ b/src/key.rs
@@ -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())
+ }
+}