Skip to content

Commit

Permalink
Add one more test for cell assign
Browse files Browse the repository at this point in the history
  • Loading branch information
avl committed Aug 18, 2024
1 parent b3ea6f2 commit 55f6fff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arcshift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ impl<T: 'static> ArcShiftCell<T> {
/// This method is very fast, basically the speed of a regular reference, unless
/// the value has been modified by calling one of the update-methods.
///
/// This method will drop older values which are no longer needed
/// This method will do a reload (drop older values which are no longer needed).
/// This method is reentrant - you are allowed to call it from within the closure 'f'.
/// However, only the outermost invocation will cause a reload.
pub fn get(&self, f: impl FnOnce(&T)) {
self.recursion.set(self.recursion.get() + 1);
let val = if self.recursion.get() == 1 {
Expand Down
18 changes: 18 additions & 0 deletions arcshift/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,25 @@ fn simple_cell_recursion() {
owner.validate();
});
}
#[test]
fn simple_cell_assign() {
model(|| {
let owner = SpyOwner2::new();
{
let cell = ArcShiftCell::new(owner.create("original"));
let new_value = ArcShift::new(owner.create("new"));

cell.get(|val| {
assert_eq!(val.str(), "original");
assert!(cell.assign(&ArcShift::new(owner.create("dummy"))).is_err());
});

cell.assign(&new_value).unwrap();

cell.get(|val| assert_eq!(val.str(), "new"));
}
});
}
#[test]
fn simple_rcu() {
model(|| {
Expand Down

0 comments on commit 55f6fff

Please sign in to comment.