Skip to content

Commit

Permalink
chore: clean up test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Apr 24, 2024
1 parent aef38fa commit 0808fdf
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,18 @@ mod tests {
use super::*;

#[test]
fn single_borrow_and_modify() {
fn borrow_mut_modify_and_borrow_after_drop() {
let cell = OwnedRefCell::new(10);
{
let mut b = cell.borrow_mut();
*b = 20;
}
{
let b = cell.borrow();
assert_eq!(*b, 20);
}
let b = cell.borrow();
assert_eq!(*b, 20);
}

#[test]
fn cannot_borrow_mut_while_immutable_borrowed() {
fn cannot_borrow_mut_while_immutably_borrowed() {
let cell = OwnedRefCell::new(10);
let _b = cell.borrow();
assert!(cell.try_borrow_mut().is_none());
Expand All @@ -218,33 +216,23 @@ mod tests {
}

#[test]
fn multiple_immutable_borrows() {
fn cannot_borrow_mut_while_mutably_borrowed() {
let cell = OwnedRefCell::new(10);
let b1 = cell.try_borrow().unwrap();
let b2 = cell.try_borrow().unwrap();
assert_eq!(*b1, 10);
assert_eq!(*b2, 10);
}

#[test]
fn mixed_borrows_fail() {
let cell = OwnedRefCell::new(10);
let _b1 = cell.borrow();
let _b = cell.borrow_mut();
assert!(cell.try_borrow_mut().is_none());
}

#[test]
fn reuse_after_drop() {
fn multiple_immutable_borrows() {
let cell = OwnedRefCell::new(10);
{
let _b1 = cell.borrow_mut();
}
let b2 = cell.borrow();
let b1 = cell.try_borrow().unwrap();
let b2 = cell.try_borrow().unwrap();
assert_eq!(*b1, 10);
assert_eq!(*b2, 10);
}

#[test]
fn multiple_borrows_after_mut_borrow() {
fn multiple_immutable_borrows_after_borrow_mut() {
let cell = OwnedRefCell::new(10);
{
let _b1 = cell.borrow_mut();
Expand All @@ -256,17 +244,18 @@ mod tests {
}

#[test]
fn borrow_fail_after_borrow_mut() {
let cell = OwnedRefCell::new(30);
fn borrow_mut_again_after_drop() {
let cell = OwnedRefCell::new(10);
{
let mut b1 = cell.borrow_mut();
*b1 = 40;
let mut b = cell.borrow_mut();
*b = 20;
}
assert!(cell.try_borrow_mut().is_some());
{
let b2 = cell.borrow();
assert_eq!(*b2, 40);
let mut b = cell.borrow_mut();
*b = 30;
}
let b = cell.borrow();
assert_eq!(*b, 30);
}

#[test]
Expand Down

0 comments on commit 0808fdf

Please sign in to comment.