Skip to content

Commit

Permalink
Add clone_multiple_into_external ref preservation test
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler committed Sep 25, 2023
1 parent ee83b9e commit e3ed64e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
39 changes: 39 additions & 0 deletions rbx_dom_weak/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,45 @@ mod test {
insta::assert_yaml_snapshot!(viewer.view(&other_dom));
}

#[test]
fn clone_multiple_into_external() {
let dom = {
let mut child1 = InstanceBuilder::new("Part").with_name("Child1");
let mut child2 = InstanceBuilder::new("Part").with_name("Child2");

child1 = child1.with_property("RefProp", child2.referent);
child2 = child2.with_property("RefProp", child1.referent);

WeakDom::new(
InstanceBuilder::new("Folder")
.with_name("Root")
.with_children([child1, child2]),
)
};

let mut other_dom = WeakDom::new(InstanceBuilder::new("DataModel"));
let cloned = dom.clone_multiple_into_external(&dom.root().children(), &mut other_dom);

assert!(
other_dom.get_by_ref(cloned[0]).unwrap().parent.is_none(),
"parent of cloned subtree root should be none directly after a clone"
);

assert!(
other_dom.get_by_ref(cloned[1]).unwrap().parent.is_none(),
"parent of cloned subtree root should be none directly after a clone"
);

other_dom.transfer_within(cloned[0], other_dom.root_ref);
other_dom.transfer_within(cloned[1], other_dom.root_ref);

let mut viewer = DomViewer::new();

// This snapshot should contain Child1 and Child2, with Child1's and Child2's ref
// properties rewritten to point to the newly cloned instances
insta::assert_yaml_snapshot!(viewer.view(&other_dom));
}

#[test]
fn large_depth_tree() {
// We've had issues with stack overflows when creating WeakDoms with
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: rbx_dom_weak/src/dom.rs
expression: viewer.view(&other_dom)
---
referent: referent-0
name: DataModel
class: DataModel
properties: {}
children:
- referent: referent-1
name: Child1
class: Part
properties:
RefProp: referent-2
children: []
- referent: referent-2
name: Child2
class: Part
properties:
RefProp: referent-1
children: []

0 comments on commit e3ed64e

Please sign in to comment.