Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Nov 29, 2022
1 parent 850cc93 commit 79501bc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/once_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,21 @@ mod tests {
assert_eq!(dict.get_item(foo3).unwrap().extract::<usize>().unwrap(), 42);
});
}

#[test]
fn test_once_cell() {
Python::with_gil(|py| {
let cell = GILOnceCell::new();

assert!(cell.get(py).is_none());

assert_eq!(cell.get_or_try_init(py, || Err(5)), Err(5));
assert!(cell.get(py).is_none());

assert_eq!(cell.get_or_try_init(py, || Ok::<_, ()>(2)), Ok(&2));
assert_eq!(cell.get(py), Some(&2));

assert_eq!(cell.get_or_try_init(py, || Err(5)), Ok(&2));
})
}
}

0 comments on commit 79501bc

Please sign in to comment.