summaryrefslogtreecommitdiffstats
path: root/vendor/once_cell/tests/it.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/once_cell/tests/it.rs')
-rw-r--r--vendor/once_cell/tests/it.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/once_cell/tests/it.rs b/vendor/once_cell/tests/it.rs
index 476f14bb0..410b93b64 100644
--- a/vendor/once_cell/tests/it.rs
+++ b/vendor/once_cell/tests/it.rs
@@ -138,6 +138,41 @@ mod unsync {
}
#[test]
+ fn lazy_force_mut() {
+ let called = Cell::new(0);
+ let mut x = Lazy::new(|| {
+ called.set(called.get() + 1);
+ 92
+ });
+ assert_eq!(called.get(), 0);
+ let v = Lazy::force_mut(&mut x);
+ assert_eq!(called.get(), 1);
+
+ *v /= 2;
+ assert_eq!(*x, 46);
+ assert_eq!(called.get(), 1);
+ }
+
+ #[test]
+ fn lazy_get_mut() {
+ let called = Cell::new(0);
+ let mut x: Lazy<u32, _> = Lazy::new(|| {
+ called.set(called.get() + 1);
+ 92
+ });
+
+ assert_eq!(called.get(), 0);
+ assert_eq!(*x, 92);
+
+ let mut_ref: &mut u32 = Lazy::get_mut(&mut x).unwrap();
+ assert_eq!(called.get(), 1);
+
+ *mut_ref /= 2;
+ assert_eq!(*x, 46);
+ assert_eq!(called.get(), 1);
+ }
+
+ #[test]
fn lazy_default() {
static CALLED: AtomicUsize = AtomicUsize::new(0);