mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Scripts: test that a group's pathItems.removeAll() refuses an id found outside it
Adds a test that builds a document where a path outside a group has the same id as a path in the group, and checks that the group's pathItems.removeAll() throws and deletes nothing.
This commit is contained in:
1 parent
22b169a905
commit
fcc8f717dc
1 file changed
+27
@@ -4080,6 +4080,33 @@ fn group_path_items_remove_all_walks_only_the_group() {
|
||||
assert!(visits <= 3, "{visits} objects walked to empty a group of two paths");
|
||||
}
|
||||
|
||||
/// In a damaged document where a path outside a group has the same id as a path in it, the
|
||||
/// group's `pathItems.removeAll()` throws and deletes nothing, instead of deleting the outside path.
|
||||
#[test]
|
||||
fn group_path_items_remove_all_refuses_an_id_found_outside_the_group() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
s.execute("object.group", &json!({})).unwrap();
|
||||
let c = rect(&mut s, 200.0, 200.0, 20.0, 20.0);
|
||||
s.execute("select.set", &json!({"ids": [c.0]})).unwrap();
|
||||
s.execute("object.arrange.sendToBack", &json!({})).unwrap();
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let d = std::sync::Arc::make_mut(&mut s.active_mut().unwrap().doc);
|
||||
d.node_mut(c).unwrap().id = a;
|
||||
d.drop_lookup_cache();
|
||||
// The first object in tree order with the id is the one outside the group.
|
||||
assert_eq!(d.index_path(a).map(|p| p.len()), Some(2));
|
||||
let n = d.layers[0].children().map_or(0, Vec::len);
|
||||
let out = log(
|
||||
&mut s,
|
||||
"var d = app.activeDocument, m = ''; try { d.groupItems[0].pathItems.removeAll(); } catch (e) { m = e.message; }\
|
||||
vc.log(m); vc.log(d.groupItems[0].pathItems.length);",
|
||||
);
|
||||
assert_eq!(out, vec![json!(format!("cannot delete PathItem {}: its id also names another object", a.0)), json!(2)]);
|
||||
let d = &s.active().unwrap().doc;
|
||||
assert_eq!(d.layers[0].children().map_or(0, Vec::len), n, "the path outside the group is kept");
|
||||
}
|
||||
|
||||
/// The document's `pathItems.removeAll()` refuses to delete the path that clips a group while the
|
||||
/// group keeps other art, and deletes nothing, as the scoped collections do.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user