Add compute_patch tests for adding/removing children

This commit is contained in:
Lucien Greathouse
2019-09-30 17:04:45 -07:00
parent b512e707a5
commit 5f5bfadf2b
3 changed files with 94 additions and 0 deletions

View File

@@ -89,6 +89,74 @@ fn remove_property() {
assert_yaml_snapshot!(patch_value);
}
#[test]
fn add_child() {
let mut redactions = RedactionMap::new();
let tree = empty_tree();
redactions.intern(tree.get_root_id());
let snapshot = InstanceSnapshot {
snapshot_id: None,
metadata: Default::default(),
name: Cow::Borrowed("ROOT"),
class_name: Cow::Borrowed("ROOT"),
properties: Default::default(),
children: vec![InstanceSnapshot {
snapshot_id: None,
metadata: Default::default(),
name: Cow::Borrowed("New"),
class_name: Cow::Borrowed("Folder"),
properties: Default::default(),
children: Vec::new(),
}],
};
let patch_set = compute_patch_set(&snapshot, &tree, tree.get_root_id());
let patch_value = redactions.redacted_yaml(patch_set);
assert_yaml_snapshot!(patch_value);
}
#[test]
fn remove_child() {
let mut redactions = RedactionMap::new();
let mut tree = empty_tree();
redactions.intern(tree.get_root_id());
{
let root_id = tree.get_root_id();
let new_id = tree.insert_instance(
InstancePropertiesWithMeta {
properties: RbxInstanceProperties {
name: "Should not appear in snapshot".to_owned(),
class_name: "Folder".to_owned(),
properties: Default::default(),
},
metadata: Default::default(),
},
root_id,
);
redactions.intern(new_id);
}
let snapshot = InstanceSnapshot {
snapshot_id: None,
metadata: Default::default(),
name: Cow::Borrowed("ROOT"),
class_name: Cow::Borrowed("ROOT"),
properties: Default::default(),
children: Vec::new(),
};
let patch_set = compute_patch_set(&snapshot, &tree, tree.get_root_id());
let patch_value = redactions.redacted_yaml(patch_set);
assert_yaml_snapshot!(patch_value);
}
fn empty_tree() -> RojoTree {
RojoTree::new(InstancePropertiesWithMeta {
properties: RbxInstanceProperties {