Tests: path joins, Pathfinder refusals and unknown selection modes

Adds engine tests for code that no test reached:

- path.join with the same id twice and subpaths: the coincident
  junction anchors merge, the later-first order puts the joined subpath
  in the right place, and one undo brings back all three subpaths.
- Join from direct-selected ends: both ends of one open subpath close
  only that subpath, and with both ends of one line and one end of
  another selected, Join takes the nearest pair of selected ends.
- Pathfinder refuses an image alone ("select paths") and an anchor that
  is not a finite number ("invalid coordinates"), with no undo step.
- path.setHandle and object.blend.spine.moveAnchor refuse link with
  symmetric (one row in each existing refusal table).
- select.segments, select.anchorsMany, select.magicWand and
  path.curvatureEdit refuse an unknown mode or op and leave the
  selection, the document and the undo history unchanged.
This commit is contained in:
dotCooCoo committed 2026-12-02 20:41:13 -08:00
1 parent 15cc3b048f
commit e47fad86bc
5 files changed
+157

No files matched your search

+33
View File
@@ -5188,6 +5188,39 @@ fn malformed_anchor_selection_never_replaces_or_partially_changes_selection() {
assert!(!s.doc().unwrap().selection.contains(b));
}
/// The selection commands and Curvature edits refuse a mode or op they do not know, and leave the
/// selection, the document and the undo history as they were.
#[test]
fn an_unknown_selection_mode_or_curvature_op_is_refused_without_changes() {
let mut s = session();
let a = rect(&mut s, 10.0, 10.0, 30.0, 20.0);
let b = rect(&mut s, 50.0, 10.0, 30.0, 20.0);
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
let doc = s.doc().unwrap().doc.clone();
let objects = s.doc().unwrap().selection.objects.clone();
let anchors = s.doc().unwrap().selection.anchors.clone();
let undo = s.doc().unwrap().history.undo.len();
let mut wrong = vec![];
for (cmd, p, says) in [
("select.segments", json!({"id": a.0, "segments": [[0, 0]], "mode": "bogus"}), "unknown mode"),
("select.anchorsMany", json!({"items": [{"id": a.0, "anchors": [[0, 0]]}], "mode": "bogus"}), "unknown mode"),
("select.magicWand", json!({"id": a.0, "mode": "bogus"}), "unknown mode"),
("path.curvatureEdit", json!({"id": a.0, "op": "bogus", "anchor": 0, "x": 0, "y": 0}), "unknown op"),
] {
match s.execute(cmd, &p) {
Err(e) if e.to_string().contains(says) => {}
other => wrong.push(format!("{cmd}: {other:?}")),
}
let st = s.doc().unwrap();
let changed = st.selection.objects != objects || st.selection.anchors != anchors || st.doc != doc || st.history.undo.len() != undo;
if changed {
wrong.push(format!("{cmd} changed the selection, the document or the undo history"));
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
}
}
assert!(wrong.is_empty(), "{wrong:#?}");
}
/// #1232: through the session, Direct Selection's corner widgets pick corners across paths. With
/// a corner of `a` picked and `b` selected whole, a Shift-click on a widget of `b` deselects that
/// corner and keeps `b`'s other corners and `a`'s pick; one on a widget of `a` that is not picked
@@ -225,6 +225,7 @@ fn a_linked_handle_makes_the_anchor_smooth() {
json!({"id": id.0, "anchor": 5, "which": "out", "x": 0, "y": 0, "link": 1}),
json!({"id": id.0, "anchor": 5, "which": "out", "x": 0, "y": 0, "link": true, "independent": true}),
json!({"id": id.0, "anchor": 5, "which": "out", "x": 0, "y": 0, "link": true, "independent": "no"}),
json!({"id": id.0, "anchor": 5, "which": "out", "x": 0, "y": 0, "link": true, "symmetric": true}),
json!({"id": id.0, "anchor": 100, "which": "out", "x": 0, "y": 0, "link": true}),
json!({"id": id.0, "anchor": 7, "which": "out", "x": 1.7e308, "y": 1.7e308, "link": true}),
json!({"id": id.0, "anchor": 7, "which": "out", "x": 0, "y": -1e9, "link": true}),
+1
View File
@@ -456,6 +456,7 @@ fn a_linked_spine_handle_makes_the_point_smooth() {
for bad in [
json!({"anchor": 1, "handle": "out", "x": 75, "y": 25, "link": "yes"}),
json!({"anchor": 1, "handle": "out", "x": 75, "y": 25, "link": true, "independent": true}),
json!({"anchor": 1, "handle": "out", "x": 60, "y": 40, "link": true, "symmetric": true}),
json!({"anchor": 1, "x": 75, "y": 25, "link": true}),
] {
assert!(s.execute("object.blend.spine.moveAnchor", &bad).is_err(), "{bad}");
+74
View File
@@ -6802,6 +6802,80 @@ fn join_two_subpaths_of_same_path_node() {
assert_eq!(pd.subpaths[0].anchors[3].p, Point::new(250.0, 0.0));
}
/// A path with one open two-anchor subpath per pair of points.
fn path_of_lines(s: &mut Session, lines: &[[Point; 2]]) -> NodeId {
let p = line(s, lines[0][0].x, lines[0][0].y, lines[0][1].x, lines[0][1].y);
let rest: Vec<_> = lines[1..].iter().map(|l| vectorcraft_geom::SubPath::polyline(l, false)).collect();
s.edit("Add Subpaths", |d, _| {
if let NodeKind::Path { path, .. } = &mut d.node_mut(p).unwrap().kind {
path.subpaths.extend(rest);
}
Ok(())
})
.unwrap();
p
}
fn subpath_points(s: &Session, id: NodeId) -> Vec<Vec<Point>> {
path(s, id).subpaths.iter().map(|sp| sp.anchors.iter().map(|a| a.p).collect()).collect()
}
/// `path.join` with the same id twice and `subpaths` joins two subpaths of one path. Here the later
/// subpath comes first, so the earlier one is removed and the joined subpath takes the later one's
/// place, the coincident junction anchors become one, and the subpath between them stays as it was.
/// One undo step brings back all three subpaths.
#[test]
fn join_of_one_path_by_ids_and_subpaths_merges_the_junction_and_keeps_the_other_subpath() {
let mut s = session();
let pt = Point::new;
let p = path_of_lines(&mut s, &[[pt(100.0, 0.0), pt(110.0, 0.0)], [pt(500.0, 0.0), pt(510.0, 0.0)], [pt(0.0, 0.0), pt(100.0, 0.0)]]);
let before = subpath_points(&s, p);
let undo = s.doc().unwrap().history.undo.len();
s.execute("path.join", &json!({"ids": [p.0, p.0], "subpaths": [2, 0], "ends": ["last", "first"]})).unwrap();
assert_eq!(subpath_points(&s, p), vec![vec![pt(500.0, 0.0), pt(510.0, 0.0)], vec![pt(0.0, 0.0), pt(100.0, 0.0), pt(110.0, 0.0)]]);
assert!(path(&s, p).subpaths.iter().all(|sp| !sp.closed));
assert_eq!(s.doc().unwrap().selection.objects, vec![p]);
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(subpath_points(&s, p), before);
}
/// With both ends of one open subpath direct-selected, Join closes that subpath and leaves the
/// other open subpath of the same path as it is, instead of joining the two.
#[test]
fn join_with_both_ends_of_one_subpath_selected_closes_that_subpath() {
let mut s = session();
let pt = Point::new;
let p = path_of_lines(&mut s, &[[pt(0.0, 0.0), pt(100.0, 0.0)], [pt(0.0, 50.0), pt(100.0, 50.0)]]);
s.execute("select.anchors", &json!({"id": p.0, "anchors": [[1, 0], [1, 1]], "mode": "set"})).unwrap();
s.execute("path.join", &json!({})).unwrap();
assert_eq!(subpath_points(&s, p), vec![vec![pt(0.0, 0.0), pt(100.0, 0.0)], vec![pt(0.0, 50.0), pt(100.0, 50.0)]]);
let pd = path(&s, p);
assert!(!pd.subpaths[0].closed, "the other subpath stays open");
assert!(pd.subpaths[1].closed, "the subpath with both ends selected is closed");
}
/// With both ends of one line selected and only the first end of another, Join takes the nearest
/// pair of selected ends: the second line's unselected end is nearer but is not joined.
#[test]
fn join_with_both_ends_of_one_line_selected_takes_the_nearest_selected_pair() {
let mut s = session();
let pt = Point::new;
let a = line(&mut s, 0.0, 0.0, 100.0, 0.0);
let b = line(&mut s, 300.0, 0.0, 105.0, 0.0);
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0], [0, 1]], "mode": "set"})).unwrap();
s.execute("select.anchors", &json!({"id": b.0, "anchors": [[0, 0]], "mode": "add"})).unwrap();
s.execute("path.join", &json!({})).unwrap();
let joined = paths(&s);
assert_eq!(joined.len(), 1, "{joined:?}");
let pts: Vec<Point> = joined[0].1.subpaths[0].anchors.iter().map(|a| a.p).collect();
assert_eq!(pts, vec![pt(0.0, 0.0), pt(100.0, 0.0), pt(300.0, 0.0), pt(105.0, 0.0)]);
}
/// Direct-selecting 2 open endpoints in a complex compound path with multiple open segments joins only those 2.
#[test]
fn join_complex_compound_path_direct_endpoints() {
+48
View File
@@ -123,6 +123,54 @@ fn intersect_disjoint_is_error_and_no_change() {
assert_eq!(s.doc().unwrap().history.undo.len(), undo_len);
}
/// Pathfinder refuses a selection that holds no paths (an image alone) and paths with an anchor
/// that is not a finite number, and leaves the document and the undo history as they were.
#[test]
fn pathfinder_refuses_a_selection_without_paths_and_invalid_coordinates() {
let mut s = session();
let image = s
.edit("Place", |d, sel| {
d.images.insert("pic".into(), vectorcraft_doc::ImageBlob::png(vec![0; 8]));
let id = d.alloc_id();
let im = vectorcraft_doc::ImageObject {
key: "pic".into(),
width: 2,
height: 2,
xf: Default::default(),
link: None,
placement: Default::default(),
pixels: None,
};
d.insert(d.default_layer(), 0, vectorcraft_doc::Node::new(id, NodeKind::Image(Box::new(im))))?;
sel.set([id]);
Ok(id)
})
.unwrap();
let before = s.doc().unwrap().doc.clone();
let undo_len = s.doc().unwrap().history.undo.len();
let e = s.execute("object.pathfinder.unite", &json!({})).unwrap_err().to_string();
assert!(e.contains("select paths"), "{e}");
assert!(s.doc().unwrap().doc == before);
assert_eq!(s.doc().unwrap().history.undo.len(), undo_len);
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
let b = rect(&mut s, 5.0, 0.0, 10.0, 10.0);
s.edit("Break", |d, _| {
if let NodeKind::Path { path, .. } = &mut d.node_mut(a).unwrap().kind {
path.subpaths[0].anchors[1].p.x = f64::NAN;
}
Ok(())
})
.unwrap();
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
let undo_len = s.doc().unwrap().history.undo.len();
let e = s.execute("object.pathfinder.unite", &json!({})).unwrap_err().to_string();
assert!(e.contains("invalid coordinates"), "{e}");
assert!(s.doc().unwrap().doc.node(a).is_some() && s.doc().unwrap().doc.node(b).is_some());
assert!(s.doc().unwrap().doc.node(image).is_some());
assert_eq!(s.doc().unwrap().history.undo.len(), undo_len);
}
#[test]
fn exclude_makes_compound() {
let mut s = session();