Skip to content

Commit

Permalink
Added force_mut and get_mut tests to it.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielSanchezQ committed Sep 1, 2022
1 parent c35d46d commit f3b9cf8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/it.rs
Expand Up @@ -137,6 +137,44 @@ mod unsync {
assert_eq!(called.get(), 1);
}

#[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);
Lazy::force_mut(&mut x);
assert_eq!(called.get(), 1);

let y = *x - 30;
assert_eq!(y, 62);
assert_eq!(called.get(), 1);

*x /= 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);
Expand Down

0 comments on commit f3b9cf8

Please sign in to comment.