Skip to content

Commit

Permalink
Add one more test for the assign-function
Browse files Browse the repository at this point in the history
  • Loading branch information
avl committed Aug 18, 2024
1 parent 375e886 commit b3ea6f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions arcshift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,11 @@ impl<T: 'static> ArcShiftCell<T> {

/// Assign the given ArcShift to this instance.
/// This does not copy the value T, it replaces the ArcShift instance of Self
/// with a clone of 'other'.
/// with a clone of 'other'. It does not clone T, only the ArcShift holding it.
///
/// This returns Err if recursion is detected, and has no effect in this case.
/// Recursion occurs if 'assign' is called from within the closure supplied to
/// the 'get'-function.
/// the 'ArcShiftCell::get'-function.
pub fn assign(&self, other: &ArcShift<T>) -> Result<(), RecursionDetected> {
if self.recursion.get() == 0 {
// SAFETY:
Expand Down
2 changes: 2 additions & 0 deletions arcshift/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn simple_cell() {
owner.validate();
});
}

#[test]
fn simple_cell_recursion() {
model(|| {
Expand All @@ -179,6 +180,7 @@ fn simple_cell_recursion() {
let cell = ArcShiftCell::from_arcshift(root.clone());
cell.get(|val| {
assert_eq!(val.str(), "root");
assert!(cell.assign(&ArcShift::new(owner.create("dummy"))).is_err());
cell.get(|val| {
assert_eq!(val.str(), "root");
root.update(owner.create("B"));
Expand Down

0 comments on commit b3ea6f2

Please sign in to comment.