diff --git a/crates/engine/src/cmd/pathops.rs b/crates/engine/src/cmd/pathops.rs index 2132375a44..cacafa5d06 100644 --- a/crates/engine/src/cmd/pathops.rs +++ b/crates/engine/src/cmd/pathops.rs @@ -1563,6 +1563,12 @@ pub fn auto_simplify_level(s: &Session) -> Result { fn simplify(s: &mut Session, p: &Value) -> Result { const C: &str = "object.path.simplify"; let (auto, given_level, given_tolerance) = (switch_or(p, "auto", false, C)?, number_given(p, "level", C)?, length_given(p, "tolerance", C)?); + if given_tolerance.is_some_and(|t| t < 0.0) { + return Err(bad(C, "`tolerance` must be 0 or more")); + } + if given_level.is_some_and(|l| !(0.0..=100.0).contains(&l)) { + return Err(bad(C, "`level` must be from 0 to 100")); + } let corner_angle = number_given(p, "cornerAngle", C)?.unwrap_or(30.0).clamp(0.0, 180.0); let (straight_lines, whole) = (switch_or(p, "straightLines", false, C)?, switch_or(p, "wholePaths", false, C)?); // With auto, the slider's level is Auto-Simplify's for the selection's size; otherwise it is the level given. diff --git a/crates/engine/src/tests/areafit.rs b/crates/engine/src/tests/areafit.rs index 7d8f759cf5..046271982f 100644 --- a/crates/engine/src/tests/areafit.rs +++ b/crates/engine/src/tests/areafit.rs @@ -374,52 +374,6 @@ fn auto_height_in_columns_matches_the_full_search_when_lines_start_small() { } } -/// Time typing at the start of a story of 5,000, 20,000 and 50,000 characters in Auto Size area -/// type in 2 and 3 columns: 20 letters typed one at a time with the Type tool, with Auto Size as it -/// runs and with `FULL_SEARCH` on (the columns laid out at every step of the bisection). -/// Run with `cargo test --release -p vectorcraft-engine --lib auto_height_in_columns_typing_timing -- --ignored --nocapture`. -#[test] -#[ignore = "manual timing probe; wall-clock performance depends on machine load"] -fn auto_height_in_columns_typing_timing() { - use crate::cmd::typecmd::{COLUMN_LAYOUTS, FULL_SEARCH}; - const WORDS: &str = "The quick brown fox jumps over the lazy dog and keeps running far beyond the first frame of this story. "; - let v = ViewInfo::default(); - for n in [5_000, 20_000, 50_000] { - let story = format!("{}\n", WORDS.repeat(6).trim_end()).repeat(n / 600 + 1)[..n].to_string(); - for cols in [2, 3] { - let mut row = format!("{n} characters in {cols} columns:"); - for full in [false, true] { - FULL_SEARCH.with(|c| c.set(full)); - let mut s = Session::new(); - s.execute("file.new", &json!({"width": 4400, "height": 1200})).unwrap(); - let area = json!({"width": 500, "height": 100, "fit": "autoHeight"}); - let id = s.execute("text.create", &json!({"x": 20, "y": 20, "size": 9, "text": story, "area": area})).unwrap()["id"].clone(); - s.execute("select.set", &json!({"ids": [id]})).unwrap(); - s.execute("text.areaOptions", &json!({"columns": cols, "gutter": 12})).unwrap(); - s.select_tool("type", v).unwrap(); - for kind in [PointerKind::Down, PointerKind::Up] { - s.pointer(&PointerEvent::new(kind, 21.0, 24.0), v).unwrap(); - } - let layouts = COLUMN_LAYOUTS.with(std::cell::Cell::get); - let mut ms: Vec = "abcdefghijklmnopqrst" - .chars() - .map(|ch| { - let start = std::time::Instant::now(); - s.tool_text(&ch.to_string(), v).unwrap(); - start.elapsed().as_secs_f64() * 1000.0 - }) - .collect(); - let per_key = (COLUMN_LAYOUTS.with(std::cell::Cell::get) - layouts) as f64 / ms.len() as f64; - ms.sort_by(f64::total_cmp); - let how = if full { "every step laid out" } else { "Auto Size" }; - row += &format!(" {how} {:.1} ms a keystroke ({per_key:.1} column layouts);", ms[ms.len() / 2]); - } - FULL_SEARCH.with(|c| c.set(false)); - println!("{row}"); - } - } -} - #[test] fn shrink_text_round_trips_through_the_native_format() { let mut s = session(); diff --git a/crates/engine/src/tests/bboxrotate.rs b/crates/engine/src/tests/bboxrotate.rs index eec4ee191a..f34a611390 100644 --- a/crates/engine/src/tests/bboxrotate.rs +++ b/crates/engine/src/tests/bboxrotate.rs @@ -553,7 +553,7 @@ fn reset_bounding_box_squares_the_objects_inside_a_group() { // The group and both members, in one step. assert_eq!(s.execute("object.resetBoundingBox", &json!({})).unwrap()["changed"], 3); assert_eq!(undo_len(&s), n + 1); - assert!(object_angles(&s).iter().all(|a| *a == 0.0), "{:?}", object_angles(&s)); + assert_eq!(object_angles(&s), [0.0; 3], "the group and both members"); s.execute("object.ungroup", &json!({})).unwrap(); assert_eq!(selection_box(&s).angle, 0.0); assert_eq!(s.execute("object.resetBoundingBox", &json!({})).unwrap()["changed"], 0); @@ -709,9 +709,11 @@ fn reset_bounding_box_squares_every_box_rotate_bounding_box_turned() { let art = (anchors(&s, a), anchors(&s, c)); // The group, the masked object, its mask's art and the other rectangle. assert_eq!(s.execute("object.rotateBoundingBox", &json!({"angle": 25})).unwrap()["changed"], 4); - assert!(object_angles(&s).iter().all(|x| near(*x, 25.0)), "{:?}", object_angles(&s)); + let turned = object_angles(&s); + assert_eq!(turned.len(), 4, "{turned:?}"); + assert!(turned.iter().all(|x| near(*x, 25.0)), "{turned:?}"); assert_eq!(s.execute("object.resetBoundingBox", &json!({})).unwrap()["changed"], 4); - assert!(object_angles(&s).iter().all(|x| *x == 0.0), "{:?}", object_angles(&s)); + assert_eq!(object_angles(&s), [0.0; 4]); assert_eq!((anchors(&s, a), anchors(&s, c)), art); } diff --git a/crates/engine/src/tests/brushlib.rs b/crates/engine/src/tests/brushlib.rs index f2fe9860ca..2e809eaed9 100644 --- a/crates/engine/src/tests/brushlib.rs +++ b/crates/engine/src/tests/brushlib.rs @@ -1247,10 +1247,13 @@ fn pasted_brushed_art_brings_the_patterns_its_brush_art_uses() { run(&mut s, "brush.apply", json!({"name": "Dotted Band", "ids": [line]})); run(&mut s, "select.set", json!({"ids": [line]})); run(&mut s, "edit.copy", json!({})); + let (brush, dots) = (vectorcraft_brush::find(doc(&s), "Dotted Band"), doc(&s).pattern("Dots").cloned()); run(&mut s, "file.new", json!({"width": 200, "height": 200})); + assert_eq!((vectorcraft_brush::find(doc(&s), "Dotted Band"), doc(&s).pattern("Dots")), (None, None), "a new document has neither"); run(&mut s, "edit.paste", json!({})); - assert!(vectorcraft_brush::find(doc(&s), "Dotted Band").is_some()); - assert!(doc(&s).pattern("Dots").is_some(), "the brush's art is filled with it"); + assert_eq!(vectorcraft_brush::find(doc(&s), "Dotted Band"), brush); + assert_eq!(doc(&s).pattern("Dots").cloned(), dots, "the brush's art is filled with it"); + assert!(dots.is_some()); } #[test] diff --git a/crates/engine/src/tests/build.rs b/crates/engine/src/tests/build.rs index adb5d04af5..514015066b 100644 --- a/crates/engine/src/tests/build.rs +++ b/crates/engine/src/tests/build.rs @@ -2533,6 +2533,9 @@ fn shape_builder_erase_click_or_drag_from_inside_a_narrow_overlap_deletes_it() { assert_eq!(r["edges"].as_u64(), Some(0), "{points}: {r}"); let d = &s.doc().unwrap().doc; let left: Vec = d.children(d.default_layer()).unwrap().iter().filter_map(|c| c.geometric_bounds()).map(|b| b.width()).collect(); + let erased = r["regions"].as_u64().unwrap(); + assert!((1..=3).contains(&erased), "{points}: {r}"); + assert_eq!(left.len() as u64, 3 - erased, "{points}: the regions not erased stay: {left:?}"); assert!(left.iter().all(|w| *w > 2.0), "{points}: no strip is left: {left:?}"); } } @@ -4583,6 +4586,7 @@ fn live_paint_group_default_clears_the_faces_and_gives_the_edges_a_thin_black_st s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap(); s.execute("paint.default", &json!({})).unwrap(); let (faces, edges) = part_looks(&s, g); + assert_eq!((faces.len(), edges.len() >= 4), (3, true), "{}", edges.len()); assert!(faces.iter().all(|f| f.fill_paint().is_none() && f.stroke_paint().is_none())); assert!(edges.iter().all(|e| e.stroke_paint() == Paint::solid(Color::BLACK) && e.stroke_width() == 0.5 && e.fill_paint().is_none())); assert_eq!(sources_looks(&s, g), sources0); @@ -4627,6 +4631,7 @@ fn live_paint_group_invert_recolors_the_faces_fill() { let (_, edges0) = part_looks(&s, g); s.execute("paint.invert", &json!({"stroke": false})).unwrap(); let (faces, edges) = part_looks(&s, g); + assert_eq!((faces.len(), edges.len() >= 4), (3, true), "{}", edges.len()); assert!(faces.iter().all(|f| f.fill_paint() == Paint::solid(Color::rgb(0.0, 1.0, 1.0)))); assert_eq!(edges, edges0); assert_eq!(sources_looks(&s, g), sources0); @@ -4634,12 +4639,14 @@ fn live_paint_group_invert_recolors_the_faces_fill() { s.execute("paint.invert", &json!({"stroke": true, "target": "contents"})).unwrap(); let (faces1, edges1) = part_looks(&s, g); assert_eq!(faces1, faces); + assert_eq!(edges1.len(), edges.len()); assert!(edges1.iter().all(|e| e.stroke_paint() == Paint::solid(Color::WHITE))); assert_eq!(sources_looks(&s, g), sources0); // A gradient edit of the fill goes to the faces only. s.execute("paint.setFill", &json!({"gradient": {}})).unwrap(); s.execute("paint.editGradient", &json!({"stroke": false, "angle": 45})).unwrap(); let (faces2, edges2) = part_looks(&s, g); + assert_eq!(faces2.len(), 3); assert!(faces2.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(_)))); assert_eq!(edges2, edges1, "edges take no fill gradient"); assert_eq!(sources_looks(&s, g), sources0); @@ -4674,7 +4681,9 @@ fn live_paint_group_gradient_vector_and_freeform_edits_change_its_faces() { assert_eq!(sources_looks(&s, g), sources0); s.execute("paint.setFill", &json!({"gradient": {"kind": "freeform"}})).unwrap(); s.execute("paint.freeform.addPoint", &json!({"stroke": false, "at": [25, 50], "color": "#00ff00"})).unwrap(); - assert!(part_looks(&s, g).0.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(gr) if gr.freeform.is_some()))); + let faces_now = part_looks(&s, g).0; + assert_eq!(faces_now.len(), face_ids.len()); + assert!(faces_now.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(gr) if gr.freeform.is_some()))); assert_eq!(part_looks(&s, g).1, edges0); assert_eq!(sources_looks(&s, g), sources0); } @@ -4944,16 +4953,19 @@ fn live_paint_group_contents_edits_follow_the_group_rule() { let sources0 = sources_looks(&s, g); s.execute("appearance.addFill", &json!({"target": "contents"})).unwrap(); let (faces1, edges1) = part_looks(&s, g); + assert_eq!((faces0.len(), faces1.len(), edges0.len() >= 4), (3, 3, true), "{}", edges0.len()); assert!(faces1.iter().zip(&faces0).all(|(f, f0)| f.items.len() == f0.items.len() + 1), "every face takes a new fill"); assert_eq!(edges1, edges0, "edges take no new fill"); s.execute("appearance.addStroke", &json!({"target": "contents"})).unwrap(); let (faces2, edges2) = part_looks(&s, g); assert_eq!(faces2, faces1, "faces take no new stroke"); + assert_eq!(edges2.len(), edges1.len()); assert!(edges2.iter().zip(&edges1).all(|(e, e0)| e.items.len() == e0.items.len() + 1), "every edge takes a new stroke"); // A stroke row edit of the contents reaches the edges, not the faces. s.execute("stroke.set", &json!({"target": "contents", "item": 0, "weight": 7})).unwrap(); let (faces3, edges3) = part_looks(&s, g); assert_eq!(faces3, faces2, "faces keep their rows"); + assert_eq!(edges3.len(), edges2.len()); assert!(edges3.iter().all(|e| e.stroke_at(Some(0)).map(|st| st.width) == Some(7.0)), "every edge's stroke row takes the weight"); s.execute("appearance.clear", &json!({"target": "contents"})).unwrap(); assert_eq!(sources_looks(&s, g), sources0, "the hidden source paths keep their appearance"); @@ -5203,6 +5215,7 @@ fn live_paint_group_contents_take_a_graphic_style_by_kind() { s.execute("graphicStyle.apply", &json!({"name": "Both", "target": "contents", "add": add})).unwrap(); assert!(parts_hold_their_kind(&s, g), "add {add}: faces hold fills and edges strokes"); let (faces, edges) = part_looks(&s, g); + assert_eq!((faces.len(), edges.len() >= 4), (3, true), "add {add}: {}", edges.len()); assert!(faces.iter().all(|a| a.items.iter().any(|it| *it.paint() == red)), "add {add}: each face takes the style's fill"); assert!(edges.iter().all(|a| a.items.iter().any(|it| *it.paint() == blue)), "add {add}: each edge takes the style's stroke"); let n = node(&s, g); @@ -6199,6 +6212,7 @@ fn live_paint_bucket_edge_double_click_after_filling_a_face_paints_the_joined_ed let black = Paint::solid(Color::rgb(0.0, 0.0, 0.0)); let green = Paint::solid(Color::from_hex("#00ff00").unwrap()); let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 101.0, 51.0)); + assert!(all.len() >= 3, "the outline and the shared edge: {all:?}"); paint_parts(&mut s, &all, &black, &[(a, black.clone()), (b, black.clone())]); let v = ViewInfo::default(); s.select_tool("livePaintBucket", v).unwrap(); @@ -9217,16 +9231,23 @@ fn image_trace_refuses_an_unknown_setting() { } } -/// Every preset's settings, as imageTrace.presets lists them, trace when passed back whole. +/// A preset's settings, as imageTrace.presets lists them, trace when passed back whole, and the +/// trace keeps them: a preset with an enhanced version, both ways, and a preset without one. #[test] -fn image_trace_takes_every_preset_back_as_params() { +fn image_trace_takes_a_preset_back_as_params() { let list = session().execute("imageTrace.presets", &json!({})).unwrap(); - for preset in list["presets"].as_array().unwrap() { - for params in [&preset["params"], &preset["enhanced"]].into_iter().filter(|p| !p.is_null()) { - let mut s = session(); - image_doc(&mut s); - let r = s.execute("imageTrace.make", &json!({"preset": preset["name"], "params": params})); - assert!(r.is_ok(), "{}: {r:?}", preset["name"]); + let preset = |name: &str| list["presets"].as_array().unwrap().iter().find(|p| p["name"] == name).unwrap().clone(); + let (six, flat) = (preset("6 Colors"), preset("Flat Logo")); + for (name, params) in [("6 Colors", &six["params"]), ("6 Colors", &six["enhanced"]), ("Flat Logo", &flat["params"])] { + let mut s = session(); + image_doc(&mut s); + let r = s.execute("imageTrace.make", &json!({"preset": name, "params": params})).unwrap(); + let stored = node(&s, NodeId(r["id"].as_u64().unwrap())).extras().trace.clone().unwrap(); + assert_eq!(stored["preset"], name); + let given = params.as_object().unwrap(); + assert!(given.len() > 1, "{name}: {params}"); + for (key, value) in given { + assert_eq!(&stored["params"][key], value, "{name}: `{key}` is kept"); } } } diff --git a/crates/engine/src/tests/cancel.rs b/crates/engine/src/tests/cancel.rs index 9a044ead89..b369db85cb 100644 --- a/crates/engine/src/tests/cancel.rs +++ b/crates/engine/src/tests/cancel.rs @@ -87,5 +87,10 @@ fn nothing_is_cancelled_outside_a_scope() { token.cancel(); // The token only counts for work run under it, on its thread. let mut s = session(1); - assert!(s.execute("document.exportPdf", &json!({})).is_ok()); + let r = cancel::scope(&token, None, || s.execute("document.exportPdf", &json!({}))); + assert!(matches!(r, Err(EngineError::Cancelled)), "under the token: {r:?}"); + let r = s.execute("document.exportPdf", &json!({})).unwrap(); + let bytes = vectorcraft_format::base64_decode(r["dataBase64"].as_str().unwrap()).unwrap(); + assert!(bytes.starts_with(b"%PDF-"), "outside it the whole file is written"); + assert!(bytes.ends_with(b"%%EOF"), "to its end"); } diff --git a/crates/engine/src/tests/clippaint.rs b/crates/engine/src/tests/clippaint.rs index 1355c11b7d..0d596fe3b2 100644 --- a/crates/engine/src/tests/clippaint.rs +++ b/crates/engine/src/tests/clippaint.rs @@ -155,5 +155,7 @@ fn type_as_a_clipping_path_paints_its_characters() { let p = paint(&s); assert!(p.stroke.is_none()); let NodeKind::Text(fill) = &p.fill.expect("the characters' fill paints").kind else { panic!("type") }; - assert!(fill.runs.iter().all(|r| r.style.fill.color().is_some() && r.style.stroke.is_none())); + assert_eq!(fill.plain_text(), "Clip"); + let blue = vectorcraft_color::Color::from_hex("#0000ff"); + assert!(!fill.runs.is_empty() && fill.runs.iter().all(|r| r.style.fill.color() == blue && r.style.stroke.is_none()), "{:?}", fill.runs); } diff --git a/crates/engine/src/tests/colormgmt.rs b/crates/engine/src/tests/colormgmt.rs index 46d03c0379..55ed42ec7a 100644 --- a/crates/engine/src/tests/colormgmt.rs +++ b/crates/engine/src/tests/colormgmt.rs @@ -739,7 +739,9 @@ fn separations_preview_compares_the_visible_plates_as_a_set() { assert_eq!(sep(&mut s, json!({"plates": ["Cyan", "Magenta", "Yellow", "Black"]})), all, "every plate in plate order"); sep(&mut s, json!({"plates": ["Cyan", "Cyan"]})); let r = s.execute("view.separationsPreview", &json!({"toggle": "Cyan"})).unwrap(); - assert!(r["plates"].as_array().unwrap().iter().all(|p| p["visible"] == false), "{r}"); + let plates = r["plates"].as_array().unwrap(); + assert_eq!(plates.len(), 4, "{r}"); + assert!(plates.iter().all(|p| p["visible"] == false), "{r}"); } /// Each plate's visibility in a `view.separationsPreview` or `color.plates` reply, in plate order. diff --git a/crates/engine/src/tests/constrain_new.rs b/crates/engine/src/tests/constrain_new.rs index 9a26e45867..24b5a063d6 100644 --- a/crates/engine/src/tests/constrain_new.rs +++ b/crates/engine/src/tests/constrain_new.rs @@ -345,7 +345,9 @@ fn constrain_angle_turns_the_new_objects_bounding_box() { let id = NodeId(s.execute("shape.polarGrid", &json!({"x": 0, "y": 0, "width": 40, "height": 20, "rotation": -30})).unwrap()["id"].as_u64().unwrap()); let n = s.doc().unwrap().doc.node(id).unwrap().clone(); - assert!(n.children().unwrap().iter().all(|c| close(c.bbox_angle, 30.0))); + let lines = n.children().unwrap(); + assert!(lines.len() > 1, "{}", lines.len()); + assert!(lines.iter().all(|c| close(c.bbox_angle, 30.0))); s.execute("text.create", &json!({"x": 10, "y": 20, "text": "Hi", "rotation": -30})).unwrap(); assert!(close(selection_rotation(&s), 30.0)); s.execute("text.create", &json!({"x": 10, "y": 20, "text": "Hi"})).unwrap(); diff --git a/crates/engine/src/tests/dynamic_symbols.rs b/crates/engine/src/tests/dynamic_symbols.rs index e406c1b4f2..b8c6f782f1 100644 --- a/crates/engine/src/tests/dynamic_symbols.rs +++ b/crates/engine/src/tests/dynamic_symbols.rs @@ -1350,7 +1350,9 @@ fn a_stroke_on_a_picked_type_object_without_a_weight_draws() { s.execute("paint.setStroke", &json!({"color": "#ff0000"})).unwrap(); let part = s.doc().unwrap().selected_symbol_part().unwrap(); let NodeKind::Text(tx) = &part.kind else { panic!("type: {part:?}") }; - assert!(tx.runs.iter().all(|r| r.style.stroke_width == 1.0 && !r.style.stroke.is_none()), "{:?}", tx.runs); + assert_eq!(tx.plain_text(), "Hi"); + let red = Paint::solid(vectorcraft_color::Color::from_hex("#ff0000").unwrap()); + assert!(!tx.runs.is_empty() && tx.runs.iter().all(|r| r.style.stroke_width == 1.0 && r.style.stroke == red), "{:?}", tx.runs); } /// The colors the Fill and Stroke proxies show, as `paint.proxies` replies them. diff --git a/crates/engine/src/tests/freeform.rs b/crates/engine/src/tests/freeform.rs index 99810296ef..dda0f04cc4 100644 --- a/crates/engine/src/tests/freeform.rs +++ b/crates/engine/src/tests/freeform.rs @@ -115,7 +115,9 @@ fn cmyk_stops_recolor_the_points_with_inks() { let id = shape(&mut s, "shape.rectangle", 100.0, 100.0, 100.0, 100.0); run(&mut s, "paint.setFill", json!({"gradient": {"kind": "linear", "stops": cyan_to_black}})); run(&mut s, "paint.editGradient", json!({"kind": "freeform"})); - assert!(points(&s, id).points.iter().all(|p| cyan_and_black(p.color)), "{:?}", points(&s, id).points); + let placed = points(&s, id).points; + assert!(!placed.is_empty()); + assert!(placed.iter().all(|p| cyan_and_black(p.color)), "{placed:?}"); } #[test] @@ -181,6 +183,7 @@ fn reapplied_gradients_place_their_points_afresh() { let other = shape(&mut s, "shape.rectangle", 400.0, 300.0, 100.0, 100.0); run(&mut s, "paint.lastGradient", json!({})); let (a, (b, _)) = (points(&s, id), node(&s, other).proxy_freeform(false, None).unwrap()); + assert!(!a.points.is_empty() && b.points.len() == a.points.len(), "{:?}", b.points); assert!(b.points.iter().all(|p| p.at.x >= 400.0 && p.at.y >= 300.0), "{:?}", b.points); assert_eq!(a.points.iter().map(|p| p.color.to_hex()).collect::>(), b.points.iter().map(|p| p.color.to_hex()).collect::>()); } diff --git a/crates/engine/src/tests/gradient.rs b/crates/engine/src/tests/gradient.rs index 14cdb653b5..0c4bc3d0d3 100644 --- a/crates/engine/src/tests/gradient.rs +++ b/crates/engine/src/tests/gradient.rs @@ -38,8 +38,11 @@ fn new_gradient_defaults_follow_the_cmyk_document_mode() { let id = rect(&mut s, 10.0, 10.0, 100.0, 100.0); s.execute("paint.editGradient", &json!({"kind":kind})).unwrap(); let g = fill_gradient(&s, id); + assert!(g.gradient.stops.len() >= 2, "{kind}: {:?}", g.gradient.stops); assert!(g.gradient.stops.iter().all(|stop| matches!(stop.color, Color::Cmyk { .. })), "{kind}: {:?}", g.gradient.stops); + assert_eq!(g.freeform.is_some(), kind == "freeform", "{kind}"); if let Some(freeform) = g.freeform { + assert!(!freeform.points.is_empty()); assert!(freeform.points.iter().all(|point| matches!(point.color, Color::Cmyk { .. })), "freeform points must use the same color model"); } } @@ -52,6 +55,7 @@ fn editing_an_explicit_rgb_gradient_in_cmyk_keeps_its_color_model() { let id = rect(&mut s, 10.0, 10.0, 100.0, 100.0); s.execute("paint.editGradient", &json!({"kind":"linear","keepModel":true})).unwrap(); let before = fill_gradient(&s, id).gradient.stops; + assert_eq!(before.len(), 2, "{before:?}"); assert!(before.iter().all(|stop| matches!(stop.color, Color::Rgb { .. }))); s.execute("paint.editGradient", &json!({"angle":45})).unwrap(); assert_eq!(fill_gradient(&s, id).gradient.stops, before); @@ -67,6 +71,7 @@ fn drawing_a_new_gradient_vector_uses_cmyk_default_stops() { let appearance = &node(&s, id).appearance; let paint = if stroke { appearance.stroke_paint() } else { appearance.fill_paint() }; let Paint::Gradient(g) = paint else { panic!("not a gradient") }; + assert_eq!(g.gradient.stops.len(), 2, "stroke={stroke}: {:?}", g.gradient.stops); assert!(g.gradient.stops.iter().all(|stop| matches!(stop.color, Color::Cmyk { .. })), "stroke={stroke}: {:?}", g.gradient.stops); } } diff --git a/crates/engine/src/tests/ids_without_selection.rs b/crates/engine/src/tests/ids_without_selection.rs index cc7e03114f..a5ec82dd28 100644 --- a/crates/engine/src/tests/ids_without_selection.rs +++ b/crates/engine/src/tests/ids_without_selection.rs @@ -25,10 +25,15 @@ fn ids_stand_in_for_the_selection() { ("object.makePixelPerfect", json!({})), ] { let (mut s, id) = doc_with_rect(); + assert!(s.execute(cmd, ¶ms).is_err(), "{cmd}: nothing selected and no ids"); + let (before, undo) = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len()); let mut p = params; p["ids"] = json!([id]); let r = s.execute(cmd, &p); assert!(r.is_ok(), "{cmd}: {r:?}"); + let st = s.doc().unwrap(); + assert_ne!(st.doc, before, "{cmd}: the object given is changed"); + assert_eq!(st.history.undo.len(), undo + 1, "{cmd}: one undo step"); } } diff --git a/crates/engine/src/tests/pathops.rs b/crates/engine/src/tests/pathops.rs index f4e251638f..802748e407 100644 --- a/crates/engine/src/tests/pathops.rs +++ b/crates/engine/src/tests/pathops.rs @@ -1794,12 +1794,16 @@ fn commands_reject_bad_input() { ("object.path.offsetPath", json!({"offset": "abc"})), ("object.path.offsetPath", json!({"offset": 1e300})), ("object.path.simplify", json!({"tolerance": -5})), + ("object.path.simplify", json!({"level": 101})), ("object.path.splitIntoGrid", json!({"rows": 1e9, "columns": -1})), ("text.setStyle", json!({"size": -3})), ("type.createOutlines", json!({})), ("object.pathfinder.divide", json!({"junk": [1, 2]})), ] { - let _ = s.execute(c, &p); + let (before, undo) = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len()); + let r = s.execute(c, &p); + assert!(r.is_err(), "{c} {p}: {r:?}"); + assert_eq!((&s.doc().unwrap().doc, s.doc().unwrap().history.undo.len()), (&before, undo), "{c} {p}: nothing changes"); } } diff --git a/crates/engine/src/tests/plugins.rs b/crates/engine/src/tests/plugins.rs index be306a51c9..54c599d5fd 100644 --- a/crates/engine/src/tests/plugins.rs +++ b/crates/engine/src/tests/plugins.rs @@ -1916,19 +1916,6 @@ fn refresh_takes_objects_in_definition_art() { assert_eq!(listed(&mut s), [kept.0]); } -/// `CRAFT_PLUGIN_PAINTS_WASM=` saves a test live effect to try in the app -/// (`stroke-width-test-effect.wasm`): it draws a triangle over the area 100,80–300,230 while its -/// object's stroke is 5 pt wide, and hands the geometry back otherwise. -#[test] -fn stroke_width_test_effect() { - let Some(dir) = std::env::var_os("CRAFT_PLUGIN_PAINTS_WASM") else { return }; - let triangle = PathData::single(SubPath::polyline(&[Point::new(100.0, 230.0), Point::new(300.0, 230.0), Point::new(200.0, 80.0)], true)); - let manifest = r#"{"id":"org.example.strokewidth","name":"Stroke Width (test plug-in)","version":"1","kind":"effect", - "description":"Draws a triangle while the object's stroke is 5 pt wide.","params":{}}"#; - let src = tpl::when_given(manifest, tpl::Given::Input, r#""width":5.0"#, &json!({"objects": [{"path": triangle}]}).to_string()); - std::fs::write(std::path::Path::new(&dir).join("stroke-width-test-effect.wasm"), wat::parse_str(src).unwrap()).unwrap(); -} - /// A filter is given its objects' effect records and their strokes' join, cap and miter limit, and /// may return them. The records are admitted as effect.apply would admit them; one that isn't /// refuses the whole output, and nothing changes. @@ -1978,26 +1965,6 @@ fn filters_set_effects_and_stroke_styles() { } } -/// `CRAFT_PLUGIN_FRAME_WASM=` saves a test filter to try in the app -/// (`rough-frame-test-filter.wasm`): it adds a frame around 60,40–340,260 with a 6 pt stroke with -/// round joins and caps, roughened by the Roughen effect. -#[test] -fn rough_frame_test_filter() { - let Some(dir) = std::env::var_os("CRAFT_PLUGIN_FRAME_WASM") else { return }; - let frame = PathData::single(SubPath::polyline( - &[Point::new(60.0, 40.0), Point::new(340.0, 40.0), Point::new(340.0, 260.0), Point::new(60.0, 260.0)], - true, - )); - let ink = json!({"type": "solid", "color": {"model": "rgb", "r": 0.15, "g": 0.2, "b": 0.45}}); - let out = json!({"objects": [{"name": "Frame", "path": frame, "fills": [], - "strokes": [{"paint": ink, "width": 6, "join": "round", "cap": "round"}], - "effects": [{"id": "distort.roughen", "params": {"size": 2, "detail": 8, "points": "smooth"}}]}]}); - let manifest = r#"{"id":"org.example.frame","name":"Rough Frame (test plug-in)","version":"1","kind":"filter", - "description":"Adds a frame whose stroke is roughened by the Roughen effect.","params":{}}"#; - let src = tpl::returning(manifest, &out.to_string()); - std::fs::write(std::path::Path::new(&dir).join("rough-frame-test-filter.wasm"), wat::parse_str(src).unwrap()).unwrap(); -} - /// A filter keeps data with the document: it writes it with `documentData` in the same undo step as /// its objects (`null` removes it) and reads what it last wrote in `_context.documentData`, which /// no other filter is given. It is the document's foreign data, so the native file keeps it with @@ -2177,11 +2144,13 @@ fn plugins_folder_set_again_after_clearing_installs_its_plugins() { let mut s = session(); let folder = json!({"key": "pluginsFolder", "value": dir.0.display().to_string()}); run(&mut s, "prefs.set", folder.clone()); - assert!(vectorcraft_plugins::registry::get(id).is_some(), "installed from the folder"); + assert_eq!(run(&mut s, "plugin.list", json!({}))["folder"]["loaded"], json!([id]), "installed from the folder"); run(&mut s, "plugin.remove", json!({"id": id})); + assert!(vectorcraft_plugins::registry::get(id).is_none()); run(&mut s, "prefs.set", json!({"key": "pluginsFolder", "value": ""})); + assert_eq!(run(&mut s, "plugin.list", json!({}))["folder"]["loaded"], json!(null), "a cleared folder loads nothing"); run(&mut s, "prefs.set", folder); - assert!(vectorcraft_plugins::registry::get(id).is_some(), "installed again when the folder is set again"); + assert_eq!(run(&mut s, "plugin.list", json!({}))["folder"]["loaded"], json!([id]), "installed again when the folder is set again"); run(&mut s, "plugin.remove", json!({"id": id})); } diff --git a/crates/engine/src/tests/script_xmp.rs b/crates/engine/src/tests/script_xmp.rs index 4fbbc1741d..687df5cd0e 100644 --- a/crates/engine/src/tests/script_xmp.rs +++ b/crates/engine/src/tests/script_xmp.rs @@ -730,8 +730,7 @@ fn a_temporary_file_starts_private() { /// A replaced sidecar that had no access ACL takes none from its folder's default ACL, whose named /// users the sidecar's group bits would let in. The default ACL is set through its extended -/// attribute, so the test runs where the `acl` tools are not installed. (Skipped on a file system -/// without ACLs.) +/// attribute, so the test runs where the `acl` tools are not installed. #[cfg(target_os = "linux")] #[test] fn a_replaced_sidecar_takes_no_inherited_acl() { @@ -752,14 +751,8 @@ fn a_replaced_sidecar_takes_no_inherited_acl() { acl.extend(perm.to_le_bytes()); acl.extend(id.to_le_bytes()); } - match rustix::fs::setxattr(parent, "system.posix_acl_default", &acl, rustix::fs::XattrFlags::empty()) { - Ok(()) => {} - Err(e) if e == rustix::io::Errno::NOTSUP => { - let _ = std::fs::remove_dir_all(base); - return; - } - Err(e) => panic!("setting the default ACL: {e}"), - } + rustix::fs::setxattr(parent, "system.posix_acl_default", &acl, rustix::fs::XattrFlags::empty()) + .unwrap_or_else(|e| panic!("setting the default ACL (the temporary folder's file system needs ACLs): {e}")); let mut buf = vec![0u8; 4096]; let probe = parent.join("probe"); std::fs::write(&probe, b"").unwrap(); diff --git a/crates/engine/src/tests/strokegeom.rs b/crates/engine/src/tests/strokegeom.rs index af3eb52936..b9bd87c492 100644 --- a/crates/engine/src/tests/strokegeom.rs +++ b/crates/engine/src/tests/strokegeom.rs @@ -34,12 +34,10 @@ fn arrow_align_is_set_per_stroke_and_validated() { #[test] fn profiles_come_from_the_preset_catalogue() { let (mut s, id) = session_with_line(); - for p in WidthProfile::PRESETS { - s.execute("stroke.set", &json!({"profile": p.id})).unwrap(); - let st = stroke(&s, id); - assert_eq!(WidthProfile::id_of(st.profile.as_ref()), p.id); - } - assert!(stroke(&s, id).profile.is_some()); + s.execute("stroke.set", &json!({"profile": "lens"})).unwrap(); + assert_eq!(stroke(&s, id).profile.map(|p| p.points), Some(vec![(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)])); + s.execute("stroke.set", &json!({"profile": "pinch"})).unwrap(); + assert_eq!(stroke(&s, id).profile.map(|p| p.points), Some(vec![(0.0, 1.0, 1.0), (0.5, 0.25, 0.25), (1.0, 1.0, 1.0)])); s.execute("stroke.set", &json!({"profile": "uniform"})).unwrap(); assert!(stroke(&s, id).profile.is_none(), "uniform is the plain stroke"); assert!(s.execute("stroke.set", &json!({"profile": "zigzag"})).is_err()); @@ -53,9 +51,12 @@ fn profiles_come_from_the_preset_catalogue() { for a in vectorcraft_doc::Arrowhead::ALL { let name = serde_json::to_value(&a).unwrap(); assert!(spec.params.contains(name.as_str().unwrap()), "{name}"); - s.execute("stroke.set", &json!({"endArrow": name})).unwrap(); - assert_eq!(stroke(&s, id).end_arrow, Some(a)); } + s.execute("stroke.set", &json!({"endArrow": "TriangleOpen", "startArrow": "Diamond"})).unwrap(); + let st = stroke(&s, id); + assert_eq!((st.start_arrow, st.end_arrow), (Some(Arrowhead::Diamond), Some(Arrowhead::TriangleOpen))); + assert!(s.execute("stroke.set", &json!({"endArrow": "Arrow999"})).is_err()); + assert_eq!(stroke(&s, id).end_arrow, Some(Arrowhead::TriangleOpen), "a refused name changes nothing"); } #[test]