diff --git a/crates/engine/Cargo.toml b/crates/engine-core/Cargo.toml similarity index 100% rename from crates/engine/Cargo.toml rename to crates/engine-core/Cargo.toml diff --git a/crates/engine/src/actions_record.rs b/crates/engine-core/src/actions_record.rs similarity index 100% rename from crates/engine/src/actions_record.rs rename to crates/engine-core/src/actions_record.rs diff --git a/crates/engine/src/actions_record/tests.rs b/crates/engine-core/src/actions_record/tests.rs similarity index 99% rename from crates/engine/src/actions_record/tests.rs rename to crates/engine-core/src/actions_record/tests.rs index 60c93f370a..2046146df8 100644 --- a/crates/engine/src/actions_record/tests.rs +++ b/crates/engine-core/src/actions_record/tests.rs @@ -5,7 +5,7 @@ use crate::jobs::Started; use crate::{EngineError, Session}; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/adjust_params.rs b/crates/engine-core/src/adjust_params.rs similarity index 100% rename from crates/engine/src/adjust_params.rs rename to crates/engine-core/src/adjust_params.rs diff --git a/crates/engine/src/adjust_params/tests.rs b/crates/engine-core/src/adjust_params/tests.rs similarity index 99% rename from crates/engine/src/adjust_params/tests.rs rename to crates/engine-core/src/adjust_params/tests.rs index 5fbc44967a..61a7ffa99f 100644 --- a/crates/engine/src/adjust_params/tests.rs +++ b/crates/engine-core/src/adjust_params/tests.rs @@ -364,7 +364,7 @@ fn gray_point_fallback_keeps_tightly_spaced_points_round_trip_safe() { #[test] fn curves_eyedropper_param_drives_the_command() { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("edit.fill", json!({"color": [0.6, 0.5, 0.4]})).unwrap(); s.execute("image.adjustments.curves", json!({"eyedropper": {"point": "white", "at": [2, 2]}})).unwrap(); @@ -391,7 +391,7 @@ fn curves_eyedropper_param_drives_the_command() { /// that samples the image below the layer, so a repeated click keeps the same curve. #[test] fn layer_eyedropper_samples_below_the_curves_layer() { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("edit.fill", json!({"color": [0.6, 0.5, 0.4]})).unwrap(); s.execute("layer.newAdjustmentLayer.curves", json!({})).unwrap(); @@ -420,7 +420,7 @@ fn layer_eyedropper_samples_below_the_curves_layer() { #[test] fn eyedropper_on_a_smart_object_records_the_resolved_adjustment() { for kind in ["curves", "levels"] { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("edit.fill", json!({"color": [0.6, 0.5, 0.4]})).unwrap(); s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); @@ -437,14 +437,14 @@ fn eyedropper_on_a_smart_object_records_the_resolved_adjustment() { fn levels_eyedroppers_set_white_and_neutral_gray() { let pixel = |s: &mut crate::Session| -> Vec { serde_json::from_value(s.execute("document.pixel", json!({"x": 2, "y": 2})).unwrap()).unwrap() }; for depth in [8, 16] { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth})).unwrap(); s.execute("edit.fill", json!({"color": [0.6, 0.5, 0.4]})).unwrap(); s.execute("image.adjustments.levels", json!({"eyedropper": {"point": "white", "at": [2, 2]}})).unwrap(); let px = pixel(&mut s); assert!(px.iter().take(3).all(|v| *v > 0.995), "{depth}-bit: the sample becomes white: {px:?}"); } - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("edit.fill", json!({"color": [0.6, 0.5, 0.4]})).unwrap(); let before = pixel(&mut s); @@ -489,7 +489,7 @@ fn hue_range_sliders_stay_ordered() { /// A colourful 16×16 document (`mode`, `depth`) for command tests. fn colourful(mode: &str, depth: u32) -> crate::Session { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "mode": mode, "depth": depth})).unwrap(); for (i, c) in ["#c83c28", "#3c8c50", "#2850b4", "#d2b464"].iter().enumerate() { s.execute("select.rect", json!({"x": (i % 2) * 8, "y": (i / 2) * 8, "width": 8, "height": 8})).unwrap(); @@ -563,7 +563,7 @@ fn destructive_levels_dont_clip_in_32_bit() { // compose-side `levels_dont_clip_in_32_bit` pins the same curve, #2592). let params = json!({"inBlack": 15, "inWhite": 230, "gamma": 1.3, "outBlack": 10, "outWhite": 245}); for depth in [8, 16, 32] { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap(); s.execute("edit.fill", json!({"color": "#000000"})).unwrap(); @@ -649,7 +649,7 @@ fn destructive_levels_match_independent_signed_hdr_endpoints() { // curve at black and white, not display-clipped values. let params = json!({"inBlack": 15, "inWhite": 230, "gamma": 1.3, "outBlack": 10, "outWhite": 245}); for (depth, low, high, tolerance) in [(8, 10.0, 245.0, 0.6), (16, 10.0, 245.0, 0.6), (32, -20.308_89, 265.750_3, 0.01)] { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 8, "height": 16})).unwrap(); s.execute("edit.fill", json!({"color": "#000000"})).unwrap(); diff --git a/crates/engine/src/allocation.rs b/crates/engine-core/src/allocation.rs similarity index 100% rename from crates/engine/src/allocation.rs rename to crates/engine-core/src/allocation.rs diff --git a/crates/engine/src/brush_clear_background_tests.rs b/crates/engine-core/src/brush_clear_background_tests.rs similarity index 98% rename from crates/engine/src/brush_clear_background_tests.rs rename to crates/engine-core/src/brush_clear_background_tests.rs index e295e68c0b..4612be6a11 100644 --- a/crates/engine/src/brush_clear_background_tests.rs +++ b/crates/engine-core/src/brush_clear_background_tests.rs @@ -12,7 +12,7 @@ const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0]; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "background": "white"})).unwrap(); s.tools.foreground = BLACK; s.tools.background = GREEN; diff --git a/crates/engine/src/brush_pressure_size_default_tests.rs b/crates/engine-core/src/brush_pressure_size_default_tests.rs similarity index 97% rename from crates/engine/src/brush_pressure_size_default_tests.rs rename to crates/engine-core/src/brush_pressure_size_default_tests.rs index f3f439be8a..ca25ab2e91 100644 --- a/crates/engine/src/brush_pressure_size_default_tests.rs +++ b/crates/engine-core/src/brush_pressure_size_default_tests.rs @@ -6,7 +6,6 @@ //! these same two fields (`crates/ui-egui/src/panels/options_bar.rs`), so off here means drawn //! off there. -use crate::Session; use photocraft_paint::brush::BrushSettings; use serde_json::{Value, json}; @@ -22,7 +21,7 @@ fn the_default_brush_has_neither_pressure_toggle_on() { /// two toggles. #[test] fn brush_get_reports_both_pressure_toggles_off() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let got = s.execute("brush.get", json!({})).unwrap(); assert_eq!(got["pressureSize"], json!(false), "brush.get reports Pressure for Size off (#11809)"); @@ -49,7 +48,7 @@ fn a_brush_that_omits_the_field_takes_the_off_default() { /// same field the options-bar button is drawn from. #[test] fn pressure_for_size_still_switches_on_and_off() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.execute("tools.setBrush", json!({"brush": {"pressureSize": true}})).unwrap(); assert!(s.tools.brush.pressure_size, "the toggle still turns on"); @@ -62,7 +61,7 @@ fn pressure_for_size_still_switches_on_and_off() { /// One stroke of a pressure ramp (0.3 → 0.65 → 1.0) across a new empty layer with `brush`: the /// layer's pixels and what the stroke covers. fn ramp(brush: Value) -> (Vec, photocraft_geom::Rect) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 40})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("paint.stroke", json!({"points": [[20.0, 20.0, 0.3], [40.0, 20.0, 0.65], [60.0, 20.0, 1.0]], "size": 24.0, "color": "#ff0000", "brush": brush})) diff --git a/crates/engine/src/build_info.rs b/crates/engine-core/src/build_info.rs similarity index 100% rename from crates/engine/src/build_info.rs rename to crates/engine-core/src/build_info.rs diff --git a/crates/engine/src/canvas_geom.rs b/crates/engine-core/src/canvas_geom.rs similarity index 100% rename from crates/engine/src/canvas_geom.rs rename to crates/engine-core/src/canvas_geom.rs diff --git a/crates/engine/src/canvas_geom/tests.rs b/crates/engine-core/src/canvas_geom/tests.rs similarity index 98% rename from crates/engine/src/canvas_geom/tests.rs rename to crates/engine-core/src/canvas_geom/tests.rs index beb04de97d..80fac123fa 100644 --- a/crates/engine/src/canvas_geom/tests.rs +++ b/crates/engine-core/src/canvas_geom/tests.rs @@ -32,7 +32,7 @@ fn paint(s: &mut Session, f: impl Fn(i32, i32) -> [f32; 4]) { /// An asymmetric document: a gradient Background, a type layer, a shape layer, a raster layer /// with a vector mask and a smart object, plus a guide, a saved path and a slice. fn mixed(depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth, "mode": mode})).unwrap(); paint(&mut s, |x, y| [x as f32 / W as f32, y as f32 / H as f32, 0.3, 1.0]); s.execute("type.create", json!({"x": 4, "y": 16, "text": "Fj", "size": 14, "color": "#102080"})).unwrap(); @@ -190,7 +190,7 @@ fn gradient_fill_angle_follows_the_canvas() { /// The gradient fill's centre offset after `cmd`, as `gradient.fill.get` reports it (% of the frame). fn fill_offset_after(cmd: &str, p: serde_json::Value) -> (f64, f64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("gradient.fill.create", json!({"from": [10, 50], "to": [90, 50], "style": "radial"})).unwrap(); s.execute("gradient.fill.set", json!({"angle": 0, "offset": [25, 0]})).unwrap(); @@ -225,7 +225,7 @@ fn gradient_fill_offset_stays_a_fraction_of_the_frame() { fn turns_carry_an_angle_gradient_fill_with_its_pixels() { // An Angle gradient sweeps clockwise: a mirror must reverse it, a turn must not. for t in TURNS { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H})).unwrap(); let p = json!({"from": [20, 14], "to": [50, 4], "style": "angle", "dither": false}); s.execute("gradient.fill.create", p).unwrap(); @@ -250,7 +250,7 @@ fn turns_carry_an_angle_gradient_fill_with_its_pixels() { /// The shape's (fill, stroke) gradient angles after `cmd` on a shape whose fill and stroke both /// start as a 0° (left to right) gradient. fn shape_gradient_angles_after(cmd: &str, p: serde_json::Value) -> (f32, f32) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H})).unwrap(); let g = json!({"gradient": {"stops": [[0, "#ff0000"], [1, "#0000ff"]], "angle": 0}}); s.execute("shape.create", json!({"kind": "rect", "rect": [10, 8, 30, 20], "fill": g, "stroke": {"width": 6, "fill": g}})).unwrap(); @@ -324,7 +324,7 @@ fn canvas_size_and_crop_move_vector_geometry() { #[test] fn guide_colours_follow_their_guides() { const MAGENTA: [u8; 3] = [255, 0, 255]; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 20, "color": "#ff00ff"})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 30})).unwrap(); @@ -386,7 +386,7 @@ fn arbitrary_rotation_moves_marks_and_unlinked_vector_masks() { /// A canvas turn moves every stored video frame, not just the displayed one (#4956). #[test] fn turns_move_stored_video_frames() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); paint(&mut s, |x, y| if (x, y) == (1, 2) { [1.0, 0.0, 0.0, 1.0] } else { [0.0; 4] }); @@ -410,14 +410,14 @@ fn turns_move_stored_video_frames() { #[test] fn turns_on_empty_and_tiny_documents_never_panic() { for (w, h) in [(1, 1), (1, 7), (5, 1)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); for t in TURNS { s.execute(command(t), json!({"junk": [1, 2]})).unwrap(); } s.execute("image.rotation.arbitrary", json!({"angle": 33})).unwrap(); } - let mut s = Session::new(); + let mut s = crate::session(); for t in TURNS { assert!(s.execute(command(t), json!({})).is_err(), "no document"); } diff --git a/crates/engine/src/channel_clip.rs b/crates/engine-core/src/channel_clip.rs similarity index 100% rename from crates/engine/src/channel_clip.rs rename to crates/engine-core/src/channel_clip.rs diff --git a/crates/engine/src/channel_clip/tests.rs b/crates/engine-core/src/channel_clip/tests.rs similarity index 99% rename from crates/engine/src/channel_clip/tests.rs rename to crates/engine-core/src/channel_clip/tests.rs index 484b91ffe5..4434ae74b8 100644 --- a/crates/engine/src/channel_clip/tests.rs +++ b/crates/engine-core/src/channel_clip/tests.rs @@ -7,7 +7,7 @@ const H: i32 = 20; /// A white document whose left half is #336699: red 0.2, green 0.4, blue 0.6 there. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": W / 2, "height": H})).unwrap(); s.execute("edit.fill", json!({"color": "#336699"})).unwrap(); @@ -77,7 +77,7 @@ fn cmyk_channels_copy_and_paste_as_tone() { // #5787: copying a CMYK channel gives its tone (white where there is no ink), and pasting a // tone into a CMYK channel writes it back as ink. for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "mode": "cmyk", "depth": depth, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": W / 2, "height": H})).unwrap(); s.execute("edit.fill", json!({"color": "#00ffff"})).unwrap(); @@ -102,7 +102,7 @@ fn spot_channels_copy_and_paste_as_tone() { // #5787: a spot channel stores ink but copies as its tone, and a tone pasted into it goes back // to ink: spot -> Black prints the spot's ink in black, Cyan -> spot gives the spot Cyan's ink. for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "mode": "cmyk", "depth": depth, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": W / 2, "height": H})).unwrap(); s.execute("edit.fill", json!({"color": "#00ffff"})).unwrap(); diff --git a/crates/engine/src/clip_group.rs b/crates/engine-core/src/clip_group.rs similarity index 99% rename from crates/engine/src/clip_group.rs rename to crates/engine-core/src/clip_group.rs index 31f62696a3..1aeb7cf591 100644 --- a/crates/engine/src/clip_group.rs +++ b/crates/engine-core/src/clip_group.rs @@ -146,7 +146,7 @@ mod tests { /// A document holding `spec` (bottom to top, `*` = clipped) above its Background. fn stack(spec: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); for name in spec.split_whitespace() { let id = s.execute("layer.new.layer", json!({"name": name.trim_end_matches('*')})).unwrap()["layer"].clone(); diff --git a/crates/engine/src/cmd.rs b/crates/engine-core/src/cmd.rs similarity index 99% rename from crates/engine/src/cmd.rs rename to crates/engine-core/src/cmd.rs index 73158ece9a..4c5eb728da 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine-core/src/cmd.rs @@ -181,7 +181,7 @@ mod set_props_tests { #[test] fn opacity_and_fill_outside_zero_to_one_are_refused_not_clamped() { // #5242: `55` (a percentage, as the Layer Style commands take) used to become 100 %. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("layer.setProps", json!({"opacity": 0.55, "fill": 0.4})).unwrap(); diff --git a/crates/engine/src/cmd/actions_cmds.rs b/crates/engine-core/src/cmd/actions_cmds.rs similarity index 99% rename from crates/engine/src/cmd/actions_cmds.rs rename to crates/engine-core/src/cmd/actions_cmds.rs index c98fb733db..20a09a19ce 100644 --- a/crates/engine/src/cmd/actions_cmds.rs +++ b/crates/engine-core/src/cmd/actions_cmds.rs @@ -1410,7 +1410,7 @@ mod security_tests { #[test] fn playback_budget_is_shared_by_nested_calls() { - let mut session = Session::new(); + let mut session = crate::session(); session.actions.playback_steps = MAX_PLAYBACK_STEPS - 1; assert!(consume_playback_step(&mut session)); assert!(!consume_playback_step(&mut session)); @@ -1420,7 +1420,7 @@ mod security_tests { /// batch carries instead of restarting it for each input. #[test] fn a_nested_batch_input_does_not_reset_the_shared_playback_count() { - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); session.actions.list.push(Action::new("A", vec![ActionStep::new("select.all", json!({}))])).unwrap(); session.actions.budget_shared = true; @@ -1437,7 +1437,7 @@ mod security_tests { /// walking the whole action for free. #[test] fn disabled_steps_are_charged_to_the_playback_budget() { - let mut session = Session::new(); + let mut session = crate::session(); let mut child = Action::new("Child", (0..1000).map(|_| ActionStep::new("select.all", json!({}))).collect()); child.disabled = (0..1000).collect(); let calls = MAX_PLAYBACK_STEPS as usize / 1000 * 2; diff --git a/crates/engine/src/cmd/actions_cmds/history.rs b/crates/engine-core/src/cmd/actions_cmds/history.rs similarity index 99% rename from crates/engine/src/cmd/actions_cmds/history.rs rename to crates/engine-core/src/cmd/actions_cmds/history.rs index 35777782c4..387d24cb7d 100644 --- a/crates/engine/src/cmd/actions_cmds/history.rs +++ b/crates/engine-core/src/cmd/actions_cmds/history.rs @@ -340,7 +340,7 @@ mod tests { /// finished, even with the document and history unchanged. #[test] fn a_continuation_resumes_once() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("actions.setHistory", json!({"singleState":true})).unwrap(); begin_document_history(&mut s, "Spell"); @@ -359,7 +359,7 @@ mod tests { /// Keep the policy fixed until every clone of a paused continuation releases its lease, in either history mode. fn history_policy_stays_fixed_until_all_paused_continuations_are_released() { for single in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.setHistory", json!({"singleState":single})).unwrap(); begin_document_history(&mut s, "Paused"); let continuation = ActionHistoryContinuation::capture(&mut s); @@ -380,7 +380,7 @@ mod tests { /// Generic preference set/reset routes must preserve the same paused-policy guard as actions.setHistory. fn generic_preference_updates_cannot_change_a_paused_history_policy() { for single in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.setHistory", json!({"singleState":single})).unwrap(); begin_document_history(&mut s, "Paused"); let continuation = ActionHistoryContinuation::capture(&mut s); @@ -413,7 +413,7 @@ mod tests { fn idle_dialog_rebind_keeps_first_edit_and_clear_boundaries() { for single in [false, true] { for clear in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("actions.setHistory", json!({"singleState":single})).unwrap(); begin_document_history(&mut s, "Spell"); @@ -449,7 +449,7 @@ mod tests { /// A dialog continuation cannot adopt another caller's active grouping scope. fn idle_dialog_rebind_never_takes_an_unrelated_parent_scope() { for single in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("actions.setHistory", json!({"singleState":single})).unwrap(); begin_document_history(&mut s, "Spell"); diff --git a/crates/engine/src/cmd/actions_cmds/playback_tests.rs b/crates/engine-core/src/cmd/actions_cmds/playback_tests.rs similarity index 96% rename from crates/engine/src/cmd/actions_cmds/playback_tests.rs rename to crates/engine-core/src/cmd/actions_cmds/playback_tests.rs index ca294a06f3..ff652ced8a 100644 --- a/crates/engine/src/cmd/actions_cmds/playback_tests.rs +++ b/crates/engine-core/src/cmd/actions_cmds/playback_tests.rs @@ -9,7 +9,7 @@ fn options(s: &Session) -> (crate::prefs::PlaybackPerformance, u8, bool) { #[test] fn set_playback_refuses_bad_values_and_changes_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); let before = options(&s); for bad in [ json!({"performance": "fast"}), @@ -36,7 +36,7 @@ fn set_playback_refuses_bad_values_and_changes_nothing() { #[test] fn set_playback_stores_each_value_in_preferences() { use crate::prefs::PlaybackPerformance::*; - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(options(&s), (Accelerated, 1, true), "the defaults the reference application ships"); let r = s.execute("actions.setPlayback", json!({"performance": "pause", "seconds": 60})).unwrap(); assert_eq!(r, json!({"performance": "pause", "seconds": 60, "singleState": true})); @@ -48,7 +48,7 @@ fn set_playback_stores_each_value_in_preferences() { // A preferences file round trip keeps all three. s.execute("actions.setPlayback", json!({"performance": "pause", "seconds": 7})).unwrap(); let saved = s.prefs_to_json(); - let mut t = Session::new(); + let mut t = crate::session(); assert!(t.load_prefs_json(&saved).unwrap().is_empty()); assert_eq!(options(&t), (Pause, 7, false)); // prefs.set validates the same range and names. @@ -62,7 +62,7 @@ fn set_playback_stores_each_value_in_preferences() { #[test] fn older_or_hand_edited_preferences_load_within_range() { - let mut s = Session::new(); + let mut s = crate::session(); // Before Playback Options: only the history flag. assert!(s.load_prefs_json(r#"{"actions":{"createSingleHistoryState":false}}"#).unwrap().is_empty()); assert_eq!(options(&s), (crate::prefs::PlaybackPerformance::Accelerated, 1, false)); @@ -74,7 +74,7 @@ fn older_or_hand_edited_preferences_load_within_range() { #[test] fn set_playback_keeps_the_history_policy_of_a_running_play() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.actions.list.push(Action::new("Change", vec![ActionStep::new("actions.setPlayback", json!({"singleState": false}))])).unwrap(); let played = s.execute("actions.play", json!({"action": "Change"})).unwrap(); @@ -88,7 +88,7 @@ fn set_playback_keeps_the_history_policy_of_a_running_play() { fn headless_play_runs_the_whole_action_in_every_mode() { for performance in ["accelerated", "step", "pause"] { for single in [true, false] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("actions.setPlayback", json!({"performance": performance, "seconds": 60, "singleState": single})).unwrap(); let steps = ["A", "B", "C"].map(|n| ActionStep::new("layer.new.layer", json!({"name": n}))).to_vec(); diff --git a/crates/engine/src/cmd/actions_cmds/tests.rs b/crates/engine-core/src/cmd/actions_cmds/tests.rs similarity index 97% rename from crates/engine/src/cmd/actions_cmds/tests.rs rename to crates/engine-core/src/cmd/actions_cmds/tests.rs index b26cb1f817..97edf971eb 100644 --- a/crates/engine/src/cmd/actions_cmds/tests.rs +++ b/crates/engine-core/src/cmd/actions_cmds/tests.rs @@ -19,7 +19,7 @@ fn pixel(s: &Session, layer: usize, x: i32, y: i32) -> Vec { /// write: it updates the smart object, headless too. #[test] fn save_in_edit_contents_updates_the_smart_object() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#ff0000"})).unwrap(); @@ -42,7 +42,7 @@ fn save_in_edit_contents_updates_the_smart_object() { #[test] fn deselect_with_nothing_selected_is_a_noop_in_playback() { // #6744: imported actions often start with Deselect; with no selection Photoshop plays on. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let before = s.active().unwrap().history.past_len(); // Outside playback the command stays disabled, like Photoshop's greyed menu item. @@ -62,7 +62,7 @@ fn deselect_with_nothing_selected_is_a_noop_in_playback() { #[test] fn unchecked_steps_are_skipped_and_follow_move_and_delete() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let step = |name: &str| ActionStep::new("layer.new.layer", json!({"name": name})); s.actions.list.push(Action::new("Three", vec![step("A"), step("B"), step("C")])).unwrap(); @@ -105,7 +105,7 @@ fn unchecked_steps_are_skipped_and_follow_move_and_delete() { #[test] fn recorded_eye_visibility_replays_on_another_document_and_duplicate_names() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Same"})).unwrap(); let hidden = s.execute("layer.new.layer", json!({"name": "Same"})).unwrap()["layer"].as_u64().unwrap(); @@ -141,7 +141,7 @@ fn recorded_thumbnail_click_on_another_layer_saves_and_replays_by_name() { s.execute("layer.new.layer", json!({"name": "Active"})).unwrap(); source }; - let mut s = Session::new(); + let mut s = crate::session(); let source = fixture(&mut s); let background = s.active().unwrap().doc.background().unwrap().id.0; s.execute("actions.record", json!({"name": "Load"})).unwrap(); @@ -158,7 +158,7 @@ fn recorded_thumbnail_click_on_another_layer_saves_and_replays_by_name() { ); crate::atn_cmds::export("Set", &[&action], &[], false).unwrap(); // Replayed in another document, the first step loads its Source layer. - let mut other = Session::new(); + let mut other = crate::session(); fixture(&mut other); let ActionStep { command: id, params } = &action.steps[0]; other.execute(id, params.clone()).unwrap(); @@ -168,7 +168,7 @@ fn recorded_thumbnail_click_on_another_layer_saves_and_replays_by_name() { #[test] fn rename_keeps_calls_and_function_key_and_rejects_bad_names() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions .list .push(Action { @@ -208,7 +208,7 @@ fn rename_keeps_calls_and_function_key_and_rejects_bad_names() { #[test] fn rename_follows_conditional_branches() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); for name in ["B", "Other"] { s.actions.list.push(Action { name: name.into(), steps: vec![ActionStep::new("layer.new.layer", json!({}))], ..Default::default() }).unwrap(); @@ -234,7 +234,7 @@ fn rename_follows_conditional_branches() { #[test] fn delete_action_drops_its_function_key_but_deleting_a_step_keeps_it() { - let mut s = Session::new(); + let mut s = crate::session(); let key = format!("{PLAY_SHORTCUT_PREFIX}Action 1"); s.actions.list.push(Action::new("Action 1", vec![ActionStep::new("layer.new.layer", json!({})), ActionStep::new("layer.new.layer", json!({}))])).unwrap(); s.edit_prefs(|p| p.shortcuts.insert(key.clone(), "F2".into())); @@ -273,7 +273,7 @@ fn translated_square(s: &mut Session, depth: u32) { #[test] fn record_transform_again_replays_one_concrete_transform_at_each_depth() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); translated_square(&mut s, depth); let from = s.journal.len(); s.execute("actions.record", json!({"name": "Again"})).unwrap(); @@ -310,7 +310,7 @@ fn record_transform_again_replays_one_concrete_transform_at_each_depth() { #[test] fn record_transform_again_on_a_copy_replays_in_a_session_without_a_transform() { for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); translated_square(&mut s, depth); s.execute("actions.record", json!({"name": "Step"})).unwrap(); s.execute("edit.transform.againCopy", json!({})).unwrap(); @@ -321,7 +321,7 @@ fn record_transform_again_on_a_copy_replays_in_a_session_without_a_transform() { let action = s.actions.list.actions()[0].clone(); // A new session has no transform to repeat: the concrete steps still play. - let mut fresh = Session::new(); + let mut fresh = crate::session(); fresh.execute("file.new", json!({"width": 20, "height": 8, "depth": depth, "background": "transparent"})).unwrap(); fresh .edit("red square", |doc, _| { @@ -344,7 +344,7 @@ fn record_transform_again_on_a_copy_replays_in_a_session_without_a_transform() { fn record_drops_the_steps_of_a_command_that_failed_and_was_taken_back() { // Transform Again on a Copy of a position-locked layer duplicates it, fails to move the // copy and takes the copy back: nothing is left to record. - let mut s = Session::new(); + let mut s = crate::session(); translated_square(&mut s, 8); let id = s.active().unwrap().active_layer.unwrap(); s.execute("layer.setProps", json!({"layer": id.0, "locks": {"position": true}})).unwrap(); @@ -364,7 +364,7 @@ fn record_drops_the_steps_of_a_command_that_failed_and_was_taken_back() { #[test] fn record_script_that_plays_an_action_keeps_each_step_once() { - let mut s = Session::new(); + let mut s = crate::session(); translated_square(&mut s, 8); s.execute("actions.record", json!({"name": "Inner"})).unwrap(); s.execute("edit.transform", json!({"matrix": [1, 0, 0, 1, 1, 0], "interpolation": "nearest"})).unwrap(); @@ -382,7 +382,7 @@ fn record_script_that_plays_an_action_keeps_each_step_once() { #[test] fn record_explicit_transform_keeps_one_replayable_step() { - let mut s = Session::new(); + let mut s = crate::session(); translated_square(&mut s, 8); s.execute("actions.record", json!({"name": "Move"})).unwrap(); s.execute("edit.transform", json!({"matrix": [1, 0, 0, 1, 4, 0], "interpolation": "nearest"})).unwrap(); @@ -402,7 +402,7 @@ fn record_explicit_transform_keeps_one_replayable_step() { #[test] fn recording_folds_one_run_of_move_tool_nudges() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Target"})).unwrap(); s.execute("actions.record", json!({"name": "Nudge"})).unwrap(); @@ -417,7 +417,7 @@ fn recording_folds_one_run_of_move_tool_nudges() { /// Pattern Preview nudges fold when `wrap` matches, and stay separate when it does not. #[test] fn recording_folds_wrapped_move_tool_nudges() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Target"})).unwrap(); s.execute("actions.record", json!({"name": "Nudge"})).unwrap(); @@ -437,7 +437,7 @@ fn recording_folds_wrapped_move_tool_nudges() { /// Each nudge moves by whole pixels, so two 0.6 px steps fold into the 2 px they moved, not 1.2. #[test] fn folded_nudges_add_whole_pixel_steps() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Target"})).unwrap(); s.execute("actions.record", json!({"name": "Nudge"})).unwrap(); @@ -450,7 +450,7 @@ fn folded_nudges_add_whole_pixel_steps() { #[test] fn recording_document_activation_uses_opening_order_offset() { - let mut s = Session::new(); + let mut s = crate::session(); for name in ["First", "Second"] { s.execute("file.new", json!({"width": 8, "height": 8, "name": name})).unwrap(); } @@ -462,7 +462,7 @@ fn recording_document_activation_uses_opening_order_offset() { #[test] fn recorded_point_text_position_scales_with_the_playback_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100, "background": "transparent"})).unwrap(); s.execute("actions.record", json!({"name": "Caption"})).unwrap(); s.execute("type.create", json!({"x": 20, "y": 30, "text": "Hi", "size": 12})).unwrap(); @@ -479,7 +479,7 @@ fn recorded_point_text_position_scales_with_the_playback_canvas() { #[test] fn recorded_point_text_rejects_invalid_relative_positions() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); for params in [ json!({"xPercent": 20}), @@ -494,7 +494,7 @@ fn recorded_point_text_rejects_invalid_relative_positions() { #[test] fn recorded_single_layer_transform_replays_after_layer_ids_shift() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 8, "background": "transparent"})).unwrap(); let source = s.execute("layer.new.layer", json!({"name": "Target"})).unwrap()["layer"].as_u64().unwrap(); s.edit("source pixel", |doc, _| { @@ -551,7 +551,7 @@ fn record_command_that_runs_commands_replays_it_once() { // Straighten Layer runs Image Rotation and Crop itself: only its own call is recorded, // so playback rotates once, not three times (rotate, crop, then straighten again). for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); ruled_layer(&mut s, depth); s.execute("actions.record", json!({"name": "Level"})).unwrap(); s.execute("image.analysis.rulerTool", json!({"start": [10, 30], "end": [70, 25]})).unwrap(); @@ -580,7 +580,7 @@ fn record_command_that_runs_commands_replays_it_once() { #[test] fn record_keeps_only_replayable_steps() { - let mut s = Session::new(); + let mut s = crate::session(); record_red(&mut s, 8); let got = s.execute("actions.get", json!({"action": "Red"})).unwrap(); let ids: Vec<&str> = got["steps"].as_array().unwrap().iter().map(|st| st[0].as_str().unwrap()).collect(); @@ -595,7 +595,7 @@ fn record_keeps_only_replayable_steps() { /// Playback on a different document must match native edits at every depth, independent of history grouping. fn play_on_another_document_matches_pixels_at_each_depth() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); // This control checks the optional, per-step history behavior. s.execute("actions.setHistory", json!({"singleState": false})).unwrap(); record_red(&mut s, depth); @@ -615,7 +615,7 @@ fn play_on_another_document_matches_pixels_at_each_depth() { #[test] fn recorded_layer_selection_replays_by_name_on_another_document() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth})).unwrap(); let original = s.active().unwrap().active_layer.unwrap(); s.execute("layer.setProps", json!({"name": "Photo"})).unwrap(); @@ -629,7 +629,7 @@ fn recorded_layer_selection_replays_by_name_on_another_document() { assert_eq!(s.actions.list.actions()[0].steps[0].params, json!({"name":"Photo", "mode":"replace"})); // Persisted actions must work in an entirely different session too. let saved = s.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); replay.execute("file.new", json!({"width": 8, "height": 8, "depth": depth})).unwrap(); replay.execute("layer.setProps", json!({"name": "Photo"})).unwrap(); @@ -660,7 +660,7 @@ fn recorded_mask_drop_replays_on_another_document() { id }; let has_mask = |s: &Session, name: &str| s.active().unwrap().doc.walk().iter().any(|(_, _, l)| l.name == name && l.mask.is_some()); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let photo = masked(&mut s, "Photo"); let shadow = s.execute("layer.new.layer", json!({"name": "Shadow"})).unwrap()["layer"].as_u64().unwrap(); @@ -670,7 +670,7 @@ fn recorded_mask_drop_replays_on_another_document() { assert_eq!(s.actions.list.actions()[0].steps[0].params, json!({"layer": "Photo", "to": "Shadow", "copy": false})); // Another document: an extra layer between them, so the recorded id is a different layer. let saved = s.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); replay.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); masked(&mut replay, "Photo"); @@ -699,7 +699,7 @@ fn recorded_mask_drop_onto_a_duplicate_name_replays_on_the_same_layer() { (photo, lower, upper) }; let mask_on = |s: &Session, id: u64| s.active().unwrap().doc.layer(photocraft_doc::LayerId(id)).unwrap().mask.is_some(); - let mut s = Session::new(); + let mut s = crate::session(); let (photo, lower, upper) = build(&mut s, false); s.execute("actions.record", json!({"name": "Copy mask"})).unwrap(); s.execute("layer.layerMask.moveTo", json!({"layer": photo, "to": lower, "copy": true})).unwrap(); @@ -707,7 +707,7 @@ fn recorded_mask_drop_onto_a_duplicate_name_replays_on_the_same_layer() { assert_eq!(s.actions.list.actions()[0].steps[0].params, json!({"layer": "Photo", "to": "Twin", "toOccurrence": 0, "copy": true})); assert!(mask_on(&s, lower) && !mask_on(&s, upper)); let saved = s.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); let (photo2, lower2, upper2) = build(&mut replay, true); assert_ne!((photo, lower, upper), (photo2, lower2, upper2), "the ids differ"); @@ -729,7 +729,7 @@ fn recorded_mask_drop_onto_a_duplicate_name_replays_on_the_same_layer() { #[test] fn recorded_layer_drag_replays_on_another_document() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth})).unwrap(); s.execute("actions.record", json!({"name": "Retouch"})).unwrap(); s.execute("layer.stampVisible", json!({})).unwrap(); @@ -747,7 +747,7 @@ fn recorded_layer_drag_replays_on_another_document() { let names = |s: &Session| s.active().unwrap().doc.layers.iter().rev().map(|l| l.name.clone()).collect::>(); let recorded = names(&s); let saved = s.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); replay.execute("file.new", json!({"width": 16, "height": 16, "depth": depth})).unwrap(); let result = replay.execute("actions.play", json!({"action": 0})).unwrap(); @@ -755,7 +755,7 @@ fn recorded_layer_drag_replays_on_another_document() { assert_eq!(names(&replay), recorded, "{depth}: the same stack"); } // Several layers of the drop target's name: the recorded occurrence picks the right one. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Twin"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Twin"})).unwrap(); @@ -775,7 +775,7 @@ fn recorded_layer_drag_replays_on_another_document() { } s.active().unwrap().doc.layers.iter().map(|l| l.id).collect::>() }; - let mut s = Session::new(); + let mut s = crate::session(); let ids = build(&mut s); let (lowest, top) = (ids[1], ids[3]); s.execute("actions.record", json!({"name": "Twins"})).unwrap(); @@ -785,7 +785,7 @@ fn recorded_layer_drag_replays_on_another_document() { let order = |s: &Session| s.active().unwrap().doc.layers.iter().map(|l| l.id).collect::>(); let want: Vec<_> = order(&s).iter().map(|id| ids.iter().position(|x| x == id).unwrap()).collect(); let saved = s.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); let ids2 = build(&mut replay); let result = replay.execute("actions.play", json!({"action": 0})).unwrap(); @@ -805,14 +805,14 @@ fn recorded_layer_drag_replays_on_another_document() { s.execute("layer.select", json!({"layer": group.0, "mode": "replace"})).unwrap(); (group, top) }; - let mut g = Session::new(); + let mut g = crate::session(); let (group, top) = build_group(&mut g); g.execute("actions.record", json!({"name": "Group"})).unwrap(); g.execute("layer.moveTo", json!({"layer": group.0, "target": top.0, "position": "above"})).unwrap(); g.execute("actions.stop", json!({})).unwrap(); let recorded = g.actions.list.actions()[0].steps[0].params.clone(); let saved = g.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); let (group2, _) = build_group(&mut replay); let result = replay.execute("actions.play", json!({"action": 0})).unwrap(); @@ -820,7 +820,7 @@ fn recorded_layer_drag_replays_on_another_document() { let top_layer = |s: &Session| s.active().unwrap().doc.layers.last().map(|l| l.id); assert_eq!(top_layer(&replay), Some(group2), "{recorded}: the group went to the top"); // Several moved layers named like the target are left out too, so the name is unambiguous. - let mut m = Session::new(); + let mut m = crate::session(); m.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let a = photocraft_doc::LayerId(m.execute("layer.new.layer", json!({"name": "Twin"})).unwrap()["layer"].as_u64().unwrap()); let b = photocraft_doc::LayerId(m.execute("layer.new.layer", json!({"name": "Twin"})).unwrap()["layer"].as_u64().unwrap()); @@ -829,7 +829,7 @@ fn recorded_layer_drag_replays_on_another_document() { assert_eq!(m.active().unwrap().doc.layers.last().map(|l| l.id), Some(b), "both moved above the third Twin"); assert_eq!(m.active().unwrap().doc.layers.iter().rev().nth(2).map(|l| l.id), Some(target)); // An ⌥-drag copy of the selected layer beside itself replays by name too. - let mut c = Session::new(); + let mut c = crate::session(); c.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let src = photocraft_doc::LayerId(c.execute("layer.new.layer", json!({"name": "Solo"})).unwrap()["layer"].as_u64().unwrap()); c.execute("actions.record", json!({"name": "Copy"})).unwrap(); @@ -837,7 +837,7 @@ fn recorded_layer_drag_replays_on_another_document() { c.execute("actions.stop", json!({})).unwrap(); assert_eq!(c.actions.list.actions()[0].steps[0].params, json!({"target": "Solo", "position": "above", "copy": true})); let saved = c.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); replay.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); replay.execute("layer.new.layer", json!({"name": "Solo"})).unwrap(); @@ -857,14 +857,14 @@ fn recorded_layer_drag_replays_on_another_document() { s.execute("layer.select", json!({"layer": group.0, "mode": "replace"})).unwrap(); (group, a, b) }; - let mut gc = Session::new(); + let mut gc = crate::session(); let (group, a, _) = build_copy(&mut gc); gc.execute("actions.record", json!({"name": "Copy group"})).unwrap(); // Below `a`: the copy's "Twin" then comes before `a` in document order. gc.execute("layer.moveTo", json!({"layer": group.0, "target": a.0, "position": "below", "copy": true})).unwrap(); gc.execute("actions.stop", json!({})).unwrap(); let saved = gc.actions.list.to_file().to_json().unwrap(); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.actions.list = ActionList::from_file(ActionsFile::from_json(&saved).unwrap()); let (_, a2, _) = build_copy(&mut replay); let result = replay.execute("actions.play", json!({"action": 0})).unwrap(); @@ -895,7 +895,7 @@ fn recorded_layer_drag_replays_on_another_document() { /// than exported as a copy beside the original. #[test] fn recorded_in_place_duplicate_keeps_in_place_only_for_artboards() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("actions.record", json!({"name": "Layer copy"})).unwrap(); s.execute("layer.duplicate", json!({"inPlace": true})).unwrap(); @@ -909,7 +909,7 @@ fn recorded_in_place_duplicate_keeps_in_place_only_for_artboards() { assert!(crate::atn_cmds::export("Audit", &[&s.actions.list.actions()[0]], &[], false).is_ok()); assert!(crate::atn_cmds::export("Audit", &[&s.actions.list.actions()[1]], &[], false).is_err()); // Several selected layers are copied together: one artboard among them keeps `inPlace`. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let photo = s.active().unwrap().active_layer.unwrap(); s.execute("layer.new.layer", json!({"name": "Logo"})).unwrap(); @@ -929,7 +929,7 @@ fn recorded_in_place_duplicate_keeps_in_place_only_for_artboards() { #[test] fn named_selection_preserves_modes_and_duplicate_occurrences() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("layer.setProps", json!({"name":"Photo"})).unwrap(); let first = s.active().unwrap().active_layer.unwrap(); @@ -1002,7 +1002,7 @@ fn named_selection_preserves_modes_and_duplicate_occurrences() { #[test] fn play_stops_at_the_failing_step_and_reports_it() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute("actions.record", json!({})).unwrap(); s.execute("layer.new.layer", json!({"name": "One"})).unwrap(); @@ -1023,7 +1023,7 @@ fn play_stops_at_the_failing_step_and_reports_it() { #[test] fn play_refuses_recursion() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions .list .push(Action { @@ -1046,7 +1046,7 @@ fn play_checks_each_step_with_the_authorize_hook() { fn deny_file(id: &str, _: &Value) -> Result<()> { if id.starts_with("file.") { Err(EngineError::Other(format!("automation command `{id}` is disabled"))) } else { Ok(()) } } - let mut s = Session::new(); + let mut s = crate::session(); s.authorize = Some(deny_file); s.actions .list @@ -1075,7 +1075,7 @@ fn actions_automation_wrote_keep_its_gate_when_the_user_plays_them() { if id.starts_with("file.") { Err(EngineError::Other(format!("automation command `{id}` is disabled"))) } else { Ok(()) } } let open = || ActionStep::new("file.openAs", json!({"path": "/outside/secret.png"})); - let mut s = Session::new(); + let mut s = crate::session(); s.automation_gate = Some(deny_file); s.actions.list.push(Action::new("Mine", vec![open()])).unwrap(); s.actions.list.push(Action::new("Edited", vec![ActionStep::new("layer.new.layer", json!({}))])).unwrap(); @@ -1124,7 +1124,7 @@ fn a_step_automation_runs_into_the_users_recording_keeps_its_gate() { fn admit(_: &str, _: &Value) -> Result<()> { Ok(()) } - let mut s = Session::new(); + let mut s = crate::session(); s.automation_gate = Some(deny_file); // The user records an action of their own: it is not marked. s.execute("actions.record", json!({"name": "Mine"})).unwrap(); @@ -1164,7 +1164,7 @@ fn a_step_automation_runs_into_the_users_recording_keeps_its_gate() { #[test] fn append_delete_and_from_step() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "white"})).unwrap(); let started = s.execute("actions.record", json!({"name": "Grow"})).unwrap(); assert_eq!(started["index"], 0); @@ -1188,7 +1188,7 @@ fn append_delete_and_from_step() { #[test] fn delete_one_step_while_recording_keeps_journal_and_remaining_steps() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("actions.record", json!({"name": "Edit"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Kept"})).unwrap(); @@ -1224,7 +1224,7 @@ fn delete_one_step_while_recording_keeps_journal_and_remaining_steps() { #[test] fn nested_call_records_one_named_step_and_tracks_child_edits() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.actions .list @@ -1259,7 +1259,7 @@ fn nested_call_records_one_named_step_and_tracks_child_edits() { #[test] fn nested_failure_cycles_depth_and_authorization_stop_parent() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions .list .push(Action { @@ -1309,7 +1309,7 @@ fn nested_failure_cycles_depth_and_authorization_stop_parent() { #[test] fn move_pending_steps_is_atomic_persists_and_changes_playback_order() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.execute("actions.record", json!({"name": "Order"})).unwrap(); for name in ["One", "Two", "Three"] { @@ -1340,7 +1340,7 @@ fn move_pending_steps_is_atomic_persists_and_changes_playback_order() { #[test] fn new_names_do_not_collide_with_named_calls() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action { name: "Action 2".into(), steps: vec![], disabled: Default::default(), ..Default::default() }).unwrap(); assert_eq!(s.execute("actions.record", json!({})).unwrap()["action"], "Action 3"); s.execute("actions.stop", json!({})).unwrap(); @@ -1350,7 +1350,7 @@ fn new_names_do_not_collide_with_named_calls() { #[test] fn moving_action_keeps_recording_attached_to_it() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); for name in ["A", "B", "C"] { s.actions.list.push(Action { name: name.into(), steps: vec![], disabled: Default::default(), ..Default::default() }).unwrap(); @@ -1367,7 +1367,7 @@ fn moving_action_keeps_recording_attached_to_it() { #[test] fn bad_params_do_not_panic() { - let mut s = Session::new(); + let mut s = crate::session(); let junk = [ Value::Null, json!([]), @@ -1397,7 +1397,7 @@ fn bad_params_do_not_panic() { fn actions_persist_with_the_preset_store() { let dir = std::env::temp_dir().join(format!("pc-actions-{}-persist", std::process::id())); let _ = std::fs::remove_dir_all(&dir); - let mut s = Session::new(); + let mut s = crate::session(); let warnings = s.attach_preset_store(crate::preset_store::open_dir(&dir)); assert!(warnings.iter().all(|w| !w.contains("actions")), "{warnings:?}"); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); @@ -1406,7 +1406,7 @@ fn actions_persist_with_the_preset_store() { s.execute("actions.stop", json!({})).unwrap(); drop(s); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(crate::preset_store::open_dir(&dir)); let listed = t.execute("actions.list", json!({})).unwrap(); assert_eq!(listed["actions"][0]["name"], "Kept"); @@ -1415,7 +1415,7 @@ fn actions_persist_with_the_preset_store() { // An action created before the store finishes loading is kept, and a different one on // disk is merged in. - let mut early = Session::new(); + let mut early = crate::session(); early.execute("actions.record", json!({"name": "Early"})).unwrap(); early.execute("actions.stop", json!({})).unwrap(); early.attach_preset_store(crate::preset_store::open_dir(&dir)); @@ -1423,7 +1423,7 @@ fn actions_persist_with_the_preset_store() { assert!(names.contains(&"Early".into()) && names.contains(&"Kept".into()), "{names:?}"); std::fs::write(dir.join("actions.json"), b"{").unwrap(); - let mut bad = Session::new(); + let mut bad = crate::session(); let warnings = bad.attach_preset_store(crate::preset_store::open_dir(&dir)); assert!(warnings.iter().any(|w| w.contains("actions")), "{warnings:?}"); assert!(bad.actions.list.actions().is_empty()); @@ -1434,7 +1434,7 @@ fn actions_persist_with_the_preset_store() { /// a selection fill and styled text all act on the document the replay runs in. #[test] fn a_recorded_edit_run_replays_on_a_second_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "background": "white"})).unwrap(); s.execute("actions.record", json!({"name": "Studio"})).unwrap(); s.execute("image.crop", json!({"x": 8, "y": 8, "width": 48, "height": 48})).unwrap(); @@ -1472,7 +1472,7 @@ fn a_recorded_edit_run_replays_on_a_second_document() { #[test] fn button_color_is_one_of_the_photoshop_swatches() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.record", json!({"name": "Print"})).unwrap(); s.execute("actions.stop", json!({})).unwrap(); let set = s.execute("actions.setColor", json!({"action": "Print", "color": "blue"})).unwrap(); @@ -1494,7 +1494,7 @@ fn button_color_is_one_of_the_photoshop_swatches() { /// An arrangement that cannot move the layer must not create a grouped history entry. fn arrange_that_cannot_move_is_a_noop_in_playback() { // #8453: imported actions make an adjustment layer, then Bring it to Front, where it already is. - let mut s = Session::new(); + let mut s = crate::session(); // Keep individual rows visible so grouping cannot hide an extra no-op record. s.execute("actions.setHistory", json!({"singleState": false})).unwrap(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); @@ -1613,7 +1613,7 @@ fn scoped_source_slots_do_not_bind_previously_missing_references() { assert_eq!(called.len(), 4); assert_eq!(called.last(), list.first(), "the scoped source keeps its embedded index"); assert!(resolve(&called, &called[0].steps[0].params, "actions.play").is_err(), "the ordinary source still has a missing target"); - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); session.actions.list = list_of(called); let (id, params) = steps.last().unwrap(); @@ -1626,7 +1626,7 @@ fn scoped_source_slots_do_not_bind_previously_missing_references() { /// surrounding spaces (from an older actions.json); a new set name is trimmed. #[test] fn record_keeps_an_existing_sets_exact_name() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action { set: Some(" Web ".into()), ..Action::new("Old", Vec::new()) }).unwrap(); s.execute("actions.record", json!({"name": "New", "set": " Web "})).unwrap(); s.execute("actions.stop", json!({})).unwrap(); @@ -1641,10 +1641,10 @@ fn record_keeps_an_existing_sets_exact_name() { /// exact name too, so the first action recorded into it lands in that folder and saves with it. #[test] fn record_keeps_an_empty_loaded_sets_exact_name() { - let mut src = Session::new(); + let mut src = crate::session(); src.actions.list.replace(ActionList::from_file(ActionsFile::new(Vec::new(), vec![" Web ".into()]))); let saved = src.execute("actions.save", json!({"set": " Web "})).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(s.execute("actions.load", json!({"data": saved["data"]})).unwrap()["set"], " Web "); s.execute("actions.record", json!({"name": "First", "set": " Web "})).unwrap(); s.execute("actions.stop", json!({})).unwrap(); @@ -1656,7 +1656,7 @@ fn record_keeps_an_empty_loaded_sets_exact_name() { #[test] fn skipped_steps_count_against_the_script_limit() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", (0..3).map(|_| ActionStep::new("select.all", json!({}))).collect())).unwrap(); s.actions.script_depth = 1; s.actions.script_steps = crate::automate_cmds::MAX_SCRIPT_STEPS - 1; @@ -1718,7 +1718,7 @@ fn rename_leaves_calls_that_reach_another_sets_action_alone() { ] }; let session = || { - let mut s = Session::new(); + let mut s = crate::session(); let file = ["A", "B"] .map(|set| Action { set: Some(set.into()), ..Action::new("Target", vec![ActionStep::new("image.adjustments.invert", json!({}))]) }) .into_iter() @@ -1752,7 +1752,7 @@ fn rename_leaves_calls_that_reach_another_sets_action_alone() { /// a Batch naming the same action in another set and an inline Batch stay as they were. #[test] fn rename_follows_named_batch_steps_in_their_set() { - let mut s = Session::new(); + let mut s = crate::session(); let mut target = Action::new("Target", vec![ActionStep::new("image.adjustments.invert", json!({}))]); target.set = Some("S".into()); s.actions.list.push(target).unwrap(); @@ -1783,7 +1783,7 @@ fn playback_stops_when_a_nested_batch_cannot_write_its_error_log() { let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).unwrap(); let dir = dir.to_string_lossy().into_owned(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); // A folder as the log path: the log write fails while every file succeeds. let batch = json!({"source": "open", "steps": [], "output": format!("{dir}/out"), "format": "png", "errorLog": dir}); diff --git a/crates/engine/src/cmd/actions_edit_cmds.rs b/crates/engine-core/src/cmd/actions_edit_cmds.rs similarity index 99% rename from crates/engine/src/cmd/actions_edit_cmds.rs rename to crates/engine-core/src/cmd/actions_edit_cmds.rs index c62400246a..da927f70d8 100644 --- a/crates/engine/src/cmd/actions_edit_cmds.rs +++ b/crates/engine-core/src/cmd/actions_edit_cmds.rs @@ -507,7 +507,7 @@ mod tests { use crate::actions_cmds::Action; fn session_with(steps: &[&str]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.actions.list.push(Action::new("A", steps.iter().map(|id| ActionStep::new(*id, json!({}))).collect())).unwrap(); s @@ -619,7 +619,7 @@ mod tests { assert_eq!(played["failed"]["step"], 0, "{played}"); assert_ne!(names(&s).last().map(String::as_str), Some("after")); // Without a document only always/never answer; layer conditions are false. - let t = Session::new(); + let t = crate::session(); assert!(evaluate(&t, "always").unwrap()); assert!(!evaluate(&t, "isOpen").unwrap()); assert!(!evaluate(&t, "isBackground").unwrap()); @@ -697,7 +697,7 @@ mod tests { } fn record_conditional(width: u32, height: u32) -> (Session, usize) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": width, "height": height})).unwrap(); s.actions.list.push(Action::new("Tall", vec![ActionStep::new("layer.new.layer", json!({"name": "Tall"}))])).unwrap(); let layers = s.active().unwrap().doc.walk().len(); diff --git a/crates/engine/src/cmd/actions_edit_cmds/insert_path.rs b/crates/engine-core/src/cmd/actions_edit_cmds/insert_path.rs similarity index 100% rename from crates/engine/src/cmd/actions_edit_cmds/insert_path.rs rename to crates/engine-core/src/cmd/actions_edit_cmds/insert_path.rs diff --git a/crates/engine/src/cmd/actions_edit_cmds/library_commands.rs b/crates/engine-core/src/cmd/actions_edit_cmds/library_commands.rs similarity index 100% rename from crates/engine/src/cmd/actions_edit_cmds/library_commands.rs rename to crates/engine-core/src/cmd/actions_edit_cmds/library_commands.rs diff --git a/crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs b/crates/engine-core/src/cmd/actions_edit_cmds/library_commands/tests.rs similarity index 95% rename from crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs rename to crates/engine-core/src/cmd/actions_edit_cmds/library_commands/tests.rs index 9438f4c165..83786e1bf3 100644 --- a/crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs +++ b/crates/engine-core/src/cmd/actions_edit_cmds/library_commands/tests.rs @@ -29,7 +29,7 @@ fn set(caption: &str, action: Option<(&str, u16)>) -> Vec { #[test] fn confirmed_clear_restores_both_shortcut_maps_without_document_history() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8})).unwrap(); s.actions.list.push(Action::new("Original", Vec::new())).unwrap(); s.actions.list.new_set("Empty").unwrap(); @@ -64,7 +64,7 @@ fn confirmed_clear_restores_both_shortcut_maps_without_document_history() { // An edit after a library command ends its undo; so does a change to the action shortcuts. #[test] fn any_later_edit_ends_the_library_undo() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.reset", json!({"confirm":true,"mode":"replace"})).unwrap(); s.execute("actions.newSet", json!({"name":"Later"})).unwrap(); assert!(s.execute("actions.undoLibrary", json!({})).is_err()); @@ -76,7 +76,7 @@ fn any_later_edit_ends_the_library_undo() { #[test] fn reset_appends_a_numbered_set_and_persists_it() { let store = MemBackend::default(); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(store.clone()))); s.actions.list.new_set("Existing").unwrap(); assert!(s.execute("actions.reset", json!({"confirm":true,"mode":"bad"})).is_err()); @@ -87,7 +87,7 @@ fn reset_appends_a_numbered_set_and_persists_it() { assert_eq!(s.actions.list.actions()[0].steps[0].command, "image.adjustments.invert"); assert_eq!(s.actions.list.actions()[1].steps[0].command, "image.adjustments.desaturate"); s.sync_preset_store(); - let mut reopened = Session::new(); + let mut reopened = crate::session(); reopened.attach_preset_store(open(Box::new(store))); assert_eq!(reopened.actions.list.actions(), s.actions.list.actions()); assert_eq!(reopened.actions.list.sets(), s.actions.list.sets()); @@ -100,7 +100,7 @@ fn reset_appends_a_numbered_set_and_persists_it() { #[test] fn whole_replace_validates_the_tail_and_keeps_every_set_in_order() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.reset", json!({"confirm":true,"mode":"append"})).unwrap(); let prior = s.actions.list.actions().to_vec(); let mut archive = set("Repeated", Some(("Action", 2))); @@ -129,7 +129,7 @@ fn whole_replace_validates_the_tail_and_keeps_every_set_in_order() { // Two actions one set gives the same name keep their own function keys. #[test] fn atn_load_keeps_function_keys_of_repeated_names_separate() { - let mut s = Session::new(); + let mut s = crate::session(); let result = s.execute("actions.load", json!({"data":b64(&set_of("Keys", &[("Same", 2), ("Same", 3)]))})).unwrap(); assert_eq!(result["functionKeys"], json!([{"action":"Same","key":"F2"},{"action":"Same 2","key":"F3"}])); assert_eq!(s.prefs().shortcuts[&format!("{PLAY_SHORTCUT_PREFIX}Same")], "F2"); @@ -139,7 +139,7 @@ fn atn_load_keeps_function_keys_of_repeated_names_separate() { /// Imported calls look in their own set before falling back to the first archive name. #[test] fn whole_replace_resolves_unqualified_calls_in_their_own_set() { - let mut s = Session::new(); + let mut s = crate::session(); let mut archive = set("Repeated", Some(("Child", 0))); let child = Action::new("Child", Vec::new()); let parent = Action::new("Parent", vec![ActionStep::new("actions.play", json!({"action":"Child"}))]); @@ -166,7 +166,7 @@ fn whole_replace_follows_explicit_atn_set_scopes() { let mut archive = set("First", Some(("Target", 0))); let (tail, _) = crate::atn_cmds::export("Second", &[&second, &caller], &[], false).unwrap(); archive.extend_from_slice(&tail[4..]); - let mut s = Session::new(); + let mut s = crate::session(); let result = s.execute("actions.replace", json!({"confirm":true,"data":b64(&archive)})).unwrap(); assert_eq!(result["actions"], json!(["Target", "Target 2", "Caller"])); let list = s.actions.list.actions(); @@ -187,7 +187,7 @@ fn whole_replace_keeps_diagnostics_on_their_archive_actions() { let mut archive = set("First", Some(("Target", 0))); let (tail, _) = crate::atn_cmds::export("Second", &[&first, &second], &[], false).unwrap(); archive.extend_from_slice(&tail[4..]); - let mut s = Session::new(); + let mut s = crate::session(); let result = s.execute("actions.replace", json!({"confirm":true,"data":b64(&archive)})).unwrap(); assert_eq!(result["actions"], json!(["Target", "Target 2", "Target 3"])); assert_eq!(result["unsupported"].as_array().unwrap().len(), 1); @@ -199,7 +199,7 @@ fn whole_replace_keeps_diagnostics_on_their_archive_actions() { #[test] fn shortcut_only_clear_restores_orphan_bindings_on_undo() { - let mut s = Session::new(); + let mut s = crate::session(); let orphan = "actions.play:Missing"; s.edit_prefs(|prefs| { prefs.shortcuts.insert(orphan.into(), "F2".into()); @@ -222,7 +222,7 @@ fn pre_attachment_replacement_persists_without_reloading_disk_and_keeps_undo() { for undo_before_attachment in [false, true] { let store = MemBackend::default(); store.write(ACTIONS_FILE, br#"{"version":1,"actions":[{"name":"Disk","set":"Saved"}]}"#).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Early", Vec::new())).unwrap(); s.execute("actions.reset", json!({"confirm":true,"mode":"replace"})).unwrap(); if undo_before_attachment { @@ -236,13 +236,13 @@ fn pre_attachment_replacement_persists_without_reloading_disk_and_keeps_undo() { assert_eq!(s.actions.list.sets(), ["PhotoCraft Basics"]); assert_eq!(names(&s), ["Invert Colors", "Desaturate"]); - let mut reopened = Session::new(); + let mut reopened = crate::session(); assert!(reopened.attach_preset_store(open(Box::new(store.clone()))).is_empty()); assert_eq!(reopened.actions.list.actions(), s.actions.list.actions()); s.execute("actions.undoLibrary", json!({})).unwrap(); assert_eq!(names(&s), ["Early"]); s.sync_preset_store(); - let mut reopened = Session::new(); + let mut reopened = crate::session(); assert!(reopened.attach_preset_store(open(Box::new(store))).is_empty()); assert_eq!(reopened.actions.list.actions(), s.actions.list.actions()); } @@ -252,14 +252,14 @@ fn pre_attachment_replacement_persists_without_reloading_disk_and_keeps_undo() { fn pre_attachment_clear_remains_authoritative_after_an_ordinary_edit() { let store = MemBackend::default(); store.write(ACTIONS_FILE, br#"{"version":1,"actions":[{"name":"Disk"}]}"#).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Early", Vec::new())).unwrap(); s.execute("actions.clearAll", json!({"confirm":true})).unwrap(); s.execute("actions.newSet", json!({"name":"New"})).unwrap(); assert!(s.attach_preset_store(open(Box::new(store.clone()))).is_empty()); assert!(s.actions.list.actions().is_empty()); assert_eq!(s.actions.list.sets(), ["New"]); - let mut reopened = Session::new(); + let mut reopened = crate::session(); assert!(reopened.attach_preset_store(open(Box::new(store))).is_empty()); assert!(reopened.actions.list.actions().is_empty()); assert_eq!(reopened.actions.list.sets(), ["New"]); @@ -270,7 +270,7 @@ fn empty_pre_attachment_clear_replaces_the_saved_library() { for undo in [false, true] { let store = MemBackend::default(); store.write(ACTIONS_FILE, br#"{"version":1,"actions":[{"name":"Disk"}]}"#).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(s.execute("actions.clearAll", json!({"confirm":true})).unwrap()["cleared"], 0); let revision = s.actions.list.revision(); assert_eq!(s.execute("actions.clearAll", json!({"confirm":true})).unwrap()["cleared"], 0); @@ -280,7 +280,7 @@ fn empty_pre_attachment_clear_replaces_the_saved_library() { } assert!(s.attach_preset_store(open(Box::new(store.clone()))).is_empty()); assert_eq!(s.actions.list.actions().first().map(|action| action.name.as_str()), undo.then_some("Disk")); - let mut reopened = Session::new(); + let mut reopened = crate::session(); assert!(reopened.attach_preset_store(open(Box::new(store))).is_empty()); assert_eq!(reopened.actions.list.actions(), s.actions.list.actions()); } diff --git a/crates/engine/src/cmd/actions_edit_cmds/record_again.rs b/crates/engine-core/src/cmd/actions_edit_cmds/record_again.rs similarity index 100% rename from crates/engine/src/cmd/actions_edit_cmds/record_again.rs rename to crates/engine-core/src/cmd/actions_edit_cmds/record_again.rs diff --git a/crates/engine/src/cmd/adjust_cmds.rs b/crates/engine-core/src/cmd/adjust_cmds.rs similarity index 100% rename from crates/engine/src/cmd/adjust_cmds.rs rename to crates/engine-core/src/cmd/adjust_cmds.rs diff --git a/crates/engine/src/cmd/adjust_cmds/replace_color_range.rs b/crates/engine-core/src/cmd/adjust_cmds/replace_color_range.rs similarity index 99% rename from crates/engine/src/cmd/adjust_cmds/replace_color_range.rs rename to crates/engine-core/src/cmd/adjust_cmds/replace_color_range.rs index d0d065f202..7191078c79 100644 --- a/crates/engine/src/cmd/adjust_cmds/replace_color_range.rs +++ b/crates/engine-core/src/cmd/adjust_cmds/replace_color_range.rs @@ -221,7 +221,7 @@ mod tests { /// A matching opaque default cannot allocate gap tiles beyond the existing adjustment budget. #[test] fn opaque_gap_budget_refuses_before_pixel_allocation_or_edit() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", serde_json::json!({"width":4,"height":2,"mode":"lab","depth":32,"background":"transparent"})).unwrap(); s.edit("Distant opaque exception", |doc, active| { let surface = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap(); @@ -248,7 +248,7 @@ mod tests { #[test] fn lab_bounds_refuse_subtracted_samples_and_click_order() { for extra in [serde_json::json!({"subtractPoints": [[1, 1]]}), serde_json::json!({"order": ["+", "-"]}), serde_json::json!({"subtractPoints": []})] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", serde_json::json!({"width": 4, "height": 2})).unwrap(); let before = s.active().unwrap().doc.clone(); let mut p = serde_json::json!({"labMinimum": [0, -10, -10], "labMaximum": [100, 10, 10], "lightness": 50}); diff --git a/crates/engine/src/cmd/adjust_cmds/tests.rs b/crates/engine-core/src/cmd/adjust_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/adjust_cmds/tests.rs rename to crates/engine-core/src/cmd/adjust_cmds/tests.rs index 616973587d..41701533c4 100644 --- a/crates/engine/src/cmd/adjust_cmds/tests.rs +++ b/crates/engine-core/src/cmd/adjust_cmds/tests.rs @@ -4,7 +4,7 @@ const DEPTHS: [u64; 3] = [8, 16, 32]; const MODES: [&str; 4] = ["rgb", "gray", "cmyk", "lab"]; fn session(depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": depth, "mode": mode})).unwrap(); paint(&mut s, |x, y| [0.1 + x as f32 / 60.0, 0.2 + y as f32 / 50.0, 0.6 - x as f32 / 120.0, 1.0]); s @@ -131,7 +131,7 @@ fn disabled_without_pixels() { assert!(!s.is_enabled(id), "{id}"); } assert!(s.is_enabled("image.adjustments.hdrToning")); - assert!(!Session::new().is_enabled("image.adjustments.hdrToning")); + assert!(!crate::session().is_enabled("image.adjustments.hdrToning")); } #[test] @@ -1242,7 +1242,7 @@ fn black_white_auto_spreads_the_greys() { assert_eq!(auto_black_white(&[]), BW_DEFAULTS); // The command: an adjustment layer reads the image under it; the document is unchanged. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); paint(&mut s, |x, _| if x < 10 { [0.776, 0.2, 0.2, 1.0] } else { [0.29, 0.29, 1.0, 1.0] }); let id = s.execute("layer.newAdjustmentLayer.blackWhite", json!({})).unwrap()["layer"].as_u64().unwrap(); @@ -1260,7 +1260,7 @@ fn black_white_auto_spreads_the_greys() { assert_eq!(s.execute("image.adjustments.blackWhite.auto", json!({"layer": id})).unwrap(), r); // Sampling a big canvas still finds a thin painted stripe. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 512, "height": 512, "background": "transparent"})).unwrap(); paint(&mut s, |x, y| match (x, y < 256) { (1, true) => [0.776, 0.2, 0.2, 1.0], @@ -1273,7 +1273,7 @@ fn black_white_auto_spreads_the_greys() { // Columns alternating with a period that divides the sampling stride (4 here): both colours // are still sampled, not only the even columns. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 512, "height": 512})).unwrap(); paint(&mut s, |x, _| if x % 2 == 0 { [0.776, 0.2, 0.2, 1.0] } else { [0.29, 0.29, 1.0, 1.0] }); let r = s.execute("image.adjustments.blackWhite.auto", json!({})).unwrap(); @@ -1299,7 +1299,7 @@ fn black_white_auto_reads_the_whole_input() { let split = |x: i32, _| if x < 10 { red } else { blue }; // A selection over the red half doesn't narrow Image › Adjustments' Auto. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); paint(&mut s, split); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); @@ -1319,7 +1319,7 @@ fn black_white_auto_reads_the_whole_input() { assert_eq!(auto(&mut s, json!({"layer": id})), mix.to_vec()); // Nor clipping it to a layer that only covers the red half. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); paint(&mut s, |_, _| blue); s.execute("layer.new.layer", json!({})).unwrap(); @@ -1330,7 +1330,7 @@ fn black_white_auto_reads_the_whole_input() { assert_eq!(auto(&mut s, json!({"layer": id})), mix.to_vec()); // A Black & White smart filter: its own result is grey, its input is the colours. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); paint(&mut s, split); s.execute("filter.convertForSmartFilters", json!({})).unwrap(); @@ -1345,7 +1345,7 @@ fn black_white_auto_reads_the_whole_input() { assert!(s.execute("image.adjustments.blackWhite.auto", json!({"filter": 0})).is_err(), "not a smart object"); // Past the render limit there is nothing to sample. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40000, "height": 30000, "background": "transparent"})).unwrap(); let id = s.execute("layer.newAdjustmentLayer.blackWhite", json!({})).unwrap()["layer"].as_u64().unwrap(); assert!(s.execute("image.adjustments.blackWhite.auto", json!({"layer": id})).is_err()); diff --git a/crates/engine/src/cmd/adjust_params.rs b/crates/engine-core/src/cmd/adjust_params.rs similarity index 100% rename from crates/engine/src/cmd/adjust_params.rs rename to crates/engine-core/src/cmd/adjust_params.rs diff --git a/crates/engine/src/cmd/adjustment_brush_cmds.rs b/crates/engine-core/src/cmd/adjustment_brush_cmds.rs similarity index 100% rename from crates/engine/src/cmd/adjustment_brush_cmds.rs rename to crates/engine-core/src/cmd/adjustment_brush_cmds.rs diff --git a/crates/engine/src/cmd/adjustment_brush_cmds_tests.rs b/crates/engine-core/src/cmd/adjustment_brush_cmds_tests.rs similarity index 99% rename from crates/engine/src/cmd/adjustment_brush_cmds_tests.rs rename to crates/engine-core/src/cmd/adjustment_brush_cmds_tests.rs index bc927059b9..f1cf749ba4 100644 --- a/crates/engine/src/cmd/adjustment_brush_cmds_tests.rs +++ b/crates/engine-core/src/cmd/adjustment_brush_cmds_tests.rs @@ -11,7 +11,7 @@ use crate::Session; const CMD: &str = "paint.adjustmentBrush"; fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1200, "height": 900, "background": "white"})).unwrap(); s } @@ -262,7 +262,7 @@ fn indexed_color_refuses_the_stroke_with_the_alert() { #[test] fn bad_params_are_errors_not_panics() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute(CMD, dab("levels")).is_err(), "no document"); let mut s = doc(); for p in [ diff --git a/crates/engine/src/cmd/align_cmds.rs b/crates/engine-core/src/cmd/align_cmds.rs similarity index 100% rename from crates/engine/src/cmd/align_cmds.rs rename to crates/engine-core/src/cmd/align_cmds.rs diff --git a/crates/engine/src/cmd/align_cmds/auto_blend_background_tests.rs b/crates/engine-core/src/cmd/align_cmds/auto_blend_background_tests.rs similarity index 99% rename from crates/engine/src/cmd/align_cmds/auto_blend_background_tests.rs rename to crates/engine-core/src/cmd/align_cmds/auto_blend_background_tests.rs index 92e811f566..4b5860320d 100644 --- a/crates/engine/src/cmd/align_cmds/auto_blend_background_tests.rs +++ b/crates/engine-core/src/cmd/align_cmds/auto_blend_background_tests.rs @@ -33,7 +33,7 @@ fn paint_scene(s: &mut Session, id: LayerId, x0: i32, x1: i32, gain: f32) { /// The issue's document: Left (the scene at x 0..240) as the Background, its uncovered area /// white, and Right (the scene at x 160..400, darkened) above it. fn left_background_and_right() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "background": "white"})).unwrap(); let bg = s.active().unwrap().doc.background().unwrap().id; paint_scene(&mut s, bg, 0, 240, 1.0); diff --git a/crates/engine/src/cmd/align_cmds/tests.rs b/crates/engine-core/src/cmd/align_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/align_cmds/tests.rs rename to crates/engine-core/src/cmd/align_cmds/tests.rs index e3387a2def..3c7cd021f6 100644 --- a/crates/engine/src/cmd/align_cmds/tests.rs +++ b/crates/engine-core/src/cmd/align_cmds/tests.rs @@ -39,7 +39,7 @@ fn select(s: &mut Session, ids: &[LayerId]) { #[test] fn auto_align_repositions_at_all_depths() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 240, "depth": depth, "background": "transparent"})).unwrap(); let a = texture_layer(&mut s, "A", 20, 20); let b = texture_layer(&mut s, "B", 31, 13); @@ -58,7 +58,7 @@ fn auto_align_repositions_at_all_depths() { #[test] fn auto_align_auto_projection_and_errors() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 240, "background": "transparent"})).unwrap(); let a = texture_layer(&mut s, "A", 20, 20); let b = texture_layer(&mut s, "B", 26, 25); @@ -75,7 +75,7 @@ fn auto_align_auto_projection_and_errors() { #[test] fn auto_align_keeps_a_locked_layer_as_the_reference() { for lock in ["all", "position", "pixels"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 240, "background": "transparent"})).unwrap(); let a = texture_layer(&mut s, "A", 20, 20); let b = texture_layer(&mut s, "B", 31, 13); @@ -113,7 +113,7 @@ fn auto_align_keeps_a_locked_layer_as_the_reference() { #[test] fn auto_align_moves_the_background_as_a_normal_layer() { let setup = || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 240, "background": "white"})).unwrap(); let bg = s.active().unwrap().doc.background().unwrap().id; paint_texture(&mut s, bg, 20, 20); @@ -155,7 +155,7 @@ fn auto_align_moves_the_background_as_a_normal_layer() { #[test] fn auto_align_warps_layer_masks_keeping_their_default() { for (projection, reveal) in [("reposition", true), ("reposition", false), ("cylindrical", true)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 240, "background": "transparent"})).unwrap(); let a = texture_layer(&mut s, "A", 20, 20); let b = texture_layer(&mut s, "B", 31, 13); @@ -184,7 +184,7 @@ fn auto_align_warps_layer_masks_keeping_their_default() { #[test] fn auto_blend_panorama_masks_and_seamless_layer() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "depth": depth, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "left"})).unwrap(); s.edit("l", |doc, active| { @@ -218,7 +218,7 @@ fn auto_blend_panorama_masks_and_seamless_layer() { /// #14214: the Background can't take a mask, and Auto-Blend leaves it the Background (no mask). #[test] fn auto_blend_keeps_the_background() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "background": "white"})).unwrap(); let bg = s.active().unwrap().doc.background().unwrap().id; s.execute("layer.new.layer", json!({"name": "right"})).unwrap(); @@ -241,7 +241,7 @@ fn auto_blend_keeps_the_background() { /// Seamless Tones and Colors evens out a 10% exposure step between two panorama layers. #[test] fn auto_blend_panorama_seamless_matches_exposure() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "background": "transparent"})).unwrap(); let mut ids = Vec::new(); for (name, x0, x1, gain) in [("left", 0, 130, 1.0f32), ("right", 70, 200, 1.1)] { @@ -266,7 +266,7 @@ fn auto_blend_panorama_seamless_matches_exposure() { /// wholly over the bottom one. It used to get an all-black mask; now it shows on its side. #[test] fn auto_blend_panorama_of_a_layer_the_canvas_crops_to_all_overlap() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "left"})).unwrap(); s.edit("l", |doc, active| { @@ -298,7 +298,7 @@ fn auto_blend_panorama_of_a_layer_the_canvas_crops_to_all_overlap() { /// its bounds, not cut off at the canvas edge. #[test] fn auto_blend_panorama_masks_past_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "left"})).unwrap(); s.edit("l", |doc, active| { @@ -329,7 +329,7 @@ fn auto_blend_panorama_masks_past_the_canvas() { /// estimate, so the extent past the canvas is capped independently: it keeps to the canvas. #[test] fn auto_blend_sparse_huge_bounds_keep_to_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "a"})).unwrap(); s.edit("a", |doc, active| { @@ -373,7 +373,7 @@ fn auto_blend_budget_counts_layers_and_channels() { #[test] fn auto_blend_stack_without_seamless() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({"name": "sharp"})).unwrap(); s.edit("checker", |doc, active| { @@ -430,7 +430,7 @@ fn smooth_layer(s: &mut Session, name: &str, dx: i32, dy: i32) -> LayerId { #[test] fn auto_align_registers_a_smooth_bracket_by_intensity() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 150, "depth": depth, "background": "transparent"})).unwrap(); let a = smooth_layer(&mut s, "A", 0, 0); let b = smooth_layer(&mut s, "B", 4, 3); @@ -460,7 +460,7 @@ fn auto_align_registers_a_smooth_bracket_by_intensity() { /// moving them by whatever pose its search box ends at. #[test] fn auto_align_rejects_unrelated_layers_instead_of_guessing_a_pose() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 150, "depth": 8, "background": "transparent"})).unwrap(); let a = smooth_layer(&mut s, "A", 0, 0); s.execute("layer.new.layer", json!({"name": "stripes"})).unwrap(); @@ -498,7 +498,7 @@ fn auto_align_rejects_unrelated_layers_instead_of_guessing_a_pose() { fn auto_blend_stack_fuses_the_sharp_halves() { let checker = |x: i32, y: i32| if (x / 3 + y / 3) % 2 == 0 { 0.2 } else { 0.8 }; for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 64, "depth": depth, "background": "transparent"})).unwrap(); let mut ids = Vec::new(); for (name, sharp_left) in [("left", true), ("right", false)] { @@ -544,7 +544,7 @@ fn auto_blend_stack_fuses_the_sharp_halves() { #[test] fn auto_blend_stack_depth_map() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 48, "depth": depth, "background": "transparent"})).unwrap(); let mut ids = Vec::new(); for k in 0..3 { diff --git a/crates/engine/src/cmd/analysis_cmds.rs b/crates/engine-core/src/cmd/analysis_cmds.rs similarity index 100% rename from crates/engine/src/cmd/analysis_cmds.rs rename to crates/engine-core/src/cmd/analysis_cmds.rs diff --git a/crates/engine/src/cmd/analysis_cmds/tests.rs b/crates/engine-core/src/cmd/analysis_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/analysis_cmds/tests.rs rename to crates/engine-core/src/cmd/analysis_cmds/tests.rs index c8e44553ad..2830f8f8e3 100644 --- a/crates/engine/src/cmd/analysis_cmds/tests.rs +++ b/crates/engine-core/src/cmd/analysis_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_doc::{ColorMode, LayerContent, LayerId}; fn session(w: u32, h: u32, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "background": "white"})).unwrap(); s } @@ -78,7 +78,7 @@ fn failed_compound_preserves_a_clean_document() { fn record_measurements_refuses_an_area_too_large_to_measure() { // #933: with no selection the whole document is measured, and `width * height` overflowed // u32 on a legal 65536×65536 document, panicking inside `run`. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 65536, "height": 65536, "background": "transparent"})).unwrap(); let err = s.execute("image.analysis.recordMeasurements", json!({"source": "selection"})).unwrap_err(); assert!(err.to_string().contains("too large to measure"), "{err}"); @@ -384,7 +384,7 @@ fn place_scale_marker_lays_out_its_label_in_points_at_high_resolution() { // `fontSize` is in points and `type.create` renders it at resolution/72 px per point, but the // layout treated it as pixels: at 300 ppi a 12 pt label (50 px) overlapped the bar. for res in [72.0, 300.0] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1200, "height": 900, "resolution": res, "background": "white"})).unwrap(); let r = s.execute("image.analysis.placeScaleMarker", json!({"fontSize": 12, "textPosition": "bottom"})).unwrap(); let bar_bottom = r["barRect"][3].as_f64().unwrap(); @@ -440,7 +440,7 @@ fn place_scale_marker_on_a_short_document_errors_without_panicking() { #[test] fn analysis_info_and_cmyk_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 30, "height": 20, "mode": "cmyk", "background": "white"})).unwrap(); assert_eq!(d(&s).mode, ColorMode::Cmyk); s.execute("count.add", json!({"x": 3, "y": 4})).unwrap(); diff --git a/crates/engine/src/cmd/analysis_straighten_enabled_tests.rs b/crates/engine-core/src/cmd/analysis_straighten_enabled_tests.rs similarity index 99% rename from crates/engine/src/cmd/analysis_straighten_enabled_tests.rs rename to crates/engine-core/src/cmd/analysis_straighten_enabled_tests.rs index b2d107d7bb..e9d232a960 100644 --- a/crates/engine/src/cmd/analysis_straighten_enabled_tests.rs +++ b/crates/engine-core/src/cmd/analysis_straighten_enabled_tests.rs @@ -19,14 +19,14 @@ const CMD: &str = "image.analysis.straightenLayer"; /// A white document with a Background, as File > New makes one. fn session(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": "white"})).unwrap(); s } /// The same document in CMYK at 16 bits, which the reference also straightens. fn cmyk_16(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "mode": "cmyk", "depth": 16, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/analysis_straighten_selection_tests.rs b/crates/engine-core/src/cmd/analysis_straighten_selection_tests.rs similarity index 99% rename from crates/engine/src/cmd/analysis_straighten_selection_tests.rs rename to crates/engine-core/src/cmd/analysis_straighten_selection_tests.rs index 5435de0c48..653e40d2a5 100644 --- a/crates/engine/src/cmd/analysis_straighten_selection_tests.rs +++ b/crates/engine-core/src/cmd/analysis_straighten_selection_tests.rs @@ -11,7 +11,7 @@ const CMD: &str = "image.analysis.straightenLayer"; /// An 800 × 600 document with a pixel layer "Colors" painted at 100,100 to 400,300, active, and a /// ruler that tilts it by a few degrees. fn session() -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); let l = LayerId(s.execute("layer.new.layer", json!({"name": "Colors"})).unwrap()["layer"].as_u64().unwrap()); s.edit("paint", |doc, _| { diff --git a/crates/engine/src/cmd/artboard_cmds.rs b/crates/engine-core/src/cmd/artboard_cmds.rs similarity index 100% rename from crates/engine/src/cmd/artboard_cmds.rs rename to crates/engine-core/src/cmd/artboard_cmds.rs diff --git a/crates/engine/src/cmd/artboard_cmds/export_options.rs b/crates/engine-core/src/cmd/artboard_cmds/export_options.rs similarity index 100% rename from crates/engine/src/cmd/artboard_cmds/export_options.rs rename to crates/engine-core/src/cmd/artboard_cmds/export_options.rs diff --git a/crates/engine/src/cmd/artboard_cmds/export_options_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/export_options_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/export_options_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/export_options_tests.rs index 62345e5668..0f460b2a32 100644 --- a/crates/engine/src/cmd/artboard_cmds/export_options_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/export_options_tests.rs @@ -8,7 +8,7 @@ use photocraft_geom::Rect; /// 64 x 48, transparent, with two boards: "Clear" (transparent, a red square inside, half the /// board left empty) and "White" (white background, empty). fn session() -> (Session, u64, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "background": "transparent"})).unwrap(); s.edit("Red", |doc, active| { let fmt = doc.pixel_format(); diff --git a/crates/engine/src/cmd/artboard_cmds/file_names_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/file_names_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/file_names_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/file_names_tests.rs index 67f93498c8..5d49ca681a 100644 --- a/crates/engine/src/cmd/artboard_cmds/file_names_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/file_names_tests.rs @@ -10,7 +10,7 @@ const MEASURED: [(&str, [u32; 4]); 3] = [("Red Board", [0, 0, 200, 150]), ("Blue /// The issue's test document: 800 x 400, RGB, 8 bit, transparent, unsaved and named /// `abfiles-test`, with `boards` added bottom to top. fn session(boards: &[(&str, [u32; 4])]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"name": "abfiles-test", "width": 800, "height": 400, "depth": 8, "background": "transparent"})).unwrap(); for (name, rect) in boards { s.execute("layer.new.artboard", json!({"name": name, "rect": rect, "background": "transparent"})).unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/file_types_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/file_types_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/file_types_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/file_types_tests.rs index 7ca2b2b4e9..994b6e891a 100644 --- a/crates/engine/src/cmd/artboard_cmds/file_types_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/file_types_tests.rs @@ -7,7 +7,7 @@ use super::*; /// Layers panel, then Blue Board 200 x 200, then an empty transparent board on top. 300 ppi, so /// a page sized from the document resolution would not be 72 ppi. fn boards() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400, "name": "abfiles-test", "background": "transparent"})).unwrap(); for (name, rect, bg) in [ ("Red Board", [0, 0, 200, 150], json!({"background": "custom", "color": "#ff0000"})), @@ -171,7 +171,7 @@ fn unknown_format_is_an_error_and_writes_nothing() { /// empty buffer (`region data length mismatch`). #[test] fn oversized_board_is_a_bad_params_error_for_png8_and_pdf() { - let mut s = Session::new(); + let mut s = crate::session(); let mut doc = Document::new("huge", Size::new(40_000, 40_000), ColorMode::Rgb, SampleType::U8); let mut board = Layer::group("Huge Board", Vec::new()); if let LayerContent::Group(g) = &mut board.content { diff --git a/crates/engine/src/cmd/artboard_cmds/first_board_background_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/first_board_background_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/first_board_background_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/first_board_background_tests.rs index 5d1f50206f..6accde7455 100644 --- a/crates/engine/src/cmd/artboard_cmds/first_board_background_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/first_board_background_tests.rs @@ -6,7 +6,7 @@ use photocraft_geom::Rect; /// 800 x 600 with the white Background and a pixel layer "Red" at 100,100 to 300,250. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "depth": depth, "background": "white"})).unwrap(); s.edit("Red", |doc, active| { let fmt = doc.pixel_format(); diff --git a/crates/engine/src/cmd/artboard_cmds/from_group_hidden_bounds_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/from_group_hidden_bounds_tests.rs similarity index 98% rename from crates/engine/src/cmd/artboard_cmds/from_group_hidden_bounds_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/from_group_hidden_bounds_tests.rs index 3a1e7e34c6..2ea364c50e 100644 --- a/crates/engine/src/cmd/artboard_cmds/from_group_hidden_bounds_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/from_group_hidden_bounds_tests.rs @@ -17,7 +17,7 @@ fn square(doc: &Document, name: &str, r: Rect, rgba: [f32; 4]) -> Layer { /// 800 x 600 with the white Background and "Group 1" holding Blue above Red; with `inner`, Blue /// sits in its own group "Inner". Returns the session and the ids of Group 1, Red and Blue. fn session(inner: bool) -> (Session, [LayerId; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); let ids = s .edit("Group 1", |doc, active| { @@ -94,7 +94,7 @@ fn a_hidden_group_inside_hides_its_children_too() { #[test] fn a_group_with_every_layer_hidden_is_handled_like_an_empty_group() { - let mut empty = Session::new(); + let mut empty = crate::session(); empty.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); let e = empty.edit("Group 1", |doc, _| Ok(doc.insert_above(None, Layer::group("Group 1", vec![])))).unwrap(); let today = from_group(&mut empty, e); diff --git a/crates/engine/src/cmd/artboard_cmds/from_group_reset_props_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/from_group_reset_props_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/from_group_reset_props_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/from_group_reset_props_tests.rs index 2fec3f2be1..63051bbca3 100644 --- a/crates/engine/src/cmd/artboard_cmds/from_group_reset_props_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/from_group_reset_props_tests.rs @@ -9,7 +9,7 @@ use photocraft_doc::LayerMask; /// 200 x 200 with a top-level group "Group" (one child "Red" with pixels) that has the given /// blend, opacity, fill opacity and an optional mask. fn session_with_group(blend: BlendMode, opacity: f32, fill_opacity: f32, mask: bool) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "depth": 8, "background": "white"})).unwrap(); let gid = s .edit("Group", |doc, active| { diff --git a/crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/from_layers_history_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/from_layers_history_name_tests.rs index 34dbe6d306..ee6f3befbf 100644 --- a/crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/from_layers_history_name_tests.rs @@ -5,7 +5,7 @@ use photocraft_geom::Rect; /// 100 x 80 RGB at `depth` with a pixel layer "Red" holding a square at 10,10 to 30,30. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "depth": depth, "background": "white"})).unwrap(); s.edit("Red", |doc, active| { let fmt = doc.pixel_format(); diff --git a/crates/engine/src/cmd/artboard_cmds/include_name_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/include_name_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/include_name_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/include_name_tests.rs index 228cbf022e..c3af277594 100644 --- a/crates/engine/src/cmd/artboard_cmds/include_name_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/include_name_tests.rs @@ -11,7 +11,7 @@ const RED: [f32; 4] = [220.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0, 1.0]; /// The spec's test document: 800 x 400, transparent, `Red Board` 0,0-200,150 (white, a red /// layer at 20,20-120,100) and `Blue Board` 120,30-320,230 (white, a blue layer at 130,40-230,140). fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400, "depth": depth, "background": "transparent"})).unwrap(); board(&mut s, "Red Board", [0, 0, 200, 150], Rect::new(20, 20, 120, 100), RED); board(&mut s, "Blue Board", [120, 30, 200, 200], Rect::new(130, 40, 230, 140), [30.0 / 255.0, 30.0 / 255.0, 220.0 / 255.0, 1.0]); diff --git a/crates/engine/src/cmd/artboard_cmds/overlapping_areas_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/overlapping_areas_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/overlapping_areas_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/overlapping_areas_tests.rs index 9dcabef043..603a272d78 100644 --- a/crates/engine/src/cmd/artboard_cmds/overlapping_areas_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/overlapping_areas_tests.rs @@ -13,7 +13,7 @@ const WHITE: [u8; 3] = [255, 255, 255]; /// (pixel layer `Red` at 20,20-120,100), `Blue Board` 120,30-320,230 (pixel layer `Blue` at /// 130,40-230,140) and `Empty Board` 600,0-700,100, all with white backgrounds. fn session(depth: u32) -> (Session, [u64; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400, "depth": depth, "background": "transparent"})).unwrap(); let board = |s: &mut Session, name: &str, rect: [i64; 4]| s.execute("layer.new.artboard", json!({"rect": rect, "name": name})).unwrap()["layer"].as_u64().unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/pdf_document_per_artboard_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/pdf_document_per_artboard_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/pdf_document_per_artboard_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/pdf_document_per_artboard_tests.rs index 2b2a6f6bbd..b9ef5a5460 100644 --- a/crates/engine/src/cmd/artboard_cmds/pdf_document_per_artboard_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/pdf_document_per_artboard_tests.rs @@ -10,7 +10,7 @@ const MEASURED: [(&str, [u32; 4]); 3] = [("Red Board", [0, 0, 200, 150]), ("Blue /// The issue's test document: 800 x 400, RGB, 8 bit, 72 ppi, named `abpdf-test`, with `boards` /// added bottom to top. fn session(boards: &[(&str, [u32; 4])]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"name": "abpdf-test", "width": 800, "height": 400, "depth": 8, "resolution": 72})).unwrap(); for (name, rect) in boards { s.execute("layer.new.artboard", json!({"rect": rect, "name": name})).unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/pdf_include_background_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/pdf_include_background_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/pdf_include_background_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/pdf_include_background_tests.rs index cf9d883e73..345d1aeb3b 100644 --- a/crates/engine/src/cmd/artboard_cmds/pdf_include_background_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/pdf_include_background_tests.rs @@ -14,7 +14,7 @@ use super::*; /// The issue's document at `depth` bits. Returns the session and the ids of Red, Blue and Empty /// Board. fn session(depth: u32) -> (Session, [u64; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"name": "abpdf-test", "width": 800, "height": 400, "depth": depth, "background": "transparent"})).unwrap(); let mut board = |name: &str, rect: [u32; 4], layer: Option<(&str, [u32; 4], &str)>| { let id = s.execute("layer.new.artboard", json!({"name": name, "rect": rect, "background": "white"})).unwrap()["layer"].as_u64().unwrap(); @@ -180,7 +180,7 @@ fn unticked_every_page_with_layers_is_masked_and_the_xref_still_points_at_object #[test] fn unticked_a_board_its_layer_covers_entirely_stays_opaque() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 200, "background": "transparent"})).unwrap(); let id = s.execute("layer.new.artboard", json!({"name": "Full", "rect": [0, 0, 120, 80]})).unwrap()["layer"].as_u64().unwrap(); s.execute("layer.select", json!({"layer": id})).unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/pdf_overlapping_areas_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/pdf_overlapping_areas_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/pdf_overlapping_areas_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/pdf_overlapping_areas_tests.rs index 0f55e3518e..4885213edf 100644 --- a/crates/engine/src/cmd/artboard_cmds/pdf_overlapping_areas_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/pdf_overlapping_areas_tests.rs @@ -14,7 +14,7 @@ const CMD: &str = "file.export.artboardsToPdf"; /// (pixel layer `Red` at 20,20-120,100), `Blue Board` 120,30-320,230 (pixel layer `Blue` at /// 130,40-230,140) and `Empty Board` 600,0-700,100, all with white backgrounds. fn session(depth: u32) -> (Session, [u64; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400, "depth": depth, "background": "transparent"})).unwrap(); let board = |s: &mut Session, name: &str, rect: [i64; 4]| s.execute("layer.new.artboard", json!({"rect": rect, "name": name})).unwrap()["layer"].as_u64().unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/pdf_page_order_tests.rs similarity index 98% rename from crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/pdf_page_order_tests.rs index 0541f8e456..820459f1dc 100644 --- a/crates/engine/src/cmd/artboard_cmds/pdf_page_order_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/pdf_page_order_tests.rs @@ -5,7 +5,7 @@ use super::*; /// The measured document, and the ids of Red, Blue and Empty Board (bottom to top). fn session() -> (Session, [u64; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400, "depth": 8, "resolution": 72})).unwrap(); let mut board = |rect: [i64; 4], name: &str| { let r = s.execute("layer.new.artboard", json!({"rect": rect, "name": name})).unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/pdf_reverse_page_order_tests.rs b/crates/engine-core/src/cmd/artboard_cmds/pdf_reverse_page_order_tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/pdf_reverse_page_order_tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/pdf_reverse_page_order_tests.rs index b3009e1251..11b2f720cf 100644 --- a/crates/engine/src/cmd/artboard_cmds/pdf_reverse_page_order_tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/pdf_reverse_page_order_tests.rs @@ -6,7 +6,7 @@ use super::*; /// The measured document, and the ids of Red, Blue and Empty Board (bottom to top). fn session() -> (Session, [u64; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400, "depth": 8, "resolution": 72})).unwrap(); let mut board = |rect: [i64; 4], name: &str| { let r = s.execute("layer.new.artboard", json!({"rect": rect, "name": name})).unwrap(); diff --git a/crates/engine/src/cmd/artboard_cmds/tests.rs b/crates/engine-core/src/cmd/artboard_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/artboard_cmds/tests.rs rename to crates/engine-core/src/cmd/artboard_cmds/tests.rs index ec43601104..91d2f438ba 100644 --- a/crates/engine/src/cmd/artboard_cmds/tests.rs +++ b/crates/engine-core/src/cmd/artboard_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_geom::Rect; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "depth": depth})).unwrap(); s } @@ -593,7 +593,7 @@ fn moving_an_artboard_past_the_canvas_keeps_its_shapes_whole() { // Partly past the edge: the whole shape, not just the part inside the old canvas. ("layer.artboard.set", json!({"x": 90}), (120, 100), [(91, 21), (95, 30), (110, 30)], Some((15, 30))), ] { - let mut s = Session::new(); + let mut s = crate::session(); let sh = shape_board(&mut s); s.execute(cmd, p.clone()).unwrap(); assert_eq!((doc(&s).size.width, doc(&s).size.height), size, "{cmd} {p}"); @@ -868,7 +868,7 @@ fn new_document_with_an_artboard() { ("transparent", ArtboardBackground::Transparent), ("#336699", ArtboardBackground::Custom(Color::rgba(0x33 as f32 / 255.0, 0x66 as f32 / 255.0, 0x99 as f32 / 255.0, 1.0))), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 90, "background": background, "artboard": true})).unwrap(); let d = doc(&s); assert_eq!(d.layers.len(), 1, "{background}: only the board"); @@ -881,7 +881,7 @@ fn new_document_with_an_artboard() { assert!(!d.layers.iter().any(|l| d.is_background(l.id)), "{background}: no Background layer"); } // Without the option nothing changes; a non-boolean is refused. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "artboard": false})).unwrap(); assert!(doc(&s).artboards().is_empty()); assert!(s.execute("file.new", json!({"artboard": "yes"})).is_err()); @@ -924,7 +924,7 @@ fn from_layers_defaults_are_the_selected_layers_size() { let mut s = session(8); s.execute("layer.new.layer", json!({})).unwrap(); assert_eq!(from_layers_defaults(&s), Some(("Artboard 1".to_string(), [100, 80])), "an empty layer: the canvas"); - assert_eq!(from_layers_defaults(&Session::new()), None); + assert_eq!(from_layers_defaults(&crate::session()), None); } /// #10258: with the active layer on an artboard (the board, or a layer inside it), Select All diff --git a/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs b/crates/engine-core/src/cmd/assign_profile_enabled_modes_tests.rs similarity index 97% rename from crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs rename to crates/engine-core/src/cmd/assign_profile_enabled_modes_tests.rs index 8a3b3a09b6..7d74a74942 100644 --- a/crates/engine/src/cmd/assign_profile_enabled_modes_tests.rs +++ b/crates/engine-core/src/cmd/assign_profile_enabled_modes_tests.rs @@ -12,7 +12,7 @@ const CMD: &str = "edit.assignProfile"; /// A white document of `mode` (as `file.new` names it) at `depth` bits. fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "mode": mode, "depth": depth, "background": "white"})).unwrap(); s } @@ -32,7 +32,7 @@ fn assert_refused(s: &mut Session, what: &str) { #[test] fn no_document_greys_it_out() { - assert_refused(&mut Session::new(), "no document"); + assert_refused(&mut crate::session(), "no document"); } #[test] diff --git a/crates/engine/src/cmd/atn_cmds.rs b/crates/engine-core/src/cmd/atn_cmds.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds.rs rename to crates/engine-core/src/cmd/atn_cmds.rs diff --git a/crates/engine/src/cmd/atn_cmds/adjustments.rs b/crates/engine-core/src/cmd/atn_cmds/adjustments.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/adjustments.rs rename to crates/engine-core/src/cmd/atn_cmds/adjustments.rs diff --git a/crates/engine/src/cmd/atn_cmds/artboard_section_tests.rs b/crates/engine-core/src/cmd/atn_cmds/artboard_section_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/artboard_section_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/artboard_section_tests.rs index 6695f9a1e8..e9005169a2 100644 --- a/crates/engine/src/cmd/atn_cmds/artboard_section_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/artboard_section_tests.rs @@ -64,7 +64,7 @@ fn load(items: Vec) -> (Session, Value) { actions: vec![AtnAction { name: UnicodeString::new_nul("A"), items, ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&atn::write(&file).unwrap())})).unwrap(); (s, r) } diff --git a/crates/engine/src/cmd/atn_cmds/automate_tests.rs b/crates/engine-core/src/cmd/atn_cmds/automate_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/automate_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/automate_tests.rs index d930b11183..9e4e438d3b 100644 --- a/crates/engine/src/cmd/atn_cmds/automate_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/automate_tests.rs @@ -28,7 +28,7 @@ fn load(items: Vec) -> (Session, Value) { actions: vec![AtnAction { name: UnicodeString::new_nul("A"), items, ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&atn::write(&file).unwrap())})).unwrap(); (s, r) } diff --git a/crates/engine/src/cmd/atn_cmds/canvas_size_default_anchor_tests.rs b/crates/engine-core/src/cmd/atn_cmds/canvas_size_default_anchor_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/canvas_size_default_anchor_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/canvas_size_default_anchor_tests.rs index 55f3b9dbb3..09e836d5d3 100644 --- a/crates/engine/src/cmd/atn_cmds/canvas_size_default_anchor_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/canvas_size_default_anchor_tests.rs @@ -20,7 +20,7 @@ fn canvas_file(descriptor: Descriptor) -> Vec { /// The 400 x 300 test document: a white Background with a red square at the top left and a blue /// one at the bottom right, plus a layer "Top" with a green 50 x 50 square in the middle. fn test_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Top"})).unwrap(); s.edit("paint", |doc, _| { diff --git a/crates/engine/src/cmd/atn_cmds/convert.rs b/crates/engine-core/src/cmd/atn_cmds/convert.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/convert.rs rename to crates/engine-core/src/cmd/atn_cmds/convert.rs diff --git a/crates/engine/src/cmd/atn_cmds/descriptors.rs b/crates/engine-core/src/cmd/atn_cmds/descriptors.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/descriptors.rs rename to crates/engine-core/src/cmd/atn_cmds/descriptors.rs diff --git a/crates/engine/src/cmd/atn_cmds/events.rs b/crates/engine-core/src/cmd/atn_cmds/events.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/events.rs rename to crates/engine-core/src/cmd/atn_cmds/events.rs diff --git a/crates/engine/src/cmd/atn_cmds/fade_step_tests.rs b/crates/engine-core/src/cmd/atn_cmds/fade_step_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/fade_step_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/fade_step_tests.rs index 2da2d037f2..2e47f55749 100644 --- a/crates/engine/src/cmd/atn_cmds/fade_step_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/fade_step_tests.rs @@ -27,7 +27,7 @@ fn imported(descriptor: Descriptor) -> (String, f64, String) { /// An 8 x 8 image, inverted so there is an edit to fade. fn inverted(depth: u8) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8,"depth":depth,"background":"transparent"})).unwrap(); s.execute("edit.fill", json!({"contents":"color","color":"#4080c0"})).unwrap(); s.execute("image.adjustments.invert", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/atn_cmds/fields.rs b/crates/engine-core/src/cmd/atn_cmds/fields.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/fields.rs rename to crates/engine-core/src/cmd/atn_cmds/fields.rs diff --git a/crates/engine/src/cmd/atn_cmds/files.rs b/crates/engine-core/src/cmd/atn_cmds/files.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/files.rs rename to crates/engine-core/src/cmd/atn_cmds/files.rs diff --git a/crates/engine/src/cmd/atn_cmds/files/replacement.rs b/crates/engine-core/src/cmd/atn_cmds/files/replacement.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/files/replacement.rs rename to crates/engine-core/src/cmd/atn_cmds/files/replacement.rs diff --git a/crates/engine/src/cmd/atn_cmds/frame_section_tests.rs b/crates/engine-core/src/cmd/atn_cmds/frame_section_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/frame_section_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/frame_section_tests.rs index 9093683f75..be71cfde3c 100644 --- a/crates/engine/src/cmd/atn_cmds/frame_section_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/frame_section_tests.rs @@ -48,7 +48,7 @@ fn load(ds: Vec) -> (Session, Value) { actions: vec![AtnAction { name: UnicodeString::new_nul("A"), items: items.collect(), ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&atn::write(&file).unwrap())})).unwrap(); (s, r) } @@ -163,7 +163,7 @@ fn a_loaded_step_plays_with_no_layer_selected() { /// Without a layer of its own the command still frames the selected layers. #[test] fn without_a_layer_the_selected_layers_are_framed() { - let mut s = Session::new(); + let mut s = crate::session(); let (photo, other) = two_layers(&mut s); s.execute(FRAME, json!({"name": "Frame 1"})).unwrap(); assert_eq!(frames(&s, "Frame 1").into_iter().map(|f| f.1).collect::>(), vec![[60.0, 5.0, 30.0, 20.0]]); diff --git a/crates/engine/src/cmd/atn_cmds/layer_list_tests.rs b/crates/engine-core/src/cmd/atn_cmds/layer_list_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/layer_list_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/layer_list_tests.rs index 425b177b7c..ea4a62c3de 100644 --- a/crates/engine/src/cmd/atn_cmds/layer_list_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/layer_list_tests.rs @@ -13,7 +13,7 @@ fn item(event: &str, label: &str, d: Option) -> AtnItem { } fn two_layers() -> (Session, u64, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute("layer.new.layer", json!({"name": "First"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Second"})).unwrap(); diff --git a/crates/engine/src/cmd/atn_cmds/layer_props_tests.rs b/crates/engine-core/src/cmd/atn_cmds/layer_props_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/layer_props_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/layer_props_tests.rs index cd4c2ac729..eeae01c35e 100644 --- a/crates/engine/src/cmd/atn_cmds/layer_props_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/layer_props_tests.rs @@ -114,7 +114,7 @@ fn expanded_properties_replay_like_direct_edits_at_every_depth() { for depth in [8, 16, 32] { for named in [false, true] { let prepare = || { - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"width": 2, "height": 2, "depth": depth})).unwrap(); session.execute("layer.new.layer", json!({"name": "Original"})).unwrap(); session.execute("layer.new.layer", json!({"name": "Other"})).unwrap(); diff --git a/crates/engine/src/cmd/atn_cmds/measurement_tests.rs b/crates/engine-core/src/cmd/atn_cmds/measurement_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/measurement_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/measurement_tests.rs index 35aa8272f2..1d1096a11f 100644 --- a/crates/engine/src/cmd/atn_cmds/measurement_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/measurement_tests.rs @@ -35,7 +35,7 @@ fn load(items: Vec) -> (Session, Value) { actions: vec![AtnAction { name: UnicodeString::new_nul("A"), items, ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&atn::write(&file).unwrap())})).unwrap(); (s, r) } diff --git a/crates/engine/src/cmd/atn_cmds/menu_item.rs b/crates/engine-core/src/cmd/atn_cmds/menu_item.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/menu_item.rs rename to crates/engine-core/src/cmd/atn_cmds/menu_item.rs diff --git a/crates/engine/src/cmd/atn_cmds/mode_change_tests.rs b/crates/engine-core/src/cmd/atn_cmds/mode_change_tests.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/mode_change_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/mode_change_tests.rs diff --git a/crates/engine/src/cmd/atn_cmds/path_tests.rs b/crates/engine-core/src/cmd/atn_cmds/path_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/path_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/path_tests.rs index b54bde4c8a..d536857589 100644 --- a/crates/engine/src/cmd/atn_cmds/path_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/path_tests.rs @@ -116,7 +116,7 @@ fn whole_atn_and_native_insert_path_replay_keep_geometry() { assert!(skipped.is_empty()); assert_eq!(atn::parse(&bytes).unwrap().actions[0].items[0].descriptor, Some(original.clone())); let expected = path_from(&original).unwrap(); - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":400,"height":300})).unwrap(); s.execute("path.set", json!({"name":"Source","path":crate::vector_cmds::path_json(&expected)})).unwrap(); s.actions.list.push(Action::new("Captured", Vec::new())).unwrap(); diff --git a/crates/engine/src/cmd/atn_cmds/recorded_tools_tests.rs b/crates/engine-core/src/cmd/atn_cmds/recorded_tools_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/recorded_tools_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/recorded_tools_tests.rs index d6bb9ed0c6..2eae59c50b 100644 --- a/crates/engine/src/cmd/atn_cmds/recorded_tools_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/recorded_tools_tests.rs @@ -65,7 +65,7 @@ fn gradient_tool_steps_load_play_and_save_back() { .with("null", target_ref("contentLayer")) .with("T ", D::Descriptor(tool_gradient(-35.0, 140.0, (12.5, -8.0)).with("Algn", D::Boolean(false)))); let items = vec![step(b"Mk ", "Make", make.clone()), step(b"setd", "Set", set.clone())]; - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&action(items))})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); let ids: Vec<&str> = s.actions.list.actions()[0].steps.iter().map(|st| st.command.as_str()).collect(); @@ -115,7 +115,7 @@ fn create_droplet_step_loads_plays_and_saves_back() { let file = dir.join("Sharpen.pcdroplet").to_string_lossy().into_owned(); let out = dir.join("out").to_string_lossy().into_owned(); let recorded = droplet(&file, &out, &[("OvrO", D::Boolean(true))]); - let mut s = Session::new(); + let mut s = crate::session(); // The action the droplet runs. s.actions.list.push(crate::actions_cmds::Action::new("Sharpen", vec![ActionStep::new("filter.sharpen.sharpen", json!({}))])).unwrap(); s.actions.list.assign_set(0, Some("Tools".into())).unwrap(); @@ -204,7 +204,7 @@ fn create_droplet_steps_follow_a_renamed_loaded_action() { ..Default::default() }) .unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(crate::actions_cmds::Action::new("Sharpen", vec![])).unwrap(); s.actions.list.assign_set(0, Some("Tools".into())).unwrap(); let r = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&file), "set": "Loaded"})).unwrap(); diff --git a/crates/engine/src/cmd/atn_cmds/render_tests.rs b/crates/engine-core/src/cmd/atn_cmds/render_tests.rs similarity index 98% rename from crates/engine/src/cmd/atn_cmds/render_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/render_tests.rs index 16e772c174..5a9e6160a8 100644 --- a/crates/engine/src/cmd/atn_cmds/render_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/render_tests.rs @@ -65,7 +65,7 @@ fn code_spellings_in_text_steps_keep_their_bytes_and_flags() { original.actions[0].items[0].with_dialog = true; original.actions[0].items[0].dialog_options = 2; let bytes = atn::write(&original).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&bytes)})).unwrap(); assert_eq!(loaded["unsupported"].as_array().unwrap().len(), 1, "{:?}", original.actions[0].items[0].event); assert_eq!(s.actions.list.actions()[0].steps[0].command, PHOTOSHOP_STEP); @@ -114,7 +114,7 @@ fn clouds_events_map_and_refuse_unrepresentable_native_settings() { #[test] fn clouds_recorded_through_the_dialog_save() { for id in ["filter.render.clouds", "filter.render.differenceClouds"] { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Render", vec![ActionStep::new(id, json!({"seed": 0}))])).unwrap(); let saved = s.execute("actions.save", json!({"action": "Render"})).unwrap(); assert_eq!(saved["skipped"], json!([]), "{id}"); @@ -140,7 +140,7 @@ fn render_descriptors_load_and_save_without_losing_values() { events.push(AtnEvent::name(name)); } for event in events { - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&file(event, descriptor.clone()))})).unwrap(); assert_eq!(loaded["unsupported"], json!([])); let saved = s.execute("actions.save", json!({"action": "Render"})).unwrap(); @@ -240,7 +240,7 @@ fn duplicate_render_keys_keep_their_bytes_and_flags() { original.actions[0].items[0].with_dialog = true; original.actions[0].items[0].dialog_options = 2; let bytes = atn::write(&original).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": photocraft_paint::tile::b64_encode(&bytes)})).unwrap(); assert_eq!(loaded["unsupported"].as_array().unwrap().len(), 1, "{event}/{key}"); assert_eq!(s.actions.list.actions()[0].steps[0].command, PHOTOSHOP_STEP); @@ -271,7 +271,7 @@ fn render_actions_match_direct_filters_and_undo() { for depth in [8, 16, 32] { for (event, descriptor, id, params) in &cases { let setup = || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 6, "mode": mode, "depth": depth, "background": "transparent"})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#304050"})).unwrap(); s.execute("tools.setColors", json!({"foreground": "#fe1020", "background": "#1050e0"})).unwrap(); diff --git a/crates/engine/src/cmd/atn_cmds/selection_tests.rs b/crates/engine-core/src/cmd/atn_cmds/selection_tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/selection_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/selection_tests.rs index 4b780f70b9..9be4a0c6f4 100644 --- a/crates/engine/src/cmd/atn_cmds/selection_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/selection_tests.rs @@ -77,7 +77,7 @@ fn group_f_load_save_preserves_recorded_descriptors() { events.push(AtnEvent::name(name)); } for event in events { - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data":photocraft_paint::tile::b64_encode(&file(event.clone(),d.clone()))})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{id}"); let saved = s.execute("actions.save", json!({"action":"Step"})).unwrap(); @@ -95,7 +95,7 @@ fn assert_kept(id: &str, name: Option<&str>, descriptor: Descriptor) { original.actions[0].items[0].enabled = false; original.actions[0].items[0].with_dialog = true; original.actions[0].items[0].dialog_options = 2; - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data":photocraft_paint::tile::b64_encode(&atn::write(&original).unwrap())})).unwrap(); assert_eq!(loaded["unsupported"].as_array().unwrap().len(), 1, "{id}/{name:?}/{descriptor:?}"); assert_eq!(s.actions.list.actions()[0].steps[0].command, PHOTOSHOP_STEP); @@ -358,7 +358,7 @@ fn play(s: &mut Session, event: AtnEvent, d: Descriptor) -> Value { /// A small image with real pixels; all witnesses operate through the public command boundary. fn image(depth: u8) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8,"depth":depth,"background":"transparent"})).unwrap(); s.execute("edit.fill", json!({"contents":"color","color":"#4080c0"})).unwrap(); s @@ -434,7 +434,7 @@ fn fade_action_consumes_the_previous_edit_and_fails_without_it() { assert!(result.get("failed").is_none(), "{result}"); assert_eq!(s.execute("document.pixel", json!({"x":3,"y":3})).unwrap(), before); } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8})).unwrap(); let before = s.active().unwrap().doc.clone(); let result = play(&mut s, AtnEvent::Code(*b"Fade"), desc("null").with("Opct", pct(50.0)).with("Md ", enm("BlnM", "Mltp"))); diff --git a/crates/engine/src/cmd/atn_cmds/steps_artboard.rs b/crates/engine-core/src/cmd/atn_cmds/steps_artboard.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_artboard.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_artboard.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_artboard_section.rs b/crates/engine-core/src/cmd/atn_cmds/steps_artboard_section.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_artboard_section.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_artboard_section.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_automate.rs b/crates/engine-core/src/cmd/atn_cmds/steps_automate.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_automate.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_automate.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_batch.rs b/crates/engine-core/src/cmd/atn_cmds/steps_batch.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_batch.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_batch.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_calculations.rs b/crates/engine-core/src/cmd/atn_cmds/steps_calculations.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_calculations.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_calculations.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_channels.rs b/crates/engine-core/src/cmd/atn_cmds/steps_channels.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_channels.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_channels.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_content_aware.rs b/crates/engine-core/src/cmd/atn_cmds/steps_content_aware.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_content_aware.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_content_aware.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_direct_adjustments.rs b/crates/engine-core/src/cmd/atn_cmds/steps_direct_adjustments.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_direct_adjustments.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_direct_adjustments.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_distort.rs b/crates/engine-core/src/cmd/atn_cmds/steps_distort.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_distort.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_distort.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_doc.rs b/crates/engine-core/src/cmd/atn_cmds/steps_doc.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_doc.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_doc.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_droplet.rs b/crates/engine-core/src/cmd/atn_cmds/steps_droplet.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_droplet.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_droplet.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_frame_section.rs b/crates/engine-core/src/cmd/atn_cmds/steps_frame_section.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_frame_section.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_frame_section.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_gallery.rs b/crates/engine-core/src/cmd/atn_cmds/steps_gallery.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_gallery.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_gallery.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_gradient.rs b/crates/engine-core/src/cmd/atn_cmds/steps_gradient.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_gradient.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_gradient.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_image.rs b/crates/engine-core/src/cmd/atn_cmds/steps_image.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_image.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_image.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_layer.rs b/crates/engine-core/src/cmd/atn_cmds/steps_layer.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_layer.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_layer.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_layer_style.rs b/crates/engine-core/src/cmd/atn_cmds/steps_layer_style.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_layer_style.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_layer_style.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_lookup.rs b/crates/engine-core/src/cmd/atn_cmds/steps_lookup.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_lookup.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_lookup.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_make.rs b/crates/engine-core/src/cmd/atn_cmds/steps_make.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_make.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_make.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_measurement.rs b/crates/engine-core/src/cmd/atn_cmds/steps_measurement.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_measurement.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_measurement.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_mode_change.rs b/crates/engine-core/src/cmd/atn_cmds/steps_mode_change.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_mode_change.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_mode_change.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_other.rs b/crates/engine-core/src/cmd/atn_cmds/steps_other.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_other.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_other.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_path.rs b/crates/engine-core/src/cmd/atn_cmds/steps_path.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_path.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_path.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_perspective_warp.rs b/crates/engine-core/src/cmd/atn_cmds/steps_perspective_warp.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_perspective_warp.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_perspective_warp.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_render.rs b/crates/engine-core/src/cmd/atn_cmds/steps_render.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_render.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_render.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_selection.rs b/crates/engine-core/src/cmd/atn_cmds/steps_selection.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_selection.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_selection.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs b/crates/engine-core/src/cmd/atn_cmds/steps_shape_blur.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_shape_blur.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_shape_blur.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_stack.rs b/crates/engine-core/src/cmd/atn_cmds/steps_stack.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_stack.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_stack.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_stylize.rs b/crates/engine-core/src/cmd/atn_cmds/steps_stylize.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_stylize.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_stylize.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_type_path.rs b/crates/engine-core/src/cmd/atn_cmds/steps_type_path.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_type_path.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_type_path.rs diff --git a/crates/engine/src/cmd/atn_cmds/steps_video.rs b/crates/engine-core/src/cmd/atn_cmds/steps_video.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/steps_video.rs rename to crates/engine-core/src/cmd/atn_cmds/steps_video.rs diff --git a/crates/engine/src/cmd/atn_cmds/stylize_tests.rs b/crates/engine-core/src/cmd/atn_cmds/stylize_tests.rs similarity index 98% rename from crates/engine/src/cmd/atn_cmds/stylize_tests.rs rename to crates/engine-core/src/cmd/atn_cmds/stylize_tests.rs index 8ea206b704..fa0db81272 100644 --- a/crates/engine/src/cmd/atn_cmds/stylize_tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/stylize_tests.rs @@ -138,7 +138,7 @@ pub(super) fn load_items(items: Vec) -> Session { ..Default::default() }; let bytes = atn::write(&file).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.load", json!({"data":photocraft_paint::tile::b64_encode(&bytes)})).unwrap(); s } @@ -227,7 +227,7 @@ fn trace_levels_clamp_on_import_and_play_at_the_boundary() { assert_eq!(saved[0].descriptor.as_ref().unwrap().to_bytes(), expected.to_bytes()); assert!(saved[0].with_dialog); for depth in [8, 16, 32] { - let mut direct = Session::new(); + let mut direct = crate::session(); prepare_pattern(&mut imported, depth, "rgb"); prepare_pattern(&mut direct, depth, "rgb"); let played = imported.execute("actions.play", json!({"action":"A"})).unwrap(); @@ -336,7 +336,7 @@ fn exports_materialize_native_defaults_and_reject_unrepresentable_settings() { } let mut params = fixture.defaults.clone(); params[key] = value; - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", vec![ActionStep::new(fixture.id, params)])).unwrap(); assert!(s.execute("actions.save", json!({"action":"A"})).is_err(), "{}/{key}", fixture.id); } @@ -376,7 +376,7 @@ fn imported_group_d_playback_matches_direct_commands_across_modes_and_depths() { imported.actions.list.set_step(0, 10, false).unwrap(); imported.actions.list.set_dialog(0, 0, true).unwrap(); let steps = imported.actions.list.actions()[0].steps.clone(); - let mut direct = Session::new(); + let mut direct = crate::session(); for s in [&mut imported, &mut direct] { prepare_pattern(s, depth, mode); } @@ -444,7 +444,7 @@ fn native_and_measured_defaults_stay_distinct_through_playback() { for id in ["filter.pixelate.mosaic", "filter.stylize.traceContour"] { let item = export_item(id, &json!({}), "Group D").unwrap(); let mut imported = load_items(vec![item]); - let mut native = Session::new(); + let mut native = crate::session(); prepare_pattern(&mut imported, 8, "rgb"); prepare_pattern(&mut native, 8, "rgb"); native.execute(id, json!({})).unwrap(); @@ -465,7 +465,7 @@ fn tiles_and_pointillize_exports_drop_dialog_colours() { coloured["foreground"] = json!([0.2, 0.4, 0.6, 1.0]); coloured["background"] = json!("#ffffff"); assert_eq!(export_item(id, &coloured, "Group D").unwrap().descriptor, plain, "{id}"); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", vec![ActionStep::new(id, coloured)])).unwrap(); assert!(s.execute("actions.save", json!({"action":"A"})).is_ok(), "{id}"); } diff --git a/crates/engine/src/cmd/atn_cmds/tables.rs b/crates/engine-core/src/cmd/atn_cmds/tables.rs similarity index 100% rename from crates/engine/src/cmd/atn_cmds/tables.rs rename to crates/engine-core/src/cmd/atn_cmds/tables.rs diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine-core/src/cmd/atn_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/atn_cmds/tests.rs rename to crates/engine-core/src/cmd/atn_cmds/tests.rs index 59a7a66b16..0746040998 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine-core/src/cmd/atn_cmds/tests.rs @@ -300,7 +300,7 @@ fn layer_comp_apply_imports_plays_and_undoes() { let name = "合成 𠮷"; let data = set_of("Comps", vec![("Apply", vec![item("applyComp", "Apply Layer Comp", Some(desc("null").with("null", name_ref("compsClass", name))))])]); for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); assert_eq!(s.actions.list.actions()[0].steps, [ActionStep::new("layerComp.apply", json!({"comp": name}))]); @@ -334,7 +334,7 @@ fn layer_comp_apply_round_trips_by_name() { for name in ["Comp 1", "合成 𠮷"] { let descriptor = desc("null").with("null", name_ref("compsClass", name)); let data = set_of("Comps", vec![("Apply", vec![item("applyComp", "Apply Layer Comp", Some(descriptor.clone()))])]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); let saved = s.execute("actions.save", json!({"set": "Comps"})).unwrap(); @@ -343,7 +343,7 @@ fn layer_comp_apply_round_trips_by_name() { let file = atn::parse(&bytes).unwrap(); assert_eq!(file.actions[0].items[0].event, AtnEvent::Name("applyComp".into())); assert_eq!(file.actions[0].items[0].descriptor, Some(descriptor)); - let mut reloaded = Session::new(); + let mut reloaded = crate::session(); reloaded.execute("actions.load", json!({"data": saved["data"]})).unwrap(); assert_eq!(reloaded.actions.list.actions(), s.actions.list.actions()); } @@ -371,7 +371,7 @@ fn layer_comp_apply_unknown_references_are_kept_and_stop_playback() { let items: Vec<_> = references.into_iter().map(|reference| item("applyComp", "Apply Layer Comp", reference.map(|r| desc("null").with("null", r)))).collect(); let data = set_of("Comps", vec![("Unknown", items.clone())]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(loaded["unsupported"].as_array().unwrap().len(), items.len()); assert!(s.actions.list.actions()[0].steps.iter().all(|st| st.command == PHOTOSHOP_STEP)); @@ -395,7 +395,7 @@ fn layer_comp_apply_unknown_references_are_kept_and_stop_playback() { #[test] fn load_maps_events_keeps_flags_and_plays() { - let mut s = Session::new(); + let mut s = crate::session(); let bytes = atn::write(&sample()).unwrap(); let r = s.execute("actions.load", json!({"data": b64(&bytes)})).unwrap(); assert_eq!(r["set"], "Test Set"); @@ -462,7 +462,7 @@ fn load_maps_events_keeps_flags_and_plays() { /// copy of the action it named. #[test] fn load_renames_each_play_target_once() { - let mut s = Session::new(); + let mut s = crate::session(); let mut mine = Action::new("A", vec![]); mine.set = Some("Mine".into()); s.actions.list.push(mine).unwrap(); @@ -479,7 +479,7 @@ fn load_renames_each_play_target_once() { assert_eq!(r["functionKeys"], json!([{"action": "A 3", "key": "F4"}])); // Adding to a set of the same name leaves the Play steps already in it alone. - let mut s = Session::new(); + let mut s = crate::session(); for (name, steps) in [("A", vec![]), ("B", vec![ActionStep::new("actions.play", json!({"action": "A"}))])] { let mut a = Action::new(name, steps); a.set = Some("File".into()); @@ -495,7 +495,7 @@ fn load_renames_each_play_target_once() { /// so a rename still finds its Play target. #[test] fn load_renames_play_targets_longer_than_the_name_limit() { - let mut s = Session::new(); + let mut s = crate::session(); let long = "x".repeat(2000); let clipped = "x".repeat(1024); let mut mine = Action::new(clipped.clone(), vec![]); @@ -514,7 +514,7 @@ fn load_renames_play_targets_longer_than_the_name_limit() { /// set name read from the file. #[test] fn load_clips_an_overlong_set_override() { - let mut s = Session::new(); + let mut s = crate::session(); let actions: Vec = (0..3).map(|i| Action::new(format!("A{i}"), vec![])).collect(); let refs: Vec<&Action> = actions.iter().collect(); let (bytes, _) = export("File", &refs, &[], false).unwrap(); @@ -529,7 +529,7 @@ fn load_clips_an_overlong_set_override() { fn load_many_duplicate_names_get_sequential_suffixes() { // Several actions share one base name. Deduplication must stay O(n) overall and produce // the sequence A, A 2, A 3, A 4 (the next-suffix cache cannot skip or repeat a number). - let mut s = Session::new(); + let mut s = crate::session(); let dupes: Vec = (0..4).map(|_| Action::new("A", vec![])).collect(); let refs: Vec<&Action> = dupes.iter().collect(); let (bytes, _) = export("File", &refs, &[], false).unwrap(); @@ -539,7 +539,7 @@ fn load_many_duplicate_names_get_sequential_suffixes() { #[test] fn save_round_trips_through_photoshop_events() { - let mut s = Session::new(); + let mut s = crate::session(); let bytes = atn::write(&sample()).unwrap(); s.execute("actions.load", json!({"data": b64(&bytes)})).unwrap(); let first = s.actions.list.actions().to_vec(); @@ -560,7 +560,7 @@ fn save_round_trips_through_photoshop_events() { assert_eq!(get_ref(file.actions[0].items[7].descriptor.as_ref().unwrap(), "null").unwrap().len(), 2); // Loading what was saved gives the same actions. - let mut t = Session::new(); + let mut t = crate::session(); t.execute("actions.load", json!({"data": b64(&saved)})).unwrap(); assert_eq!(t.actions.list.actions(), first); @@ -580,7 +580,7 @@ fn save_round_trips_through_photoshop_events() { #[test] fn a_selective_color_step_in_the_scalar_form_keeps_its_values() { let back = |params: Value| -> Value { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", vec![ActionStep::new("image.adjustments.selectiveColor", params)])).unwrap(); let r = s.execute("actions.save", json!({"action": "A"})).unwrap(); assert_eq!(r["skipped"], json!([])); @@ -608,7 +608,7 @@ fn a_selective_color_step_in_the_scalar_form_keeps_its_values() { // A channel the command would refuse is not quietly dropped: the step is refused too, since // writing it would export an adjustment that is not the one recorded. `null` is absent, as // the command reads it. - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", vec![ActionStep::new("image.adjustments.selectiveColor", json!({"colors": "reds", "cyan": "35"}))])).unwrap(); let e = s.execute("actions.save", json!({"action": "A"})).unwrap_err().to_string(); assert!(e.contains("image.adjustments.selectiveColor"), "{e}"); @@ -636,7 +636,7 @@ fn a_setting_the_event_cannot_hold_is_refused() { ("layer.setAdjustment", json!({"kind": "exposure", "layer": "Target_existing", "exposure": -0.75, "offset": 0.035, "gamma": 1.37})), ("layer.setAdjustment", json!({"kind": "exposure", "document": 2, "exposure": -0.75})), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", vec![ActionStep::new(id, params)])).unwrap(); let before = s.actions.list.actions()[0].steps.clone(); let e = s.execute("actions.save", json!({"action": "A"})).unwrap_err().to_string(); @@ -670,7 +670,7 @@ fn settings_at_the_value_the_event_plays_still_export() { ("image.adjustments.equalize", json!({"selectedAreaOnly": true})), ("image.adjustments.equalize", json!({})), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("A", vec![ActionStep::new(id, params.clone())])).unwrap(); let r = s.execute("actions.save", json!({"action": "A"})).unwrap_or_else(|e| panic!("{id} {params}: {e}")); assert_eq!(r["skipped"], json!([]), "{id} {params}"); @@ -681,6 +681,7 @@ fn settings_at_the_value_the_event_plays_still_export() { #[test] /// Each mapped command retains its parameters through its corresponding ATN descriptor. fn every_mapped_command_exports_and_imports_back() { + crate::install().unwrap(); let cases: Vec<(&str, Value)> = vec![ ( "edit.perspectiveWarp", @@ -1283,7 +1284,7 @@ fn bucket_round_trip(params: Value) -> Option { #[test] fn bucket_keeps_an_explicit_color_through_atn() { let fill = |params: &Value| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "#ffffff"})).unwrap(); s.execute("paint.bucket", params.clone()).unwrap(); let d = s.active().unwrap(); @@ -1490,7 +1491,7 @@ fn save_preserves_the_kind_of_unsupported_atn_events() { warnings: vec![], ..Default::default() }; - let mut session = Session::new(); + let mut session = crate::session(); session.execute("actions.load", json!({"data": b64(&atn::write(&source).unwrap())})).unwrap(); let saved = session.execute("actions.save", json!({"set": "S"})).unwrap(); let bytes = photocraft_paint::tile::b64_decode(saved["data"].as_str().unwrap()).unwrap(); @@ -1646,7 +1647,7 @@ fn crop_sides_in_other_units_are_refused_not_played_as_pixels() { #[test] fn step_commands_and_bad_params_fail_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); for p in [ json!({}), json!({"path": ""}), @@ -1687,7 +1688,7 @@ fn step_commands_and_bad_params_fail_gracefully() { #[test] fn save_writes_the_file_and_the_set_of_the_selected_action() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.load", json!({"data": b64(&atn::write(&sample()).unwrap())})).unwrap(); s.actions.list.push(Action::new("Loose", vec![ActionStep::new("select.all", json!({}))])).unwrap(); let dir = std::env::temp_dir().join(format!("pc-atn-{}", std::process::id())); @@ -1712,7 +1713,7 @@ fn save_writes_the_file_and_the_set_of_the_selected_action() { #[test] fn save_over_an_existing_file_never_rewrites_it_in_place() { use std::io::Read; - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Owned", vec![ActionStep::new("select.all", json!({}))])).unwrap(); let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("Owned.atn"); @@ -1733,7 +1734,7 @@ fn save_over_an_existing_file_never_rewrites_it_in_place() { #[test] fn layer_param_accepts_a_name() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "A"})).unwrap(); s.execute("layer.new.layer", json!({"name": "B"})).unwrap(); @@ -2015,7 +2016,7 @@ fn remaining_events_import_in_their_photoshop_shapes() { assert_eq!(path_text(&path_value("")), None); // Apply Image by layer name runs on a document; a missing name is a clear error. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "High-Frequency"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Top"})).unwrap(); @@ -2050,7 +2051,7 @@ fn select_document_by_offset_imports_plays_and_saves_back() { ]; let data = set_of("Template", vec![("Copy In", copy_in)]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "name": "source"})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#ff0000"})).unwrap(); s.execute("file.new", json!({"width": 8, "height": 8, "name": "template", "background": "transparent"})).unwrap(); @@ -2086,14 +2087,14 @@ fn select_document_by_offset_imports_plays_and_saves_back() { .collect(); assert_eq!(offsets, [-1, 1]); assert!(file.actions[0].items[0].descriptor.as_ref().unwrap().get("DocI").is_none()); - let mut t = Session::new(); + let mut t = crate::session(); t.execute("actions.load", json!({"data": b64(&saved)})).unwrap(); assert_eq!(t.actions.list.actions(), first); // An absolute tab index has no Photoshop equivalent: it stays out of a strict save. assert!(export_item("document.activate", &json!({"document": 0}), "S").is_none()); assert!(export_item("document.activate", &json!({"document": 0, "offset": 1}), "S").is_none()); - let mut one = Session::new(); + let mut one = crate::session(); one.execute("file.new", json!({"width": 8, "height": 8, "name": "template"})).unwrap(); one.execute("actions.load", json!({"data": data})).unwrap(); let r = one.execute("actions.play", json!({"action": "Copy In"})).unwrap(); @@ -2165,7 +2166,7 @@ fn distressing_and_remove_white_shapes_import_and_play() { let undo = vec![item("Invs", "Inverse", None), item("slct", "Select", Some(desc("null").with("null", ord("HstS", "Ordn", "Prvs"))))]; let data = set_of("TrueGrit", vec![("Distress", distress), ("Remove White", remove_white), ("Nudge", nudge), ("Undo", undo)]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 80, "resolution": 200})).unwrap(); s.execute("layer.new.layer", json!({"name": "Ink"})).unwrap(); s.execute("select.rect", json!({"x": 20, "y": 20, "width": 80, "height": 40})).unwrap(); @@ -2188,7 +2189,7 @@ fn distressing_and_remove_white_shapes_import_and_play() { assert!(st.doc.selection.is_some(), "the targeted mask loads as the selection"); assert_eq!(st.channel_view.target, crate::channel_cmds::ChannelTarget::LayerMask); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 10})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#202020"})).unwrap(); @@ -2206,7 +2207,7 @@ fn distressing_and_remove_white_shapes_import_and_play() { let ink = surf.sample_channel(20, 15, 1); assert!((ink - (1.0 - 22.0 / 255.0)).abs() < 0.02, "the ink keeps its darkness as opacity: {ink}"); // An image that opened as a normal layer has no Background: the step leaves it as it is. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "background": "transparent"})).unwrap(); s.execute("edit.fill", json!({"contents": "white"})).unwrap(); s.execute("actions.load", json!({"data": data})).unwrap(); @@ -2215,7 +2216,7 @@ fn distressing_and_remove_white_shapes_import_and_play() { let surf = s.active().unwrap().doc.layers.last().unwrap().surface().unwrap().clone(); assert!(surf.sample_channel(2, 2, 1) < 0.01, "white is cleared without a Background"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "resolution": 200})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 5, "height": 5})).unwrap(); @@ -2250,7 +2251,7 @@ fn remove_white_clears_the_targeted_layer_not_the_converted_background() { item("setd", "Set", Some(fsel(enm("Ordn", "None")))), ]; let data = set_of("TrueGrit", vec![("Remove White", steps)]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); let art = s.execute("layer.new.layer", json!({"name": "Art"})).unwrap()["layer"].as_u64().unwrap(); s.execute("edit.fill", json!({"contents": "white"})).unwrap(); @@ -2314,7 +2315,7 @@ fn events_photoshop_only_runs_by_name_export_by_name_and_old_codes_still_import( let photoshop = vec![blur("boxblur"), surface("surfaceBlur"), item("FltI", "Flatten Image", None), item("flattenImage", "Flatten Image", None)]; let legacy = vec![blur("BoxB"), surface("SrfB"), item("Fltn", "Flatten Image", None)]; let data = set_of("S", vec![("Photoshop", photoshop), ("Legacy", legacy)]); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(r["unsupported"], json!([]), "{r}"); let ids = |i: usize| s.actions.list.actions()[i].steps.iter().map(|st| st.command.clone()).collect::>(); @@ -2350,7 +2351,7 @@ fn events_photoshop_only_runs_by_name_export_by_name_and_old_codes_still_import( #[test] fn photo_filter_saves_under_the_name_photoshop_runs() { let params = json!({"color": "#0022cd", "density": 67, "preserveLuminosity": false}); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "#808080"})).unwrap(); s.execute("actions.record", json!({"name": "Filter"})).unwrap(); s.execute("image.adjustments.photoFilter", params.clone()).unwrap(); @@ -2370,7 +2371,7 @@ fn photo_filter_saves_under_the_name_photoshop_runs() { // command, and saving them again writes the name. let data = set_of("S", vec![("Photoshop", vec![item("photoFilter", "Photo Filter", Some(d.clone()))]), ("Legacy", vec![item("PhtF", "Photo Filter", Some(d))])]); - let mut t = Session::new(); + let mut t = crate::session(); let r = t.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(r["unsupported"], json!([]), "{r}"); for a in t.actions.list.actions() { @@ -2416,7 +2417,7 @@ fn photo_filter_saves_under_the_name_photoshop_runs() { fn black_white_adjustment_layer_saves_as_photoshops_class_and_old_class_still_imports() { let id = "layer.newAdjustmentLayer.blackWhite"; let params = json!({"reds": 17, "yellows": 83, "greens": -12, "cyans": 107, "blues": 51, "magentas": 133, "tint": true, "tintColor": "#c08040"}); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("BW", vec![ActionStep::new(id, params.clone())])).unwrap(); let r = s.execute("actions.save", json!({"action": "BW"})).unwrap(); assert_eq!(r["skipped"], json!([])); @@ -2425,7 +2426,7 @@ fn black_white_adjustment_layer_saves_as_photoshops_class_and_old_class_still_im let make = file.actions[0].items[0].descriptor.as_ref().unwrap(); let kind = get_obj(make, "Usng").and_then(|u| get_obj(u, "Type")).unwrap(); assert_eq!(trimmed(&kind.class_id), "BanW"); - let mut t = Session::new(); + let mut t = crate::session(); let r = t.execute("actions.load", json!({"data": b64(&saved)})).unwrap(); assert_eq!(r["unsupported"], json!([]), "{r}"); assert_eq!(t.actions.list.actions()[0].steps, vec![ActionStep::new(id, params)]); @@ -2438,7 +2439,7 @@ fn black_white_adjustment_layer_saves_as_photoshops_class_and_old_class_still_im item("Mk ", "Make", Some(desc("null").with("null", class_ref("AdjL")).with("Usng", D::Descriptor(using)))) }; let data = set_of("S", vec![("A", ["BanW", "BlnW", "BANW", "BlnWx"].into_iter().map(make).collect())]); - let mut t = Session::new(); + let mut t = crate::session(); let r = t.execute("actions.load", json!({"data": data})).unwrap(); let steps: Vec<&str> = t.actions.list.actions()[0].steps.iter().map(|st| st.command.as_str()).collect(); assert_eq!(steps, [id, id, PHOTOSHOP_STEP, PHOTOSHOP_STEP], "{r}"); @@ -2503,7 +2504,7 @@ fn black_white_native_fraction_keeps_its_pixels_at_every_depth() { for depth in [8, 16, 32] { let mut samples = Vec::new(); for reds in [40.4, 40.0] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1, "height": 1, "background": "#ff0000", "depth": depth})).unwrap(); s.execute("layer.newAdjustmentLayer.blackWhite", json!({"reds": reds})).unwrap(); samples.push(photocraft_compose::flatten(&s.active().unwrap().doc).into_px()); @@ -2546,7 +2547,7 @@ fn smart_blur_quality_uses_photoshop_codes() { ]; let items = cases.iter().map(|(q, m, _, _)| item("SmrB", "Smart Blur", Some(smart_blur(enm("SmBQ", q), m)))).collect(); let data = set_of("Blurs", vec![("Smart", items)]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.load", json!({"data": data})).unwrap(); let steps = &s.actions.list.actions()[0].steps; for ((q, _, quality, mode), ActionStep { command: id, params: p }) in cases.iter().zip(steps) { @@ -2613,14 +2614,14 @@ fn photoshop_shadows_highlights_steps_play() { normalise(&mut q); assert_eq!(q, json!({"shadowAmount": 35, "shadowTone": 50, "shadowRadius": 30, "blackClip": 0.01})); // And it runs on a document. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "#404040"})).unwrap(); s.execute(id, p).unwrap(); } #[test] fn save_while_recording_includes_pending_steps() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("actions.record", json!({"name": "Pending"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Recorded"})).unwrap(); @@ -2942,7 +2943,7 @@ fn fractional_translation_only_transform_keeps_offset_and_interpolation() { #[test] fn numeric_layer_references_refuse_silent_fallback_to_current_selection() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let parse_first_desc = |v: &Value| -> Descriptor { @@ -3066,7 +3067,7 @@ fn arbitrary_rotation_keeps_interpolation_through_atn() { /// `Amnt`, and loads back as the same step (#7946: it was skipped, so a portable action lost it). #[test] fn emboss_saves_as_photoshops_event_and_loads_back() { - let mut s = Session::new(); + let mut s = crate::session(); let params = json!({"angle": 130, "height": 1, "amount": 70}); s.actions.list.push(Action::new("Pore", vec![ActionStep::new("filter.stylize.emboss", params.clone())])).unwrap(); let r = s.execute("actions.save", json!({"action": "Pore"})).unwrap(); @@ -3079,7 +3080,7 @@ fn emboss_saves_as_photoshops_event_and_loads_back() { for (key, want) in [("Angl", 130), ("Hght", 1), ("Amnt", 70)] { assert_eq!(d.get(key), Some(&D::Integer(want)), "{key}"); } - let mut t = Session::new(); + let mut t = crate::session(); t.execute("actions.load", json!({"data": b64(&saved)})).unwrap(); assert_eq!(t.actions.list.actions()[0].steps, vec![ActionStep::new("filter.stylize.emboss", params)]); } @@ -3149,7 +3150,7 @@ fn function_keys_keep_shift_and_command() { file.actions[1].shift = true; file.actions[1].command = true; file.actions[0].shift = true; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap(); assert_eq!(r["functionKeys"], json!([{"action": "Soften", "key": "Shift+F3"}, {"action": "Finish", "key": "Cmd+Shift+F5"}])); let shortcuts = &s.prefs().shortcuts; @@ -3400,7 +3401,7 @@ fn vibrance_adjustment_layer_steps_save_with_the_string_class() { ], )], ); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); let steps = &s.actions.list.actions()[0].steps; @@ -3418,7 +3419,7 @@ fn vibrance_adjustment_layer_steps_save_with_the_string_class() { let ty = get_obj(pair[1].descriptor.as_ref().unwrap(), "Usng").and_then(|u| get_obj(u, "Type")).unwrap(); assert!(ty.class_id.is("vibrance"), "Make class {:?}", ty.class_id); } - let mut reloaded = Session::new(); + let mut reloaded = crate::session(); reloaded.execute("actions.load", json!({"data": saved["data"]})).unwrap(); assert_eq!(reloaded.actions.list.actions()[0].steps, s.actions.list.actions()[0].steps); } @@ -3432,7 +3433,7 @@ fn vibrance_steps_with_temperature_or_tint_save_back_unchanged() { let warm = desc("vibrance").with("temperature", long(-20.0)).with("vibrance", long(5.0)); let make = desc("null").with("null", class_ref("AdjL")).with("Usng", D::Descriptor(desc("AdjL").with("Type", D::Descriptor(warm)))); let data = set_of("Vibrance", vec![("A", vec![item("set", "Set", Some(set.clone())), item("Mk ", "Make", Some(make.clone()))])]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.load", json!({"data": data})).unwrap(); assert!(s.actions.list.actions()[0].steps.iter().all(|st| st.command == "actions.photoshopStep"), "{:?}", s.actions.list.actions()[0].steps); let saved = s.execute("actions.save", json!({"set": "Vibrance"})).unwrap(); @@ -3582,13 +3583,13 @@ fn image_size_explicit_sides_keep_precedence_over_percent() { (json!({"height": 18, "resample": "nearest"}), (24, 18)), (json!({"width": 20, "percent": 50, "resample": "none", "resolution": 144}), (32, 24)), ] { - let mut native = Session::new(); + let mut native = crate::session(); native.execute("file.new", json!({"width": 32, "height": 24, "depth": depth})).unwrap(); native.execute("image.imageSize", params.clone()).unwrap(); let size = native.active().unwrap().doc.size; assert_eq!((size.width, size.height), expected, "native {params} at {depth} bits"); - let mut recorded = Session::new(); + let mut recorded = crate::session(); recorded.actions.list.push(Action::new("Resize", vec![ActionStep::new("image.imageSize", params.clone())])).unwrap(); let before = recorded.actions.list.clone(); let saved = recorded.execute("actions.save", json!({"action": "Resize"})).unwrap(); @@ -3596,7 +3597,7 @@ fn image_size_explicit_sides_keep_precedence_over_percent() { assert_eq!(saved["steps"], 1); assert_eq!(recorded.actions.list, before); - let mut replay = Session::new(); + let mut replay = crate::session(); let loaded = replay.execute("actions.load", json!({"data": saved["data"]})).unwrap(); assert_eq!(loaded["unsupported"], json!([])); replay.execute("file.new", json!({"width": 32, "height": 24, "depth": depth})).unwrap(); @@ -3612,7 +3613,7 @@ fn image_size_explicit_sides_keep_precedence_over_percent() { fn image_size_explicit_sides_do_not_hide_invalid_percent() { for percent in [json!(0), json!(-1), json!("50"), json!(false)] { let params = json!({"width": 20, "height": 18, "percent": percent, "resample": "nearest"}); - let mut native = Session::new(); + let mut native = crate::session(); native.execute("file.new", json!({"width": 32, "height": 24})).unwrap(); assert!(native.execute("image.imageSize", params.clone()).is_err(), "{params}"); let action = Action::new("Resize", vec![ActionStep::new("image.imageSize", params.clone())]); @@ -3655,7 +3656,7 @@ fn image_size_intentional_controls_still_round_trip() { #[test] fn recorded_layer_select_exports_to_atn() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let l = s.execute("layer.new.layer", json!({"name": "Wanted"})).unwrap(); let wanted_id = l["layer"].as_u64().unwrap(); @@ -3684,7 +3685,7 @@ fn recorded_layer_select_exports_to_atn() { #[test] fn select_rect_modes_export_without_becoming_replace() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); // Default or "replace" mode succeeds @@ -3718,7 +3719,7 @@ fn select_rect_modes_export_without_becoming_replace() { #[test] fn radial_blur_off_center_strict_export_refuses_silent_recentering() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); // Default center (omitted) exports successfully @@ -3993,7 +3994,7 @@ fn camera_raw_filter_steps_import_as_filter_camera_raw() { } assert_eq!(imp.unsupported.iter().map(|u| u.step).collect::>(), (1..=18).collect::>()); // The imported step plays. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 12})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#808080"})).unwrap(); @@ -4014,7 +4015,7 @@ fn loaded_camera_raw_filter_steps_save_back_unchanged() { .with("Cr12", D::Integer(10)) .with("Crv ", D::List([0, 0, 64, 50, 255, 255].map(D::Integer).to_vec())); let file = one_action(vec![item("Adobe Camera Raw Filter", "Camera Raw Filter", Some(recorded.clone()))]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); assert_eq!(s.actions.list.actions()[0].steps[0].command, "filter.cameraRaw"); @@ -4067,7 +4068,7 @@ fn camera_raw_filter_steps_with_unknown_keys_stay_photoshop_steps() { item("Adobe Camera Raw Filter", "Camera Raw Filter", None), item("Adobe Camera Raw Filter", "Camera Raw Filter", Some(cr().with("Ex12", D::Double(0.2)))), ]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap(); let unsupported: Vec = loaded["unsupported"].as_array().unwrap().iter().map(|u| u["step"].as_u64().unwrap()).collect(); assert_eq!(unsupported, [0, 1, 2], "{loaded}"); @@ -4276,7 +4277,7 @@ fn gallery_effect_steps_load_clamp_play_and_save_back() { assert_eq!(item.descriptor.unwrap().items, expected); // They play. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24})).unwrap(); s.execute("filter.render.clouds", json!({})).unwrap(); for (code, effect) in [("AccE", "accentedEdges"), ("Ct ", "cutout"), ("Plst", "plaster")] { @@ -4413,7 +4414,7 @@ fn gallery_effect_steps_save_back_as_the_event_they_were_recorded_as() { let gallery = desc("null").with("GEfk", enm("GEft", "AccE")).with("EdgW", D::Integer(3)).with("EdgB", D::Integer(20)).with("Smth", D::Integer(7)); let source = vec![item("AccE", "Accented Edges", Some(edges)), item("cutout", "Cutout", Some(cutout)), item("GEfc", "Filter Gallery", Some(gallery))]; let data = set_of("S", vec![("A", source.clone())]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); let ids: Vec<&str> = s.actions.list.actions()[0].steps.iter().map(|st| st.command.as_str()).collect(); @@ -4488,7 +4489,7 @@ fn channel_and_color_steps_load_and_save_back() { actions: vec![AtnAction { name: UnicodeString::new_nul("Inks"), items: items.clone(), ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap(); assert_eq!(r["unsupported"], json!([])); assert_eq!( @@ -4689,12 +4690,12 @@ fn trap_step_without_a_width_saves_back_the_same() { actions: vec![AtnAction { name: UnicodeString::new_nul("T"), items: vec![item("Trap", "Trap", Some(desc("null")))], ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap(); let loaded = s.actions.list.actions().to_vec(); assert_eq!(loaded[0].steps, vec![ActionStep::new("image.trap", json!({"width": 1}))]); let saved = s.execute("actions.save", json!({"set": "S"})).unwrap(); - let mut t = Session::new(); + let mut t = crate::session(); t.execute("actions.load", json!({"data": saved["data"].as_str().unwrap()})).unwrap(); assert_eq!(t.actions.list.actions(), loaded); } @@ -4724,7 +4725,7 @@ fn select_color_components_import_play_and_round_trip() { ] { for depth in [8, 16, 32] { for channel in channels { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 1, "mode": mode, "depth": depth})).unwrap(); let expected = s.execute("channel.target", json!({"channel": channel})).unwrap(); s.execute("channel.target", json!({"channel": "composite"})).unwrap(); @@ -4760,7 +4761,7 @@ fn select_color_components_preserve_unsupported_selection_shapes() { // The legacy `Lmnc` code would otherwise target Lightness and save back as `Lght`. ("lab", desc("null").with("null", channel_ord("Lmnc"))), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 1, "mode": mode})).unwrap(); let data = set_of("Unknown", vec![("Pick", vec![item("select", "Select", Some(selection.clone()))])]); let loaded = s.execute("actions.load", json!({"data": data})).unwrap(); @@ -4800,7 +4801,7 @@ fn select_color_components_preserve_unsupported_selection_shapes() { /// A CMYK component cannot retarget a same-named alpha channel when replayed on RGB. #[test] fn select_color_components_do_not_fall_back_to_alpha_names() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 1, "mode": "rgb"})).unwrap(); s.execute("channel.new", json!({"name": "cyan"})).unwrap(); for channel in [json!("cyan"), json!(0), json!({"alpha": 0})] { @@ -4819,7 +4820,7 @@ fn select_color_components_do_not_fall_back_to_alpha_names() { fn select_channel_export_rejects_nested_color_selections() { for colors in [vec![0, 1], vec![1]] { let params = json!({"channel":{"color":"cyan","colors":colors}}); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":2,"height":1,"mode":"cmyk"})).unwrap(); s.execute("channel.target", params.clone()).unwrap(); assert_eq!(s.active().unwrap().channel_view.selected_colors, colors); @@ -4831,7 +4832,7 @@ fn select_channel_export_rejects_nested_color_selections() { assert!(atn::parse(&bytes).unwrap().actions[0].items.is_empty()); assert_eq!(s.actions.list.actions()[0].steps[0].params, params); } - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Cyan", vec![ActionStep::new("channel.target", json!({"channel":{"color":"CYAN"},"extend":false}))])).unwrap(); let saved = s.execute("actions.save", json!({"action":"Cyan"})).unwrap(); assert_eq!(saved["skipped"], json!([])); @@ -4845,7 +4846,7 @@ fn select_channel_export_rejects_mode_specific_gray_objects() { for color in ["gray", "GRAY", "GrAy"] { for mode in ["gray", "rgb"] { let params = json!({"channel":{"color":color}}); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":2,"height":1,"mode":mode})).unwrap(); assert_eq!(s.execute("channel.target", params.clone()).is_ok(), mode == "gray"); s.actions.list.push(Action::new("Gray object", vec![ActionStep::new("channel.target", params.clone())])).unwrap(); @@ -4857,14 +4858,14 @@ fn select_channel_export_rejects_mode_specific_gray_objects() { assert_eq!(s.actions.list.actions()[0].steps[0].params, params); } } - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Portable", vec![ActionStep::new("channel.target", json!({"channel":"composite"}))])).unwrap(); let saved = s.execute("actions.save", json!({"action":"Portable"})).unwrap(); assert_eq!(saved["skipped"], json!([])); let bytes = photocraft_paint::tile::b64_decode(saved["data"].as_str().unwrap()).unwrap(); assert_eq!(import(&bytes).unwrap().actions[0].steps, s.actions.list.actions()[0].steps); let gray = set_of("Gray", vec![("Pick", vec![item("select", "Select", Some(desc("null").with("null", channel_ord("Gry"))))])]); - let mut rgb = Session::new(); + let mut rgb = crate::session(); rgb.execute("file.new", json!({"width":2,"height":1,"mode":"rgb"})).unwrap(); rgb.execute("actions.load", json!({"data":gray})).unwrap(); assert_eq!(rgb.actions.list.actions()[0].steps[0], ActionStep::new("channel.target", json!({"channel":"composite"}))); @@ -4953,7 +4954,7 @@ fn mapped_transform_reference_points_round_trip() { let (bytes, _) = export("Anchors", &[&loaded.actions[0]], &[], false).unwrap(); assert_eq!(import(&bytes).unwrap().actions[0].steps, loaded.actions[0].steps); if reference == "topLeft" && loaded.actions[0].steps[0].command == "select.transformSelection" { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":256,"height":256})).unwrap(); s.execute("select.rect", json!({"x":60,"y":60,"width":100,"height":100})).unwrap(); let ActionStep { command: id, params: p } = &loaded.actions[0].steps[0]; @@ -4987,7 +4988,7 @@ fn mapped_show_only_round_trip_and_toggle() { let saved = atn::parse(&bytes).unwrap(); assert_eq!(get_bool(saved.actions[0].items[0].descriptor.as_ref().unwrap(), "TglO"), Some(true)); assert_eq!(import(&bytes).unwrap().actions[0].steps, loaded.actions[0].steps); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("layer.new.layer", json!({"name":"Solo"})).unwrap(); let visible = |s: &Session| s.active().unwrap().doc.layers.iter().map(|l| l.visible).collect::>(); @@ -5014,7 +5015,7 @@ fn mapped_adjustment_label_survives_export() { ); let (bytes, _) = export("Labels", &[&loaded.actions[0]], &[], false).unwrap(); assert_eq!(import(&bytes).unwrap().actions[0].steps, loaded.actions[0].steps); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); for ActionStep { command: id, params } in &loaded.actions[0].steps { s.execute(id, params.clone()).unwrap(); @@ -5064,7 +5065,7 @@ fn mapped_copy_cut_layer_options_survive_export() { props.extend(p.as_object().unwrap().clone()); } assert_eq!(Value::Object(props), loaded.actions[0].steps[2].params); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4,"background":"white"})).unwrap(); s.execute("select.rect", json!({"x":0,"y":0,"width":2,"height":2})).unwrap(); for ActionStep { command: id, params } in &saved.actions[0].steps { @@ -5091,7 +5092,7 @@ fn mapped_named_layer_transparency_survives_export() { assert_eq!(loaded.actions[0].steps, vec![ActionStep::new("select.loadSelection", json!({"channel":"transparency","layer":"Source"}))]); let (bytes, _) = export("Transparency", &[&loaded.actions[0]], &[], false).unwrap(); assert_eq!(import(&bytes).unwrap().actions[0].steps, loaded.actions[0].steps); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4,"background":"white"})).unwrap(); s.execute("layer.setProps", json!({"name":"Source"})).unwrap(); s.execute("layer.new.layer", json!({"name":"Empty"})).unwrap(); @@ -5108,7 +5109,7 @@ fn mapped_background_property_survives_export_and_playback() { assert_eq!(loaded.actions[0].steps, vec![ActionStep::new("layer.hideLayers", json!({"layer":{"background":true}}))]); let (bytes, _) = export("Background", &[&loaded.actions[0]], &[], false).unwrap(); assert_eq!(get_list(atn::parse(&bytes).unwrap().actions[0].items[0].descriptor.as_ref().unwrap(), "null"), Some(&[r][..])); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4,"background":"white"})).unwrap(); std::sync::Arc::make_mut(s.active_mut().unwrap().doc_mut()).layers[0].name = "Hintergrund".into(); s.execute("layer.new.layer", json!({"name":"Background"})).unwrap(); @@ -5145,7 +5146,7 @@ fn mapped_close_keeps_ask_and_discard_distinct() { let (bytes, _) = export("Close", &[&loaded.actions[0]], &[], false).unwrap(); assert!(atn::parse(&bytes).unwrap().actions[0].items[0].descriptor.as_ref().unwrap().get("Svng").is_none()); assert_eq!(import(&bytes).unwrap().actions[0].steps, loaded.actions[0].steps); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let ActionStep { command: id, params: p } = &loaded.actions[0].steps[0]; @@ -5162,7 +5163,7 @@ fn mapped_close_keeps_ask_and_discard_distinct() { /// "don't save" (`Svng N`); `true` and other values stay refused. #[test] fn close_save_false_discards_and_saves_as_dont_save() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); for refused in [json!(true), json!("yes"), json!(0)] { @@ -5255,7 +5256,7 @@ fn newer_feature_steps_load_with_photoshops_defaults() { assert_eq!(back(&id, params).items, sharpen.items, "load -> save changed the step"); // Oil Paint and Smart Sharpen play. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24})).unwrap(); s.execute("filter.render.clouds", json!({})).unwrap(); let action = Action::new( @@ -5520,7 +5521,7 @@ fn smart_sharpen_outside_the_commands_limits_is_clamped_on_import_and_refused_on #[test] fn newer_feature_selection_steps_play() { let (w, h) = (160u32, 100u32); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -5688,7 +5689,7 @@ fn video_other_and_matting_steps_load_play_and_save_back() { ("RmvB", desc("null"), "layer.matting.removeBlackMatte", json!({})), ("RmvW", desc("null"), "layer.matting.removeWhiteMatte", json!({})), ]; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24, "background": "transparent"})).unwrap(); s.execute("filter.render.clouds", json!({})).unwrap(); for (code, d, id, params) in cases { @@ -5893,6 +5894,7 @@ fn displace_map_paths_a_document_may_not_name_stay_kept_steps() { /// Keep unmeasured inputs intact and refuse settings that would be changed by export. #[test] fn unmeasured_displace_stays_opaque_and_lossy_export_is_refused() { + crate::install().unwrap(); assert!(!super::menu_item_commands().contains(&"filter.distort.displace")); let path = r"C:\map.psd"; let wire = path_value(path); @@ -5969,7 +5971,7 @@ fn recorded_displace_loads_without_map_and_plays_through_the_step_gate() { let path = dir.path().join("synthetic-map.psd"); let wire = displace_descriptor(path_value(path.to_str().unwrap())); let data = set_of("Maps", vec![("A", vec![item("displace", "Displace", Some(wire))])]); - let mut source = Session::new(); + let mut source = crate::session(); let loaded = source.execute("actions.load", json!({"data":data})).unwrap(); assert_eq!(loaded["unsupported"], json!([])); assert!(!path.exists(), "loading the ATN needs no map"); @@ -6020,7 +6022,7 @@ fn recorded_displace_loads_without_map_and_plays_through_the_step_gate() { assert_eq!(snapshot(&source), before); source.authorize = None; - let mut map = Session::new(); + let mut map = crate::session(); paint_split(&mut map, 16, 8, [1.0, 1.0, 1.0, 1.0]); let encoded = photocraft_io::export(&map.active().unwrap().doc, "psd", &Default::default()).unwrap(); std::fs::write(&path, encoded.bytes).unwrap(); @@ -6087,7 +6089,7 @@ fn distort_filter_steps_load_clamp_play_and_save_back() { ), ("ZgZg", zigzag, "filter.distort.zigZag", json!({"amount": 10, "ridges": 5, "style": "pondRipples"})), ]; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24})).unwrap(); s.execute("filter.render.clouds", json!({})).unwrap(); for (code, d, id, params) in cases { @@ -6275,7 +6277,7 @@ fn wave_values_the_command_rejects_are_kept_or_refused() { for (param, n) in [("wavelengthMin", 999), ("wavelengthMax", 1), ("amplitudeMin", 999)] { assert!(export_item("filter.distort.wave", &json!({ param: n }), "S").is_none(), "{param} {n} exported"); } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24})).unwrap(); s.execute("filter.render.clouds", json!({})).unwrap(); let plays = [ @@ -6331,7 +6333,7 @@ fn pixel(s: &mut Session) -> Vec { /// another pattern plays the pattern with that id; a foreign id falls back to the name. #[test] fn pattern_fill_prefers_an_installed_id_over_a_colliding_name() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "mode": "rgb", "depth": 8})).unwrap(); let mut define = |color: &str| { s.execute("edit.fill", json!({"contents": "color", "color": color})).unwrap(); @@ -6369,7 +6371,7 @@ fn pattern_fill_prefers_an_installed_id_over_a_colliding_name() { /// An id and a name of the same pattern play it. #[test] fn pattern_fill_ids_beat_names_across_document_and_library() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "mode": "rgb", "depth": 8})).unwrap(); let red = define_pattern(&mut s, "#ff0000", "Red"); define_pattern(&mut s, "#0000ff", "Blue"); @@ -6413,7 +6415,7 @@ fn pattern_steps_named_only_by_pattern_name_export_the_name() { /// up as a name only. A pattern whose id equals that name text doesn't beat the one named so. #[test] fn pattern_fill_name_fallback_matches_names_not_ids() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "mode": "rgb", "depth": 8})).unwrap(); let red = define_pattern(&mut s, "#ff0000", "Red"); // Green is named like the red pattern's id. @@ -6430,7 +6432,7 @@ fn pattern_fill_name_fallback_matches_names_not_ids() { /// pattern, from the imported step and from the Pattern Fill dialog's command alike. #[test] fn pattern_fill_missing_everywhere_names_the_pattern() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "mode": "rgb", "depth": 8})).unwrap(); define_pattern(&mut s, "#ff0000", "Red"); let data = set_of("Pat", vec![("Missing", vec![pattern_fill_step("5e1c0000-aaaa-4bbb-8ccc-000000000000", "My Wood")])]); @@ -6448,14 +6450,14 @@ fn pattern_fill_missing_everywhere_names_the_pattern() { /// by that name. `actions.save` used to trim it and then find no set. #[test] fn save_finds_a_set_by_its_exact_name_with_spaces() { - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action { set: Some(" Web ".into()), ..Action::new("Old", Vec::new()) }).unwrap(); s.execute("actions.record", json!({"name": "New", "set": " Web "})).unwrap(); s.execute("actions.stop", json!({})).unwrap(); let saved = s.execute("actions.save", json!({"set": " Web "})).unwrap(); assert_eq!((&saved["set"], &saved["actions"]), (&json!(" Web "), &json!(["Old", "New"]))); // The file keeps the name, as Photoshop's does. - let mut reloaded = Session::new(); + let mut reloaded = crate::session(); let r = reloaded.execute("actions.load", json!({"data": saved["data"]})).unwrap(); assert_eq!(r["set"], " Web "); // Other names are still trimmed. @@ -6467,11 +6469,11 @@ fn save_finds_a_set_by_its_exact_name_with_spaces() { /// Photoshop saves an empty set to the `.atn`, and loading that file brings the empty set back. #[test] fn an_empty_new_set_saves_and_loads_back() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.newSet", json!({"name": "Later"})).unwrap(); let saved = s.execute("actions.save", json!({"set": "Later"})).unwrap(); assert_eq!((&saved["set"], &saved["actions"], &saved["steps"]), (&json!("Later"), &json!([]), &json!(0))); - let mut other = Session::new(); + let mut other = crate::session(); let r = other.execute("actions.load", json!({"data": saved["data"]})).unwrap(); assert_eq!((&r["set"], &r["actions"]), (&json!("Later"), &json!([]))); assert_eq!(crate::actions_edit_cmds::set_names(&other), ["Later"], "an empty folder"); @@ -6484,7 +6486,7 @@ fn an_empty_new_set_saves_and_loads_back() { // A set that doesn't exist is still refused, and so is saving every action when there is none. let err = s.execute("actions.save", json!({"set": "Nope"})).unwrap_err().to_string(); assert!(err.contains("no actions in a set named `Nope`"), "{err}"); - let err = Session::new().execute("actions.save", json!({})).unwrap_err().to_string(); + let err = crate::session().execute("actions.save", json!({})).unwrap_err().to_string(); assert!(err.contains("there are no actions to save"), "{err}"); } @@ -6502,7 +6504,7 @@ fn gbk_set() -> Vec { #[test] fn load_decodes_legacy_step_names() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": b64(&gbk_set())})).unwrap(); assert_eq!(r["encoding"], "GBK", "{r}"); assert_eq!(r["unsupported"][0]["name"], "可选颜色", "{r}"); @@ -6524,7 +6526,7 @@ fn load_keeps_windows_1252_symbols() { actions: vec![AtnAction { name: UnicodeString::new_nul("Logo"), items: steps, ..Default::default() }], ..Default::default() }; - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap(); assert_eq!(r["encoding"], "windows-1252", "{r}"); assert_eq!(r["unsupported"][0]["name"], "50 °", "{r}"); @@ -6537,7 +6539,7 @@ fn load_keeps_windows_1252_symbols() { #[test] fn load_encoding_override() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": b64(&gbk_set()), "encoding": "shift_jis"})).unwrap(); assert_eq!(r["encoding"], "Shift_JIS", "{r}"); let r = s.execute("actions.load", json!({"data": b64(&gbk_set()), "encoding": "auto"})).unwrap(); @@ -6546,14 +6548,14 @@ fn load_encoding_override() { #[test] fn load_reports_utf8() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("actions.load", json!({"data": b64(&atn::write(&sample()).unwrap())})).unwrap(); assert_eq!(r["encoding"], "UTF-8", "{r}"); } #[test] fn load_rejects_bad_encodings() { - let mut s = Session::new(); + let mut s = crate::session(); for bad in [json!(3), json!(""), json!("nope"), json!("replacement"), json!(["gbk"])] { assert!(s.execute("actions.load", json!({"data": b64(&gbk_set()), "encoding": bad})).is_err(), "{bad}"); } @@ -6670,7 +6672,7 @@ fn gallery_effect_steps_keep_a_legacy_panel_name_byte_for_byte() { let gbk = vec![0xC7, 0xBF, 0xBB, 0xAF, 0xB5, 0xC4, 0xB1, 0xDF, 0xD4, 0xB5]; assert!(std::str::from_utf8(&gbk).is_err()); let source = AtnItem { dictionary: gbk.clone(), ..item("AccE", "", Some(edges)) }; - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": set_of("S", vec![("A", vec![source])])})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); let saved = s.execute("actions.save", json!({"set": "S"})).unwrap(); @@ -6783,7 +6785,7 @@ fn active_fill(s: &Session) -> photocraft_doc::Fill { #[test] fn gradient_fill_set_imports_midpoints_plays_and_saves_back_unchanged() { let recorded = recorded_gradient([50, 25, 70]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": b64(&atn::write(&one_action(vec![gradient_set(recorded.clone())])).unwrap())})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); let ActionStep { command: id, params: p } = s.actions.list.actions()[0].steps[0].clone(); @@ -6810,7 +6812,7 @@ fn gradient_fill_set_imports_midpoints_plays_and_saves_back_unchanged() { assert_eq!(midpoints, vec![0.25, 0.7]); assert_eq!(opacity_stops.len(), 2); // Default midpoints load as `[]`, which clears the custom ones when played. - let mut s2 = Session::new(); + let mut s2 = crate::session(); s2.execute("actions.load", json!({"data": b64(&atn::write(&one_action(vec![gradient_set(recorded_gradient([50, 50, 50]))])).unwrap())})).unwrap(); assert_eq!(s2.actions.list.actions()[0].steps[0].params["midpoints"], json!([])); s.actions = s2.actions; @@ -6822,7 +6824,7 @@ fn gradient_fill_set_imports_midpoints_plays_and_saves_back_unchanged() { /// #10771: an edited loaded step writes a fresh descriptor from its params, midpoints included. #[test] fn edited_gradient_fill_set_writes_a_fresh_descriptor() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.load", json!({"data": b64(&atn::write(&one_action(vec![gradient_set(recorded_gradient([50, 25, 70]))])).unwrap())})).unwrap(); let mut step = s.actions.list.actions()[0].steps[0].clone(); step.params["midpoints"] = json!([0.4, 0.6]); @@ -6845,7 +6847,7 @@ fn edited_gradient_fill_set_writes_a_fresh_descriptor() { #[test] fn gradient_fill_make_imports_plays_and_saves_back_unchanged() { let recorded = recorded_gradient([50, 25, 70]); - let mut s = Session::new(); + let mut s = crate::session(); let loaded = s.execute("actions.load", json!({"data": b64(&atn::write(&one_action(vec![gradient_make(recorded.clone())])).unwrap())})).unwrap(); assert_eq!(loaded["unsupported"], json!([]), "{loaded}"); assert_eq!(s.actions.list.actions()[0].steps[0].command, "layer.newFillLayer.gradient"); @@ -6964,7 +6966,7 @@ fn layer_set(t: Descriptor) -> AtnItem { } fn blend_layers(depth: u8) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#808080"})).unwrap(); @@ -7087,12 +7089,12 @@ fn blend_if_the_command_cannot_play_stays_a_photoshop_step() { /// Save one action of steps through `actions.save`, returning the skipped list and the steps /// `actions.load` reads back. fn save_and_reload(steps: Vec) -> (Value, Vec) { - let mut s = Session::new(); + let mut s = crate::session(); let mut action = Action::new("A", steps); action.set = Some("Review".into()); s.actions.list.push(action).unwrap(); let saved = s.execute("actions.save", json!({"set": "Review", "skipUnsupported": true})).unwrap(); - let mut fresh = Session::new(); + let mut fresh = crate::session(); fresh.execute("actions.load", json!({"data": saved["data"]})).unwrap(); (saved["skipped"].clone(), fresh.actions.list.actions()[0].steps.clone()) } @@ -7215,7 +7217,7 @@ fn whole_library_conditional_scopes_roundtrip() { target.set = Some("Original".into()); let (original, _) = export("Original", &[&caller, &target], &[], false).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.replace", json!({"data":b64(&original),"confirm":true})).unwrap(); let saved = s.execute("actions.save", json!({})).unwrap(); let bytes = photocraft_paint::tile::b64_decode(saved["data"].as_str().unwrap()).unwrap(); diff --git a/crates/engine/src/cmd/automate_cmds.rs b/crates/engine-core/src/cmd/automate_cmds.rs similarity index 100% rename from crates/engine/src/cmd/automate_cmds.rs rename to crates/engine-core/src/cmd/automate_cmds.rs diff --git a/crates/engine/src/cmd/automate_cmds/contact_sheet_flatten_tests.rs b/crates/engine-core/src/cmd/automate_cmds/contact_sheet_flatten_tests.rs similarity index 95% rename from crates/engine/src/cmd/automate_cmds/contact_sheet_flatten_tests.rs rename to crates/engine-core/src/cmd/automate_cmds/contact_sheet_flatten_tests.rs index ba11c3f4e0..edf1da11d8 100644 --- a/crates/engine/src/cmd/automate_cmds/contact_sheet_flatten_tests.rs +++ b/crates/engine-core/src/cmd/automate_cmds/contact_sheet_flatten_tests.rs @@ -18,7 +18,7 @@ fn sheet(s: &mut Session, dir: &str, extra: Value) -> Vec { fn a_flattened_sheet_ends_as_one_normal_layer_named_contact_sheet_ii() { let dir = tmp("flatten-layer"); images(&dir, 3, 60, 30); - let mut s = Session::new(); + let mut s = crate::session(); let idx = sheet(&mut s, &dir, json!({"flatten": true, "caption": true, "fontSize": 10}))[0]; let st = &s.documents()[idx]; let d = &st.doc; @@ -38,7 +38,7 @@ fn a_flattened_sheet_ends_as_one_normal_layer_named_contact_sheet_ii() { fn flattening_keeps_the_pixels_of_the_unflattened_sheet() { let dir = tmp("flatten-pixels"); images(&dir, 3, 60, 30); - let mut s = Session::new(); + let mut s = crate::session(); let layered = sheet(&mut s, &dir, json!({}))[0]; let flat = sheet(&mut s, &dir, json!({"flatten": true}))[0]; let (layered, flat) = (&s.documents()[layered].doc, &s.documents()[flat].doc); @@ -50,7 +50,7 @@ fn flattening_keeps_the_pixels_of_the_unflattened_sheet() { fn every_page_of_a_flattened_multi_page_run_gets_the_layer() { let dir = tmp("flatten-pages"); images(&dir, 5, 60, 30); - let mut s = Session::new(); + let mut s = crate::session(); let docs = sheet(&mut s, &dir, json!({"flatten": true})); assert_eq!(docs.len(), 2); for idx in docs { @@ -65,7 +65,7 @@ fn every_page_of_a_flattened_multi_page_run_gets_the_layer() { fn an_unflattened_sheet_keeps_its_background_and_image_layers() { let dir = tmp("flatten-off"); images(&dir, 3, 60, 30); - let mut s = Session::new(); + let mut s = crate::session(); let idx = sheet(&mut s, &dir, json!({"flatten": false}))[0]; let st = &s.documents()[idx]; let names: Vec<&str> = st.doc.layers.iter().map(|l| l.name.as_str()).collect(); diff --git a/crates/engine/src/cmd/automate_cmds/contact_sheet_subfolders_tests.rs b/crates/engine-core/src/cmd/automate_cmds/contact_sheet_subfolders_tests.rs similarity index 98% rename from crates/engine/src/cmd/automate_cmds/contact_sheet_subfolders_tests.rs rename to crates/engine-core/src/cmd/automate_cmds/contact_sheet_subfolders_tests.rs index 9a86656d60..3550dcff37 100644 --- a/crates/engine/src/cmd/automate_cmds/contact_sheet_subfolders_tests.rs +++ b/crates/engine-core/src/cmd/automate_cmds/contact_sheet_subfolders_tests.rs @@ -27,7 +27,7 @@ fn tree(name: &str, extras: bool) -> Cleanup { for (i, rel) in files.into_iter().enumerate() { let path = join(root, rel); std::fs::create_dir_all(std::path::Path::new(&path).parent().unwrap()).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let grey = 20 + 25 * i; s.execute("file.new", json!({"width": 12, "height": 8, "background": format!("#{grey:02x}{grey:02x}{grey:02x}")})).unwrap(); crate::file_cmds::save_doc(&s.active().unwrap().doc, &path, None).unwrap(); @@ -42,7 +42,7 @@ fn tree(name: &str, extras: bool) -> Cleanup { fn sheets(input: Value, extra: Value) -> Result)>> { let mut p = json!({"input": input, "units": "pixels", "width": 200, "height": 200, "resolution": 72, "columns": 2, "rows": 2, "caption": false}); p.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone()); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.automate.contactSheetII", p)?; assert_eq!(r["errors"], json!([]), "{r}"); let docs = r["documents"].as_array().unwrap(); @@ -149,7 +149,7 @@ fn a_flag_of_the_wrong_type_is_an_error() { for input in [json!(dir), json!([join(&dir, "a_red.png")])] { let mut p = json!({"input": input, "caption": false}); p[key] = value.clone(); - let e = Session::new().execute("file.automate.contactSheetII", p).unwrap_err().to_string(); + let e = crate::session().execute("file.automate.contactSheetII", p).unwrap_err().to_string(); assert!(e.contains(&format!("\"{key}\" must be true or false")), "{key}={value}: {e}"); } } diff --git a/crates/engine/src/cmd/automate_cmds/tests.rs b/crates/engine-core/src/cmd/automate_cmds/tests.rs similarity index 95% rename from crates/engine/src/cmd/automate_cmds/tests.rs rename to crates/engine-core/src/cmd/automate_cmds/tests.rs index d78643642e..e6f98c5c2b 100644 --- a/crates/engine/src/cmd/automate_cmds/tests.rs +++ b/crates/engine-core/src/cmd/automate_cmds/tests.rs @@ -17,7 +17,7 @@ pub(super) fn tmp(name: &str) -> String { pub(super) fn images(dir: &str, n: usize, w: u32, h: u32) -> Vec { (0..n) .map(|i| { - let mut s = Session::new(); + let mut s = crate::session(); let v = (i as f32 * 40.0 + 20.0) / 255.0; s.execute( "file.new", @@ -49,7 +49,7 @@ fn browse_runs_a_script_file() { let dir = tmp("browse"); let path = format!("{dir}/make.txt"); std::fs::write(&path, "file.new {\"width\": 30, \"height\": 20}\nimage.imageRotation.90cw\n").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.scripts.browse", json!({"path": path})).unwrap(); assert_eq!(r["ok"], true); let d = &s.active().unwrap().doc; @@ -65,7 +65,7 @@ fn browse_rejects_photoshop_extendscript() { let dir = tmp("jsx"); let jsx = format!("{dir}/hello.jsx"); std::fs::write(&jsx, "alert('hi');\n").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let err = s.execute("file.scripts.browse", json!({"path": jsx})).unwrap_err().to_string(); assert!(err.contains("not Photoshop ExtendScript"), "{err}"); assert!(err.contains("JSON"), "{err}"); @@ -83,7 +83,7 @@ fn browse_rejects_photoshop_extendscript() { #[test] fn recording_browse_script_captures_each_effect_once() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 12, "height": 8})).unwrap(); s.execute("actions.record", json!({"name": "Rotate script"})).unwrap(); let run = s.execute("file.scripts.browse", json!({"steps": [["image.imageRotation.90cw", {}]]})).unwrap(); @@ -103,7 +103,7 @@ fn recording_browse_script_captures_each_effect_once() { #[test] fn standalone_browse_script_still_runs_and_journals_concrete_commands() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 12, "height": 8})).unwrap(); let start = s.journal.len(); let result = s.execute("file.scripts.browse", json!({"steps": [["image.imageRotation.90cw", {}]]})).unwrap(); @@ -115,7 +115,7 @@ fn standalone_browse_script_still_runs_and_journals_concrete_commands() { #[test] fn script_events_fire_on_new_and_close() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s .execute("file.scripts.scriptEventsManager", json!({"add": {"event": "newDocument", "steps": [["image.imageRotation.90cw", {}]], "name": "Rotate"}})) .unwrap(); @@ -145,7 +145,7 @@ fn script_events_fire_on_new_and_close() { fn droplets_are_written_and_run() { let dir = tmp("droplet"); let inputs = images(&dir, 2, 40, 20); - let mut s = Session::new(); + let mut s = crate::session(); let path = format!("{dir}/Rotate"); let r = s .execute( @@ -179,7 +179,7 @@ fn droplets_are_written_and_run() { fn batch_and_droplets_use_the_named_actions_enabled_steps() { let dir = tmp("named-actions"); let inputs = images(&dir, 1, 2, 1); - let mut s = Session::new(); + let mut s = crate::session(); let invert = crate::actions_cmds::Action::new("Invert", vec![ActionStep::new("image.adjustments.invert", json!({}))]); let mut rotate = crate::actions_cmds::Action::new("Rotate", vec![ActionStep::new("image.imageRotation.90cw", json!({})), ActionStep::new("file.close", json!({}))]); @@ -194,7 +194,7 @@ fn batch_and_droplets_use_the_named_actions_enabled_steps() { let droplet: Value = serde_json::from_slice(&std::fs::read(result["path"].as_str().unwrap()).unwrap()).unwrap(); assert_eq!(droplet["action"]["steps"], json!([["image.imageRotation.90cw", {}]])); // A droplet carries its chosen steps into a session with no saved actions. - result = Session::new().execute("file.automate.runDroplet", json!({"droplet": result["path"], "input": inputs})).unwrap(); + result = crate::session().execute("file.automate.runDroplet", json!({"droplet": result["path"], "input": inputs})).unwrap(); } assert_eq!(result["errors"], json!([]), "{command}: {result}"); let image = photocraft_codecs::decode(&std::fs::read(result["files"][0].as_str().unwrap()).unwrap()).unwrap(); @@ -208,7 +208,7 @@ fn batch_and_droplets_use_the_named_actions_enabled_steps() { fn batch_and_droplets_keep_explicit_steps_and_reject_invalid_sources_before_writing() { let dir = tmp("action-sources"); let inputs = images(&dir, 1, 2, 1); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(crate::actions_cmds::Action::new("Invert", vec![ActionStep::new("image.adjustments.invert", json!({}))])).unwrap(); for command in ["file.automate.batch", "file.automate.createDroplet"] { for (i, source) in [ @@ -224,7 +224,7 @@ fn batch_and_droplets_keep_explicit_steps_and_reject_invalid_sources_before_writ p.as_object_mut().unwrap().extend(source.as_object().unwrap().clone()); let mut result = s.execute(command, p).unwrap(); if command == "file.automate.createDroplet" { - result = Session::new().execute("file.automate.runDroplet", json!({"droplet": result["path"], "input": inputs})).unwrap(); + result = crate::session().execute("file.automate.runDroplet", json!({"droplet": result["path"], "input": inputs})).unwrap(); } assert_eq!(result["errors"], json!([]), "{command}: {result}"); let image = photocraft_codecs::decode(&std::fs::read(result["files"][0].as_str().unwrap()).unwrap()).unwrap(); @@ -258,7 +258,7 @@ fn batch_and_droplets_keep_explicit_steps_and_reject_invalid_sources_before_writ fn droplets_keep_the_recorded_save_that_marks_the_result() { let dir = tmp("droplet-save-close"); let inputs = images(&dir, 1, 4, 2); - let mut s = Session::new(); + let mut s = crate::session(); let steps = json!([["image.adjustments.invert", {}], ["file.saveAs", {}], ["file.close", {}]]); let p = json!({"path": format!("{dir}/Invert"), "steps": steps, "format": "png", "output": format!("{dir}/out"), "shim": false}); let dp = s.execute("file.automate.createDroplet", p).unwrap()["path"].as_str().unwrap().to_string(); @@ -277,7 +277,7 @@ fn droplet_shim_passes_shell_metacharacters_as_a_literal_path() { let dir = tmp("droplet-shell-quote"); let path = format!("{dir}/Droplet's \"quote\" $HOME `printf expanded` $(touch shim-injected) \\\nline"); - let mut session = Session::new(); + let mut session = crate::session(); let result = session.execute("file.automate.createDroplet", json!({"path": path, "steps": [["file.new", {}]]})).unwrap(); let droplet = result["path"].as_str().unwrap(); let shim = result["shim"].as_str().unwrap(); @@ -313,7 +313,7 @@ fn droplets_carry_the_actions_their_play_steps_call() { use crate::actions_cmds::Action; let dir = tmp("droplet-called"); let inputs = images(&dir, 2, 40, 20); - let mut s = Session::new(); + let mut s = crate::session(); let act = |name: &str, steps: Value| -> Action { serde_json::from_value(json!({"name": name, "steps": steps})).unwrap() }; s.actions.list = list_of(vec![ act("Unrelated", json!([["image.imageRotation.180", {}]])), @@ -338,7 +338,7 @@ fn droplets_carry_the_actions_their_play_steps_call() { assert_eq!(names, ["Rotate", "Outer"], "only the called actions, transitively"); // A fresh session, as `photocraft-cli droplet` and the droplet shim use. - let mut fresh = Session::new(); + let mut fresh = crate::session(); let r = fresh.execute("file.automate.runDroplet", json!({"droplet": dp, "input": [dir.clone()]})).unwrap(); assert_eq!(r["files"].as_array().unwrap().len(), inputs.len(), "{r}"); let out = photocraft_codecs::decode(&std::fs::read(format!("{dir}/out-Outer/img0.png")).unwrap()).unwrap(); @@ -405,7 +405,7 @@ fn droplets_carry_the_actions_their_play_steps_call() { assert_eq!(*captured, json!(s.actions.list.actions()[1]), "{name}: preserve disabled/dialog/set flags"); } for different in [false, true] { - let mut replay = Session::new(); + let mut replay = crate::session(); if different { replay.actions.list = list_of(vec![Action::new("Unrelated", Vec::new()), Action::new("Rotate", Vec::new())]); } @@ -441,7 +441,7 @@ fn droplets_preserve_batch_action_namespaces() { let dir = tmp("droplet-scopes"); let input = images(&dir, 1, 40, 20).remove(0); for kind in ["inline", "named", "named-set", "mixed", "mixed-two", "caller-null"] { - let mut maker = Session::new(); + let mut maker = crate::session(); let mut source = Action::new("Source", vec![ActionStep::new("actions.play", json!({"action": 1})), ActionStep::new("file.close", json!({}))]); source.disabled.insert(1); source.dialogs.insert(0); @@ -494,7 +494,7 @@ fn droplets_preserve_batch_action_namespaces() { assert_eq!(captured.last(), Some(&source), "one untouched source retains its references and flags"); assert_eq!(captured.len(), if kind.starts_with("mixed") { 3 } else { 1 }); } - let r = Session::new().execute("file.automate.runDroplet", json!({"droplet": path, "input": [input]})).unwrap(); + let r = crate::session().execute("file.automate.runDroplet", json!({"droplet": path, "input": [input]})).unwrap(); assert_eq!(r["errors"], json!([]), "{kind}: {r}"); let out = photocraft_codecs::decode(&std::fs::read(format!("{inner}/img0.png")).unwrap()).unwrap(); assert_eq!(out.dimensions(), (20, 40), "{kind}"); @@ -511,7 +511,7 @@ fn droplet_scoped_variants_keep_the_existing_action_limit() { let dir = tmp("droplet-scope-limit"); let input = images(&dir, 1, 2, 1).remove(0); for count in [4095, 4096] { - let mut maker = Session::new(); + let mut maker = crate::session(); maker.actions.list = list_of((0..count).map(|i| Action::new(format!("A{i}"), Vec::new())).collect()); let mut steps: Vec<_> = (0..count).map(|i| json!(["actions.play", {"action": i}])).collect(); steps.push( @@ -522,7 +522,7 @@ fn droplet_scoped_variants_keep_the_existing_action_limit() { .execute("file.automate.createDroplet", json!({"path": format!("{dir}/{count}"), "steps": steps, "output": output, "format": "png", "shim": false})) .unwrap()["path"] .clone(); - let result = Session::new().execute("file.automate.runDroplet", json!({"droplet": path, "input": [input]})); + let result = crate::session().execute("file.automate.runDroplet", json!({"droplet": path, "input": [input]})); if count == 4095 { assert_eq!(result.unwrap()["errors"], json!([])); assert!(std::path::Path::new(&output).exists()); @@ -538,7 +538,7 @@ fn droplets_carry_the_actions_their_conditional_steps_call() { use crate::actions_cmds::Action; let dir = tmp("droplet-conditional"); let inputs = images(&dir, 2, 40, 20); - let mut s = Session::new(); + let mut s = crate::session(); let act = |name: &str, steps: Value| -> Action { serde_json::from_value(json!({"name": name, "steps": steps})).unwrap() }; s.actions.list = list_of(vec![ act("Unrelated", json!([["image.imageRotation.180", {}]])), @@ -558,7 +558,7 @@ fn droplets_carry_the_actions_their_conditional_steps_call() { assert_eq!(names, ["Rotate", "Wide", "Tall"], "both branches and what they call"); // A fresh session, as `photocraft-cli droplet` and the droplet shim use. - let mut fresh = Session::new(); + let mut fresh = crate::session(); let r = fresh.execute("file.automate.runDroplet", json!({"droplet": dp, "input": [dir.clone()]})).unwrap(); assert_eq!(r["files"].as_array().unwrap().len(), inputs.len(), "{r}"); let img = photocraft_codecs::decode(&std::fs::read(format!("{out}/img0.png")).unwrap()).unwrap(); @@ -570,7 +570,7 @@ fn batch_and_droplets_skip_recorded_view_steps() { let dir = tmp("view-steps"); images(&dir, 1, 40, 20); let steps = json!([["view.zoomIn", {}], ["image.imageRotation.90cw", {}], ["view.fitOnScreen", {}]]); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.automate.batch", json!({"steps": steps, "input": dir.clone(), "output": format!("{dir}/batch"), "format": "png"})).unwrap(); assert!(r["errors"].as_array().unwrap().is_empty(), "{r}"); let out = photocraft_codecs::decode(&std::fs::read(format!("{dir}/batch/img0.png")).unwrap()).unwrap(); @@ -584,7 +584,7 @@ fn batch_and_droplets_skip_recorded_view_steps() { fn statistics_makes_a_stack_mode_smart_object() { let dir = tmp("stats"); let files = images(&dir, 3, 16, 12); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.scripts.statistics", json!({"mode": "mean", "input": files})).unwrap(); assert_eq!(r["images"], 3); let d = &s.active().unwrap().doc; @@ -602,7 +602,7 @@ fn stacked_smart_object_holds_the_loaded_layers_at_its_top_level() { // Like Photoshop, Load Files into Stack › Create Smart Object (Statistics without alignment) and // Statistics with alignment embed one layer per file, bottom to top, with no wrapper group. let dir = tmp("stack-top"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 72, "background": "#606060"})).unwrap(); s.edit("texture", |doc, active| { let surf = doc.layer_mut(active.ok_or(EngineError::NoDocument)?).and_then(Layer::surface_mut).ok_or(EngineError::NoDocument)?; @@ -622,7 +622,7 @@ fn stacked_smart_object_holds_the_loaded_layers_at_its_top_level() { }) .collect(); for align in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.scripts.statistics", json!({"mode": "median", "input": files, "align": align})).unwrap(); let d = &s.active().unwrap().doc; let LayerContent::Smart(so) = &d.layers[0].content else { panic!("not a smart object") }; @@ -639,7 +639,7 @@ fn contact_sheet_places_thumbnails_with_captions() { let dir = tmp("contact"); images(&dir, 5, 60, 30); for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); let r = s .execute("file.automate.contactSheetII", json!({"input": dir, "units": "pixels", "width": 400, "height": 300, "resolution": 72, "columns": 2, "rows": 2, "depth": depth, "fontSize": 10, "rotateForBestFit": true})) .unwrap(); @@ -672,7 +672,7 @@ fn a_failed_step_inside_a_called_action_fails_scripts_and_batch() { use crate::actions_cmds::Action; let dir = tmp("nested-failure"); images(&dir, 1, 8, 4); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 6})).unwrap(); s.actions .list @@ -721,7 +721,7 @@ fn a_failed_step_inside_a_called_action_fails_scripts_and_batch() { #[test] fn load_files_into_stack_aligns_before_the_smart_object() { let dir = tmp("stack-align"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 72, "background": "#606060"})).unwrap(); s.edit("texture", |doc, active| { let surf = doc.layer_mut(active.ok_or(EngineError::NoDocument)?).and_then(Layer::surface_mut).ok_or(EngineError::NoDocument)?; @@ -739,20 +739,20 @@ fn load_files_into_stack_aligns_before_the_smart_object() { path }) .collect(); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.scripts.loadFilesIntoStack", json!({"paths": files, "align": true})).unwrap(); assert_eq!(r["layers"], 2); let st = s.active().unwrap(); assert_eq!(st.doc.layers.len(), 2, "loose layers"); assert!(st.doc.layers.iter().all(|l| matches!(l.content, LayerContent::Raster(_)))); assert_eq!(st.selected_layers().len(), 2, "Auto-Align ran on them all"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.scripts.loadFilesIntoStack", json!({"paths": files, "align": true, "createSmartObject": true})).unwrap(); let d = &s.active().unwrap().doc; assert_eq!(d.layers.len(), 1); let LayerContent::Smart(_) = &d.layers[0].content else { panic!("not a smart object") }; // A single file has nothing to align with: it just loads. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.scripts.loadFilesIntoStack", json!({"paths": [files[0].clone()], "align": true})).unwrap(); assert_eq!(s.active().unwrap().doc.layers.len(), 1); } @@ -774,7 +774,7 @@ fn scripts_calling_scripts_share_one_step_budget() { for level in 0..8 { below = script_calling(&dir, &format!("level{level}"), &vec![below; 6]); } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let started = std::time::Instant::now(); let r = s.execute("file.scripts.browse", json!({"path": below})).unwrap(); @@ -792,7 +792,7 @@ fn scripts_nested_deeper_than_the_limit_fail() { for level in 0..20 { below = script_calling(&dir, &format!("level{level}"), &[below]); } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let r = s.execute("file.scripts.browse", json!({"path": below})).unwrap(); assert_eq!(r["ok"], false, "{r}"); @@ -805,7 +805,7 @@ fn scripts_nested_deeper_than_the_limit_fail() { #[test] fn droplets_skip_actions_called_only_from_disabled_steps() { let dir = tmp("droplet-disabled-calls"); - let mut s = Session::new(); + let mut s = crate::session(); let mut top = crate::actions_cmds::Action::new( "Top", vec![ActionStep::new("actions.play", json!({"action": "Skipped"})), ActionStep::new("actions.play", json!({"action": "Used"}))], @@ -821,7 +821,7 @@ fn droplets_skip_actions_called_only_from_disabled_steps() { assert_eq!(names, ["Top", "Used"], "{droplet}"); // The droplet still runs on its own: the enabled call resolves, the disabled one never plays. let inputs = images(&dir, 1, 3, 2); - let run = Session::new().execute("file.automate.runDroplet", json!({"droplet": r["path"], "input": inputs, "output": format!("{dir}/out")})).unwrap(); + let run = crate::session().execute("file.automate.runDroplet", json!({"droplet": r["path"], "input": inputs, "output": format!("{dir}/out")})).unwrap(); assert_eq!(run["errors"], json!([]), "{run}"); let out = photocraft_codecs::decode(&std::fs::read(format!("{dir}/out/img0.png")).unwrap()).unwrap(); assert_eq!(out.dimensions(), (3, 2), "the disabled Rotate must not run"); @@ -834,14 +834,14 @@ fn droplets_forward_override_open_to_batch() { let dir = tmp("droplet-override-open"); let inputs = images(&dir, 1, 6, 4); let recorded = { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 3, "background": "#00ff00"})).unwrap(); let path = format!("{dir}/recorded.png"); crate::file_cmds::save_doc(&s.active().unwrap().doc, &path, None).unwrap(); path }; for (override_open, size) in [(true, (6, 4)), (false, (2, 3))] { - let mut s = Session::new(); + let mut s = crate::session(); let out = format!("{dir}/out-{override_open}"); let r = s .execute( @@ -850,7 +850,7 @@ fn droplets_forward_override_open_to_batch() { "format": "png", "output": out, "overrideOpen": override_open, "shim": false}), ) .unwrap(); - let run = Session::new().execute("file.automate.runDroplet", json!({"droplet": r["path"], "input": [inputs[0]]})).unwrap(); + let run = crate::session().execute("file.automate.runDroplet", json!({"droplet": r["path"], "input": [inputs[0]]})).unwrap(); assert_eq!(run["errors"], json!([]), "{run}"); let image = photocraft_codecs::decode(&std::fs::read(format!("{out}/img0.png")).unwrap()).unwrap(); assert_eq!(image.dimensions(), size, "overrideOpen {override_open}: {run}"); diff --git a/crates/engine/src/cmd/background_cmds.rs b/crates/engine-core/src/cmd/background_cmds.rs similarity index 99% rename from crates/engine/src/cmd/background_cmds.rs rename to crates/engine-core/src/cmd/background_cmds.rs index f5d2ffbf3d..ffb0736145 100644 --- a/crates/engine/src/cmd/background_cmds.rs +++ b/crates/engine-core/src/cmd/background_cmds.rs @@ -109,7 +109,7 @@ mod tests { /// Bottom to top: Layer 0 (the old Background, now a normal layer), A, B. A has a 4×4 red /// square at (2, 2); the rest of it is transparent. fn session(depth: u32) -> (Session, [LayerId; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 12, "depth": depth})).unwrap(); s.execute("layer.new.layerFromBackground", json!({})).unwrap(); let l0 = doc(&s).layers[0].id; @@ -136,7 +136,7 @@ mod tests { /// A Background (the white one `file.new` makes) with A and B above it. fn with_background() -> (Session, [LayerId; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 12})).unwrap(); let bg = doc(&s).layers[0].id; let a = LayerId(s.execute("layer.new.layer", json!({"name": "A"})).unwrap()["layer"].as_u64().unwrap()); @@ -223,7 +223,7 @@ mod tests { #[test] fn refuses_groups_adjustments_missing_layers_and_bad_params() { // No document. - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled(CMD)); assert!(s.execute(CMD, json!({})).is_err()); // Already a Background: unavailable, for any layer. diff --git a/crates/engine/src/cmd/background_eraser_channel_target_tests.rs b/crates/engine-core/src/cmd/background_eraser_channel_target_tests.rs similarity index 98% rename from crates/engine/src/cmd/background_eraser_channel_target_tests.rs rename to crates/engine-core/src/cmd/background_eraser_channel_target_tests.rs index 90d2140f05..0a40dc59b1 100644 --- a/crates/engine/src/cmd/background_eraser_channel_target_tests.rs +++ b/crates/engine-core/src/cmd/background_eraser_channel_target_tests.rs @@ -73,7 +73,7 @@ fn one_colour_channel_as_the_target_param_refuses_too() { #[test] fn a_click_on_the_background_layer_is_refused_too() { for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 40, "depth": depth})).unwrap(); s.execute("channel.target", json!({"channel": "red"})).unwrap(); assert_refused(&mut s, stroke(&CLICK, json!({})), &format!("{depth}-bit Background")); @@ -99,7 +99,7 @@ fn partial_sets_that_were_not_measured_keep_erasing() { assert_erases(&mut s, stroke(&DRAG, json!({"target": {"colors": [1, 2]}})), "RGB green and blue"); for (mode, components) in [("cmyk", 4), ("lab", 3)] { for k in 0..components { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 40, "mode": mode})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 10, "width": 64, "height": 20, "antiAlias": false})).unwrap(); s.execute("edit.fill", json!({"color": "#1a3a6a"})).unwrap(); diff --git a/crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs b/crates/engine-core/src/cmd/background_eraser_transparency_lock_tests.rs similarity index 99% rename from crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs rename to crates/engine-core/src/cmd/background_eraser_transparency_lock_tests.rs index c4d91dd92c..c38f532b49 100644 --- a/crates/engine/src/cmd/background_eraser_transparency_lock_tests.rs +++ b/crates/engine-core/src/cmd/background_eraser_transparency_lock_tests.rs @@ -7,7 +7,7 @@ use super::*; /// White Background plus a normal layer "Target" with a solid red band across it (y 10..30). pub(super) fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 40, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({"name": "Target"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 10, "width": 64, "height": 20, "antiAlias": false})).unwrap(); diff --git a/crates/engine/src/cmd/brush_cmds.rs b/crates/engine-core/src/cmd/brush_cmds.rs similarity index 100% rename from crates/engine/src/cmd/brush_cmds.rs rename to crates/engine-core/src/cmd/brush_cmds.rs diff --git a/crates/engine/src/cmd/brush_cmds/define_brush_color_density_tests.rs b/crates/engine-core/src/cmd/brush_cmds/define_brush_color_density_tests.rs similarity index 99% rename from crates/engine/src/cmd/brush_cmds/define_brush_color_density_tests.rs rename to crates/engine-core/src/cmd/brush_cmds/define_brush_color_density_tests.rs index e7d27eb57a..6ddc21e664 100644 --- a/crates/engine/src/cmd/brush_cmds/define_brush_color_density_tests.rs +++ b/crates/engine-core/src/cmd/brush_cmds/define_brush_color_density_tests.rs @@ -65,7 +65,7 @@ use super::{GrayTile, Session, TipShape, json}; const COMMANDS: [&str; 2] = ["brush.defineFromSelection", "edit.defineBrushPreset"]; fn rgb_source(depth: u32, rgba: [f32; 4]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40, "depth": depth, "background": "#ffffff"})).unwrap(); s.edit("Colour square", |doc, active| { doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(photocraft_geom::Rect::new(10, 10, 30, 30), &rgba); @@ -182,7 +182,7 @@ fn native_gray_keeps_numeric_density_in_its_existing_rgb_view() { for depth in [8, 16, 32] { for profile in [None, Some(Builtin::DotGain20Compat), Some(Builtin::GrayGamma22)] { for value in [128.0 / 255.0, 200.0 / 255.0, 0.0] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40, "mode": "gray", "depth": depth, "background": "white"})).unwrap(); s.edit("Native gray square", |doc, active| { doc.icc_profile = profile.map(|p| p.profile().to_bytes()); diff --git a/crates/engine/src/cmd/brush_cmds/define_brush_merged_source_tests.rs b/crates/engine-core/src/cmd/brush_cmds/define_brush_merged_source_tests.rs similarity index 98% rename from crates/engine/src/cmd/brush_cmds/define_brush_merged_source_tests.rs rename to crates/engine-core/src/cmd/brush_cmds/define_brush_merged_source_tests.rs index 8848e1df2e..e700b1d9e0 100644 --- a/crates/engine/src/cmd/brush_cmds/define_brush_merged_source_tests.rs +++ b/crates/engine-core/src/cmd/brush_cmds/define_brush_merged_source_tests.rs @@ -9,7 +9,7 @@ fn tip(s: &Session) -> &GrayTile { } fn source(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 150, "depth": depth, "background": "#ffffff"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Tip"})).unwrap(); s.edit("Two visible squares", |doc, active| { @@ -82,7 +82,7 @@ fn selection_limits_the_visible_composite_even_with_background_active() { #[test] fn visible_group_children_and_occlusion_count_but_hidden_layers_and_groups_do_not() { for command in COMMANDS { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "white"})).unwrap(); s.edit("Visible and hidden composite contributors", |doc, active| { let mut black = Layer::raster("Nested visible black", doc.pixel_format()); @@ -115,7 +115,7 @@ fn visible_group_children_and_occlusion_count_but_hidden_layers_and_groups_do_no fn composite_transparency_and_selection_coverage_are_applied_once() { for command in COMMANDS { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth, "background": "transparent"})).unwrap(); s.edit("Nested translucent source", |doc, active| { let mut black = Layer::raster("Half black", doc.pixel_format()); @@ -152,7 +152,7 @@ fn composite_transparency_and_selection_coverage_are_applied_once() { fn a_hidden_black_source_over_white_or_transparency_is_empty_and_does_not_replace_a_preset() { for command in COMMANDS { for background in ["white", "transparent"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": background})).unwrap(); s.execute("layer.new.layer", json!({"name": "Hidden ink"})).unwrap(); s.edit("Hide all ink", |doc, active| { @@ -183,7 +183,7 @@ fn a_hidden_black_source_over_white_or_transparency_is_empty_and_does_not_replac #[test] fn merged_rgb_retains_the_document_profile_before_gray_conversion() { for command in COMMANDS { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": 32, "background": "transparent"})).unwrap(); s.edit("Linear gray nested under active group", |doc, active| { doc.icc_profile = Some(craft_cms::Builtin::LinearSrgb.profile().to_bytes()); @@ -203,7 +203,7 @@ fn merged_rgb_retains_the_document_profile_before_gray_conversion() { } fn sparse_budget_source(width: u32, height: u32, selected: bool) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": width, "height": height, "background": "transparent"})).unwrap(); s.edit("Sparse composite budget fixture", |doc, active| { let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap(); @@ -353,7 +353,7 @@ fn selected_visible_capture_is_identical_with_background_tip_group() { #[test] fn visible_composite_keeps_occlusion_and_ignores_hidden_source() { for command in COMMANDS { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "white"})).unwrap(); s.edit("Visible composite with hidden source", |doc, active| { let mut black = Layer::raster("Visible black", doc.pixel_format()); diff --git a/crates/engine/src/cmd/brush_cmds/define_brush_no_selection_tests.rs b/crates/engine-core/src/cmd/brush_cmds/define_brush_no_selection_tests.rs similarity index 98% rename from crates/engine/src/cmd/brush_cmds/define_brush_no_selection_tests.rs rename to crates/engine-core/src/cmd/brush_cmds/define_brush_no_selection_tests.rs index f15bdb4ec9..3d65576341 100644 --- a/crates/engine/src/cmd/brush_cmds/define_brush_no_selection_tests.rs +++ b/crates/engine-core/src/cmd/brush_cmds/define_brush_no_selection_tests.rs @@ -3,7 +3,7 @@ use super::*; const COMMANDS: [&str; 2] = ["edit.defineBrushPreset", "brush.defineFromSelection"]; fn source(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 150, "depth": depth, "background": "#ffffff"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Tip"})).unwrap(); s.edit("BrushSrc", |doc, active| { @@ -64,7 +64,7 @@ fn an_existing_selection_still_limits_the_tip_to_the_grey_square() { #[test] fn a_partial_selection_keeps_coverage_alpha_and_canvas_clipping() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "transparent"})).unwrap(); s.edit("Half opaque source", |doc, active| { let bounds = doc.bounds(); @@ -88,7 +88,7 @@ fn a_partial_selection_keeps_coverage_alpha_and_canvas_clipping() { #[test] fn no_document_is_disabled_and_a_group_active_capture_uses_visible_pixels() { - let mut s = Session::new(); + let mut s = crate::session(); for command in COMMANDS { assert!(!s.is_enabled(command)); assert!(s.execute(command, json!({"name": "No document"})).is_err()); @@ -104,7 +104,7 @@ fn no_document_is_disabled_and_a_group_active_capture_uses_visible_pixels() { #[test] fn a_large_canvas_is_trimmed_before_the_existing_tip_side_limit() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": MAX_TIP + 1, "height": 2, "background": "#ffffff"})).unwrap(); s.edit("One black pixel", |doc, active| { doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(MAX_TIP as i32, 0, MAX_TIP as i32 + 1, 1), &[0.0, 0.0, 0.0, 1.0]); @@ -152,7 +152,7 @@ fn a_canvas_capture_allocation_failure_leaves_the_source_and_presets_unchanged() // Sparse source and mask fixtures keep just one or two tiles, even when their // bounds would require gigabytes of dense sampling buffers. fn budget_source(width: u32, height: u32, selected: bool) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": width, "height": height, "background": "transparent"})).unwrap(); s.edit("Sparse budget source", |doc, active| { let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap(); diff --git a/crates/engine/src/cmd/brush_cmds/mixer_live.rs b/crates/engine-core/src/cmd/brush_cmds/mixer_live.rs similarity index 100% rename from crates/engine/src/cmd/brush_cmds/mixer_live.rs rename to crates/engine-core/src/cmd/brush_cmds/mixer_live.rs diff --git a/crates/engine/src/cmd/brush_cmds/mixer_live_tests.rs b/crates/engine-core/src/cmd/brush_cmds/mixer_live_tests.rs similarity index 99% rename from crates/engine/src/cmd/brush_cmds/mixer_live_tests.rs rename to crates/engine-core/src/cmd/brush_cmds/mixer_live_tests.rs index be24f3038e..02b97e83f0 100644 --- a/crates/engine/src/cmd/brush_cmds/mixer_live_tests.rs +++ b/crates/engine-core/src/cmd/brush_cmds/mixer_live_tests.rs @@ -5,7 +5,7 @@ use std::sync::Arc; /// Build format-specific red/green sampling layers and an empty painting target. fn fixture(fmt: PixelFormat) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":192,"height":96,"background":"#808080"})).unwrap(); s.execute("layer.new.layer", json!({"name":"Source"})).unwrap(); s.edit("fixture", |doc, id| { @@ -377,7 +377,7 @@ fn mixer_rotated_hard_tip_samples_safely_and_preserves_the_document() { #[test] fn mixer_default_does_not_sample_other_layers() { assert!(!MixerSettings::default().sample_all_layers); - assert!(!Session::new().tools.brush.mixer.sample_all_layers); + assert!(!crate::session().tools.brush.mixer.sample_all_layers); } /// Large session tips and spatial reservoirs stay out of each journaled stroke. diff --git a/crates/engine/src/cmd/brush_cmds/tests.rs b/crates/engine-core/src/cmd/brush_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/brush_cmds/tests.rs rename to crates/engine-core/src/cmd/brush_cmds/tests.rs index 83e2f1af20..e0ee3a39e0 100644 --- a/crates/engine/src/cmd/brush_cmds/tests.rs +++ b/crates/engine-core/src/cmd/brush_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": "transparent"})).unwrap(); s } @@ -128,7 +128,7 @@ fn fill_paints_a_cmyk_pick_with_the_picked_inks() { #[test] fn fill_works_on_cmyk_and_16_and_32_bit() { for (mode, depth) in [("cmyk", 8), ("rgb", 16), ("grayscale", 32)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 30, "mode": mode, "depth": depth})).unwrap(); s.execute("paint.stroke", json!({"points": [[10, 5], [50, 5], [50, 25], [10, 25]], "fill": true, "color": "#000000", "hardness": 1.0})).unwrap(); assert!(rgba(&s, 30, 15)[0] < 0.2, "{mode}/{depth}: {:?}", rgba(&s, 30, 15)); @@ -279,7 +279,7 @@ fn mixer_brush_reservoir_and_cleaning() { #[test] fn color_replacement_modes() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 40, "background": "#33993f"})).unwrap(); s.execute("tools.setColors", json!({"foreground": "#ff0000"})).unwrap(); let before = rgba(&s, 30, 20); @@ -301,7 +301,7 @@ fn color_replacement_modes() { fn live_color_replacement_matches_the_commit() { for depth in [8, 16] { for sampling in ["continuous", "once", "backgroundSwatch"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 40, "background": "#ff0000", "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 40, "y": 0, "width": 40, "height": 40})).unwrap(); s.execute("edit.fill", json!({"color": "#0000ff"})).unwrap(); @@ -335,7 +335,7 @@ fn live_color_replacement_matches_the_commit() { /// refused (it would otherwise recolour the layer behind the user's back). #[test] fn color_replacement_refuses_non_pixel_targets() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20, "background": "#ff0000"})).unwrap(); let steps = s.active().unwrap().history.entries().len(); for t in [json!("mask"), json!("quickMask"), json!({"channel": 0}), json!(3)] { @@ -709,7 +709,7 @@ fn define_brush_from_selection_propagates_compositor_allocation_error_transactio #[test] fn works_on_cmyk_and_16_bit() { for (mode, depth) in [("cmyk", 8), ("rgb", 16), ("grayscale", 32)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 30, "mode": mode, "depth": depth})).unwrap(); s.execute("paint.stroke", json!({"points": [[5, 15], [55, 15]], "preset": "Chalk", "color": "#000000"})).unwrap(); s.execute("paint.pencil", json!({"points": [[5, 5], [55, 5]], "size": 2, "color": "#000000"})).unwrap(); @@ -744,7 +744,7 @@ fn brush_blend_mode_multiply() { fn eraser_on_background_layer_paints_the_background_colour() { // Issue #15: erasing the Background layer (locked transparency) must paint the background // colour, not silently do nothing (opacity can't be removed there). - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20, "background": "white"})).unwrap(); s.execute("tools.setColors", json!({"background": "#ff0000"})).unwrap(); s.execute("paint.stroke", json!({"points": [[2, 10], [18, 10]], "size": 8, "erase": true, "brush": {"hardness": 1.0}})).unwrap(); @@ -778,7 +778,7 @@ fn live_stroke_matches_the_committed_stroke() { // Bad input is an error, not a panic. assert!(LiveStroke::begin(&s, &json!({"points": []})).is_err()); assert!(LiveStroke::begin(&s, &json!({"points": [[1, 1]], "target": {"channel": 9}})).is_err()); - assert!(LiveStroke::begin(&Session::new(), &json!({"points": [[1, 1]]})).is_err()); + assert!(LiveStroke::begin(&crate::session(), &json!({"points": [[1, 1]]})).is_err()); } #[test] @@ -797,7 +797,7 @@ fn stroke_coordinate_validation_keeps_the_existing_bounds() { #[test] fn live_brush_and_pencil_reject_invalid_batches_without_changing_the_preview() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32, "depth": depth, "background": "transparent"})).unwrap(); let st = s.active().unwrap(); let (doc, revision, history) = (st.doc.clone(), st.revision, st.history.past_len()); @@ -871,7 +871,7 @@ fn live_pencil_matches_the_committed_pencil_and_auto_erases() { #[test] #[ignore] fn pencil_latency_24mp() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000, "background": "white"})).unwrap(); for size in [1.0f64, 9.0, 40.0] { let p = json!({"points": [[100.0, 100.0]], "size": size, "smoothing": 0.0}); @@ -917,7 +917,7 @@ fn live_stroke_equals_the_commit_at_every_zoom_with_smoothing() { for depth in [8, 16] { for zoom in [0.25, 1.0, 4.0, 16.0] { for (amount, pulled) in [(0.1, false), (0.5, false), (0.3, true)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 120, "depth": depth, "background": "white"})).unwrap(); s.execute("edit.fill", json!({"color": "#1a2550"})).unwrap(); s.execute("paint.stroke", json!({"points": [[20, 20], [180, 100]], "size": 8, "hardness": 1.0, "color": "#ffffff"})).unwrap(); @@ -975,7 +975,7 @@ fn pose_axes_commands_keep_minimal_patches_legacy_alias_and_preset_replay() { // Explicit axis keys win over a legacy combined key in the same command. s.execute("tools.setBrush", json!({"brush": {"pose": {"overrideTilt": true, "overrideTiltY": false}}})).unwrap(); assert_eq!(photocraft_paint::dynamics::apply_pose(&s.tools.brush, input), StrokePoint { tilt_x: 45.0, ..input }); - let mut replay = Session::new(); + let mut replay = crate::session(); for (id, params) in &s.journal { replay.execute(id, params.clone()).unwrap(); } @@ -1152,7 +1152,7 @@ fn load_and_clean_brush_refuse_bad_params_and_keep_the_paint() { assert_eq!(s.tools.mixer, before, "{bad}"); } // Clean Brush takes no params, so anything extra is ignored, without a document too. - let mut empty = Session::new(); + let mut empty = crate::session(); empty.execute("brush.mixer.clean", json!({"color": [], "junk": {"x": null}})).unwrap(); empty.execute("brush.mixer.load", json!({"color": null})).unwrap(); assert_eq!(empty.tools.mixer.reservoir, Some(empty.tools.foreground)); @@ -1196,7 +1196,7 @@ fn coalesced_set_brush_calls_journal_once_per_gesture() { #[test] fn out_of_range_scatter_is_rejected_and_the_maximum_still_paints() { let new = || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s @@ -1255,7 +1255,7 @@ fn strokes_convert_through_the_documents_cmyk_profile() { .unwrap() .to_bytes(); let cmyk_session = |tagged: bool| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32, "mode": "cmyk", "background": "white"})).unwrap(); if tagged { s.edit("icc", |doc, _| { @@ -1425,7 +1425,7 @@ fn the_remembered_brush_restores_at_launch() { remember_brush(&mut s); let stored = s.prefs().last_brush.clone(); assert_eq!(stored["preset"].as_str(), Some("Hard Round")); - let mut t = Session::new(); + let mut t = crate::session(); assert_ne!(t.tools.brush.size, 44.0, "a fresh session starts on the default brush"); t.prefs.edit(|p| p.last_brush = stored); restore_brush(&mut t); @@ -1434,17 +1434,17 @@ fn the_remembered_brush_restores_at_launch() { assert_eq!(t.tools.current_preset.as_deref(), Some("Hard Round")); assert_eq!(t.tools.brush_saved_rev, t.tools.brush_rev, "the restored value is already stored"); // A malformed remembered brush keeps the default (never an error, never a panic). - let mut bad = Session::new(); + let mut bad = crate::session(); bad.prefs.edit(|p| p.last_brush = json!({"brush": {"size": "huge"}})); restore_brush(&mut bad); - assert_eq!(bad.tools.brush.size, Session::new().tools.brush.size); + assert_eq!(bad.tools.brush.size, crate::session().tools.brush.size); } /// #6212: a remembered brush reads back clamped to its controls' ranges; one that fails the /// `tools.setBrush` checks, or isn't a brush at all, doesn't read back. #[test] fn restored_brush_settings_are_clamped_or_rejected() { - let s = Session::new(); + let s = crate::session(); let b = restored_settings(&s, &json!({"size": -4.0, "opacity": 7.0, "flow": -1.0, "hardness": 0.25, "smoothing": {"amount": 9.0}})).unwrap(); assert_eq!((b.size, b.opacity, b.flow, b.hardness, b.smoothing.amount), (1.0, 1.0, 0.0, 0.25, 1.0)); let round = restored_settings(&s, &remembered_settings(&b).unwrap()).unwrap(); @@ -1458,13 +1458,13 @@ fn restored_brush_settings_are_clamped_or_rejected() { /// value its options-bar field shows, so it paints instead of laying down nothing. #[test] fn restored_brush_opacity_floors_at_one_percent() { - let s = Session::new(); + let s = crate::session(); for opacity in [0.0, -1.0, 0.004] { let b = restored_settings(&s, &json!({"opacity": opacity})).unwrap(); assert_eq!(b.opacity, 0.01, "{opacity}"); } assert_eq!(restored_settings(&s, &json!({"opacity": 0.37})).unwrap().opacity, 0.37, "values above the floor are kept"); - let mut t = Session::new(); + let mut t = crate::session(); t.prefs.edit(|p| p.last_brush = json!({"brush": {"opacity": 0.0}})); restore_brush(&mut t); assert_eq!(t.tools.brush.opacity, 0.01, "the remembered session brush"); diff --git a/crates/engine/src/cmd/brush_key_cmds.rs b/crates/engine-core/src/cmd/brush_key_cmds.rs similarity index 99% rename from crates/engine/src/cmd/brush_key_cmds.rs rename to crates/engine-core/src/cmd/brush_key_cmds.rs index 6874463b59..07f0f72282 100644 --- a/crates/engine/src/cmd/brush_key_cmds.rs +++ b/crates/engine-core/src/cmd/brush_key_cmds.rs @@ -209,7 +209,7 @@ mod tests { assert_eq!(turned(179.0, 15.0), -166.0); assert_eq!(turned(-175.0, -15.0), 170.0); assert_eq!(turned(180.0, 0.0), 180.0); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.rotateBrush", json!({"degrees": -15})).unwrap(); assert_eq!(s.tools.brush.angle, -15.0); for bad in [json!({}), json!({"degrees": "x"}), json!({"degrees": 1e9}), json!(null)] { @@ -262,7 +262,7 @@ mod tests { #[test] fn previous_and_next_brush_walk_the_presets_and_wrap() { - let mut s = Session::new(); + let mut s = crate::session(); *s.tools.presets = std::sync::Arc::new(vec![preset("One", "", &[], 11.0), preset("Two", "", &[], 22.0), preset("Three", "", &[], 33.0)]); s.tools.current_preset = None; let picked = |s: &Session| (s.tools.current_preset.clone().unwrap_or_default(), s.tools.brush.size); @@ -294,7 +294,7 @@ mod tests { #[test] fn commands_step_the_session_brush_and_journal() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setBrush", json!({"brush": {"size": 40, "hardness": 0.5}})).unwrap(); s.execute("tools.increaseBrushSize", json!({})).unwrap(); assert_eq!(s.tools.brush.size, 45.0); diff --git a/crates/engine/src/cmd/brush_key_cmds/bracket_steps_tests.rs b/crates/engine-core/src/cmd/brush_key_cmds/bracket_steps_tests.rs similarity index 97% rename from crates/engine/src/cmd/brush_key_cmds/bracket_steps_tests.rs rename to crates/engine-core/src/cmd/brush_key_cmds/bracket_steps_tests.rs index 3d4f808696..40db369006 100644 --- a/crates/engine/src/cmd/brush_key_cmds/bracket_steps_tests.rs +++ b/crates/engine-core/src/cmd/brush_key_cmds/bracket_steps_tests.rs @@ -9,7 +9,7 @@ fn commands_follow_the_measured_sequence_in_both_directions() { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 125.0, 150.0, 175.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, ]; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setBrush", json!({"brush": {"size": 1, "hardness": 0.37, "spacing": 0.42}})).unwrap(); for (command, expected) in [ ("tools.increaseBrushSize", sizes.iter().skip(1).copied().collect::>()), @@ -57,7 +57,7 @@ fn intermediate_sizes_snap_in_the_keys_direction() { /// The specified extension above 1500 continues in hundreds and saturates at the brush maximum. #[test] fn commands_continue_in_hundreds_to_the_maximum_and_back() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setBrush", json!({"brush": {"size": 1500}})).unwrap(); for size in (1600..=5000).step_by(100) { s.execute("tools.increaseBrushSize", Value::Null).unwrap(); @@ -77,7 +77,7 @@ fn commands_continue_in_hundreds_to_the_maximum_and_back() { /// Small sizes still reach 1 px, stay there on decrease and grow again on increase (#3229). #[test] fn commands_reach_and_hold_the_one_pixel_minimum() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setBrush", json!({"brush": {"size": 3}})).unwrap(); for size in [2.0, 1.0, 1.0, 1.0] { s.execute("tools.decreaseBrushSize", Value::Null).unwrap(); diff --git a/crates/engine/src/cmd/brush_preset_cmds.rs b/crates/engine-core/src/cmd/brush_preset_cmds.rs similarity index 100% rename from crates/engine/src/cmd/brush_preset_cmds.rs rename to crates/engine-core/src/cmd/brush_preset_cmds.rs diff --git a/crates/engine/src/cmd/brush_preset_cmds/tests.rs b/crates/engine-core/src/cmd/brush_preset_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/brush_preset_cmds/tests.rs rename to crates/engine-core/src/cmd/brush_preset_cmds/tests.rs index e334ba35da..36c6a1eca2 100644 --- a/crates/engine/src/cmd/brush_preset_cmds/tests.rs +++ b/crates/engine-core/src/cmd/brush_preset_cmds/tests.rs @@ -5,7 +5,7 @@ fn names(s: &Session, g: &str) -> Vec { } fn with_groups() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); for (n, g) in [("A1", "Alpha"), ("A2", "Alpha"), ("A3", "Alpha"), ("B1", "Beta"), ("B2", "Beta")] { std::sync::Arc::make_mut(&mut *s.tools.presets).push(BrushPreset { name: n.into(), @@ -116,7 +116,7 @@ fn bad_params_fail_without_changes() { /// Group "Set": S0 at its top level, folders Ink (I1, I2; subfolder Fine: F1) and Dry (D1). fn with_folders() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); for (n, f) in [("S0", &[][..]), ("I1", &["Ink"][..]), ("F1", &["Ink", "Fine"][..]), ("I2", &["Ink"][..]), ("D1", &["Dry"][..])] { let folder = f.iter().map(|x| x.to_string()).collect(); std::sync::Arc::make_mut(&mut *s.tools.presets).push(BrushPreset { diff --git a/crates/engine/src/cmd/channel_cmds.rs b/crates/engine-core/src/cmd/channel_cmds.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds.rs rename to crates/engine-core/src/cmd/channel_cmds.rs diff --git a/crates/engine/src/cmd/channel_cmds/apply_image_darker_lighter_tests.rs b/crates/engine-core/src/cmd/channel_cmds/apply_image_darker_lighter_tests.rs similarity index 98% rename from crates/engine/src/cmd/channel_cmds/apply_image_darker_lighter_tests.rs rename to crates/engine-core/src/cmd/channel_cmds/apply_image_darker_lighter_tests.rs index 26b60a2041..6ec03941ec 100644 --- a/crates/engine/src/cmd/channel_cmds/apply_image_darker_lighter_tests.rs +++ b/crates/engine-core/src/cmd/channel_cmds/apply_image_darker_lighter_tests.rs @@ -16,7 +16,7 @@ fn halves(s: &mut Session, left: &str, right: &str) { /// The measured test documents: "target" (0) RGB 200/100/50 | 50/150/250 and "source" (1) /// 128/128/128 | 255/255/255, with "target" active. fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); for (left, right) in [("#c86432", "#3296fa"), ("#808080", "#ffffff")] { s.execute("file.new", json!({"width": W, "height": H, "mode": mode, "depth": depth})).unwrap(); halves(&mut s, left, right); @@ -101,7 +101,7 @@ fn an_alpha_channel_and_a_layer_mask_take_darken_and_lighten() { #[test] fn a_grayscale_layer_takes_darken_and_lighten() { - let mut s = Session::new(); + let mut s = crate::session(); for color in ["#c8c8c8", "#808080"] { s.execute("file.new", json!({"width": 40, "height": 20, "mode": "grayscale"})).unwrap(); s.execute("edit.fill", json!({"color": color})).unwrap(); diff --git a/crates/engine/src/cmd/channel_cmds/apply_image_lock_transparency_tests.rs b/crates/engine-core/src/cmd/channel_cmds/apply_image_lock_transparency_tests.rs similarity index 99% rename from crates/engine/src/cmd/channel_cmds/apply_image_lock_transparency_tests.rs rename to crates/engine-core/src/cmd/channel_cmds/apply_image_lock_transparency_tests.rs index a026a2a15a..2d64e91450 100644 --- a/crates/engine/src/cmd/channel_cmds/apply_image_lock_transparency_tests.rs +++ b/crates/engine-core/src/cmd/channel_cmds/apply_image_lock_transparency_tests.rs @@ -5,7 +5,7 @@ use super::*; /// A 40 x 20 document whose layer "Top" is empty except a half-transparent green 10 x 10 square /// at (10,5), and a second document "source" filled with 50% gray. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({"name": "Top"})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 5, "width": 10, "height": 10, "mode": "replace"})).unwrap(); diff --git a/crates/engine/src/cmd/channel_cmds/apply_image_locked_layer_tests.rs b/crates/engine-core/src/cmd/channel_cmds/apply_image_locked_layer_tests.rs similarity index 99% rename from crates/engine/src/cmd/channel_cmds/apply_image_locked_layer_tests.rs rename to crates/engine-core/src/cmd/channel_cmds/apply_image_locked_layer_tests.rs index 6888bb7a70..f126d1dbd9 100644 --- a/crates/engine/src/cmd/channel_cmds/apply_image_locked_layer_tests.rs +++ b/crates/engine-core/src/cmd/channel_cmds/apply_image_locked_layer_tests.rs @@ -7,7 +7,7 @@ use super::*; /// at (150,100) of 0/255/0 at alpha 128. Document "source" is 128/128/128 on the left half and /// white on the right half. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth, "name": "target"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Top"})).unwrap(); s.execute("select.rect", json!({"x": 150, "y": 100, "width": 100, "height": 100, "mode": "replace"})).unwrap(); diff --git a/crates/engine/src/cmd/channel_cmds/apply_image_preserve_tests.rs b/crates/engine-core/src/cmd/channel_cmds/apply_image_preserve_tests.rs similarity index 99% rename from crates/engine/src/cmd/channel_cmds/apply_image_preserve_tests.rs rename to crates/engine-core/src/cmd/channel_cmds/apply_image_preserve_tests.rs index a7cf9a7f96..df76c6c27d 100644 --- a/crates/engine/src/cmd/channel_cmds/apply_image_preserve_tests.rs +++ b/crates/engine-core/src/cmd/channel_cmds/apply_image_preserve_tests.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; /// Target "target" (document 0): white Background, layer "Top" transparent except a 0/255/0 /// square at alpha 128 over (10,4)-(19,13). Source "source" (document 1): 128/128/128. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "depth": depth, "name": "target"})).unwrap(); s.execute("file.new", json!({"width": 40, "height": 20, "depth": depth, "name": "source"})).unwrap(); s.execute("edit.fill", json!({"color": "#808080"})).unwrap(); diff --git a/crates/engine/src/cmd/channel_cmds/calc.rs b/crates/engine-core/src/cmd/channel_cmds/calc.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/calc.rs rename to crates/engine-core/src/cmd/channel_cmds/calc.rs diff --git a/crates/engine/src/cmd/channel_cmds/manage.rs b/crates/engine-core/src/cmd/channel_cmds/manage.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/manage.rs rename to crates/engine-core/src/cmd/channel_cmds/manage.rs diff --git a/crates/engine/src/cmd/channel_cmds/planes.rs b/crates/engine-core/src/cmd/channel_cmds/planes.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/planes.rs rename to crates/engine-core/src/cmd/channel_cmds/planes.rs diff --git a/crates/engine/src/cmd/channel_cmds/refs.rs b/crates/engine-core/src/cmd/channel_cmds/refs.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/refs.rs rename to crates/engine-core/src/cmd/channel_cmds/refs.rs diff --git a/crates/engine/src/cmd/channel_cmds/selection.rs b/crates/engine-core/src/cmd/channel_cmds/selection.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/selection.rs rename to crates/engine-core/src/cmd/channel_cmds/selection.rs diff --git a/crates/engine/src/cmd/channel_cmds/spot.rs b/crates/engine-core/src/cmd/channel_cmds/spot.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/spot.rs rename to crates/engine-core/src/cmd/channel_cmds/spot.rs diff --git a/crates/engine/src/cmd/channel_cmds/targeting.rs b/crates/engine-core/src/cmd/channel_cmds/targeting.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/targeting.rs rename to crates/engine-core/src/cmd/channel_cmds/targeting.rs diff --git a/crates/engine/src/cmd/channel_cmds/tests.rs b/crates/engine-core/src/cmd/channel_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/channel_cmds/tests.rs rename to crates/engine-core/src/cmd/channel_cmds/tests.rs index 36c6ef68da..da49686776 100644 --- a/crates/engine/src/cmd/channel_cmds/tests.rs +++ b/crates/engine-core/src/cmd/channel_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_color::SampleType; fn session_depth(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "depth": depth})).unwrap(); s } @@ -34,6 +34,7 @@ fn rect(s: &mut Session, x: i32, y: i32, w: u32, h: u32, mode: &str) { #[test] fn specs_are_documented_and_registered() { + crate::install().unwrap(); for sp in specs() { assert!(crate::commands::find(sp.id).is_some(), "{} not registered", sp.id); assert!(sp.params.starts_with('{'), "{}", sp.id); @@ -101,7 +102,7 @@ fn load_selection_operations_and_invert() { #[test] fn load_transparency_mask_and_composite() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "background": "transparent"})).unwrap(); rect(&mut s, 0, 0, 5, 10, "replace"); s.execute("edit.fill", json!({"color": "#ffffff"})).unwrap(); @@ -122,7 +123,7 @@ fn load_transparency_mask_and_composite() { /// A white CMYK document (no ink anywhere) whose left half carries some cyan ink. fn cmyk_session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": "cmyk", "depth": depth, "background": "white"})).unwrap(); rect(&mut s, 0, 0, 20, 20, "replace"); s.execute("edit.fill", json!({"color": "#00ffff"})).unwrap(); @@ -322,7 +323,7 @@ fn shortcut_slots_target_channels() { s.execute("channel.target.composite", json!({})).unwrap(); assert_eq!(s.active().unwrap().channel_view.target, ChannelTarget::Composite); // Grayscale: ⌘3 is the first alpha channel. - let mut g = Session::new(); + let mut g = crate::session(); g.execute("file.new", json!({"width": 4, "height": 4, "mode": "gray"})).unwrap(); g.execute("channel.new", json!({})).unwrap(); g.execute("channel.target.slot3", json!({})).unwrap(); @@ -538,7 +539,7 @@ fn quick_mask_round_trip_keeps_select_all() { #[test] fn quick_mask_odd_states_dont_panic() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("select.editInQuickMaskMode", json!({})).is_err(), "no document"); let _ = s.execute("channel.options", json!({"channel": "quickMask", "indicates": "selected"})); let mut s = session(); @@ -739,7 +740,7 @@ fn apply_image_from_an_rgb_document_onto_cmyk_reads_it_in_its_own_mode() { let near = |a: &[f32], b: &[f32]| a.len() == b.len() && a.iter().zip(b).all(|(x, y)| (x - y).abs() < 0.01); // #5787: an RGB composite is tone in RGB terms: white multiplied (the default) onto a CMYK // layer changes nothing. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "background": "white"})).unwrap(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": "cmyk", "background": "white"})).unwrap(); rect(&mut s, 0, 0, 20, 20, "replace"); @@ -767,7 +768,7 @@ fn apply_image_of_a_cmyk_composite_onto_a_spot_channel_blends_as_tone() { fn apply_image_of_a_cmyk_composite_onto_rgb_keeps_black() { // #5787: Black alone (no C, M or Y) applied from a CMYK document onto RGB stays black, and // the CMYK white stays white (the merged image goes through RGB, so a few levels of drift). - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": "cmyk", "background": "white"})).unwrap(); { let d = s.active_mut().unwrap(); @@ -790,7 +791,7 @@ fn apply_image_of_a_cmyk_composite_onto_an_alpha_channel_takes_its_luminosity() // #5787: a CMYK composite reaches a channel as its luminosity, as Calculations reads it, so // Black alone stays dark and white stays white. for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": "cmyk", "depth": depth, "background": "white"})).unwrap(); { let d = s.active_mut().unwrap(); @@ -902,7 +903,7 @@ fn split_and_merge_channels() { /// paper, dark ink), and merge back into the same inks. #[test] fn split_and_merge_cmyk_keep_ink_dark() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": "cmyk", "background": "white"})).unwrap(); // Rich black (#8359): its inks don't survive a trip through RGB, so the old path fails here. let rgb = photocraft_color::convert::cmyk_to_rgb([1.0, 1.0, 1.0, 0.0]).map(|c| c.clamp(0.0, 1.0)); @@ -1143,7 +1144,7 @@ fn command_alt_2_loads_the_images_luminosity() { #[test] fn thumbnail_selection_shape_without_pixel_cache_uses_its_transparency() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":100,"height":80,"depth":depth,"background":"transparent"})).unwrap(); let id = s.execute("shape.create", json!({"kind":"rect","rect":[20,10,40,30],"fill":"#cc3333"})).unwrap()["layer"].as_u64().unwrap(); s.edit("Drop render cache", |doc, _| { @@ -1222,7 +1223,7 @@ fn opened_documents_show_their_spot_channels() { let fmt = PixelFormat::new(ColorMode::Grayscale, SampleType::U8, false); d.channels.push(AlphaChannel::new("Alpha 1", photocraft_raster::Surface::new(fmt))); d.channels.push(AlphaChannel { spot: Some((Color::rgb(0.0, 0.6, 0.65), 0.0)), ..AlphaChannel::new("teal", photocraft_raster::Surface::new(fmt)) }); - let mut s = Session::new(); + let mut s = crate::session(); s.open_document(d, None); let v = &s.active().unwrap().channel_view; let spot_on = mode != ColorMode::Multichannel; @@ -1269,7 +1270,7 @@ fn split_refuses_an_image_with_more_than_one_layer() { /// (RGB or Lab) merges; two never merge (#11451). #[test] fn merge_channels_waits_for_three_grayscale_documents() { - let mut s = Session::new(); + let mut s = crate::session(); for _ in 0..2 { s.execute("file.new", json!({"width": 8, "height": 8, "mode": "grayscale"})).unwrap(); } diff --git a/crates/engine/src/cmd/channel_cmds/tone_target.rs b/crates/engine-core/src/cmd/channel_cmds/tone_target.rs similarity index 98% rename from crates/engine/src/cmd/channel_cmds/tone_target.rs rename to crates/engine-core/src/cmd/channel_cmds/tone_target.rs index 2235fbd331..e9c7a41547 100644 --- a/crates/engine/src/cmd/channel_cmds/tone_target.rs +++ b/crates/engine-core/src/cmd/channel_cmds/tone_target.rs @@ -66,7 +66,7 @@ mod tests { /// Oversized alpha addresses must remain invalid on 32-bit targets instead of wrapping. #[test] fn review_large_alpha_addresses_never_alias_real_channels() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8})).unwrap(); s.execute("channel.new", json!({"name":"First","fill":"white"})).unwrap(); s.execute("channel.new", json!({"name":"Second","fill":"white"})).unwrap(); @@ -85,7 +85,7 @@ mod tests { /// A malformed explicit colour address cannot turn into an alpha descriptor. #[test] fn review_invalid_colour_targets_never_fall_back_to_alpha() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8})).unwrap(); s.execute("channel.new", json!({"name":"Saved sky"})).unwrap(); for p in [json!({"target":{"color":0,"channel":0}}), json!({"target":{"colors":[0,99]}})] { @@ -102,7 +102,7 @@ mod tests { let mut doc = photocraft_doc::Document::new("Channels", photocraft_geom::Size::new(8, 8), photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U8); doc.channels.push(photocraft_doc::AlphaChannel::new("Saved", photocraft_raster::Surface::new(photocraft_color::PixelFormat::GRAY8))); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); assert!(resolve_tone_target(&s, false, &json!({"target":"pixels"})).is_err()); assert!(resolve_tone_target(&s, false, &json!({"target":{"color":0}})).is_err()); @@ -121,7 +121,7 @@ mod rabbit_tests { #[test] fn rabbit_vector_mask_tone_commands_refuse_pixel_fallback() { for (kind, params) in [("levels", json!({"gamma":2})), ("curves", json!({"points":[[0,255],[255,0]]}))] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8})).unwrap(); s.execute("edit.fill", json!({"contents":"color","color":"#404040"})).unwrap(); s.execute("layer.vectorMask.revealAll", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/channel_cmds/view.rs b/crates/engine-core/src/cmd/channel_cmds/view.rs similarity index 100% rename from crates/engine/src/cmd/channel_cmds/view.rs rename to crates/engine-core/src/cmd/channel_cmds/view.rs diff --git a/crates/engine/src/cmd/color_cmds.rs b/crates/engine-core/src/cmd/color_cmds.rs similarity index 99% rename from crates/engine/src/cmd/color_cmds.rs rename to crates/engine-core/src/cmd/color_cmds.rs index 11a6d4cf3e..fb860fd601 100644 --- a/crates/engine/src/cmd/color_cmds.rs +++ b/crates/engine-core/src/cmd/color_cmds.rs @@ -1464,7 +1464,7 @@ mod tests { /// converted tile for the whole grid, the same colour everywhere. #[test] fn mode_conversion_keeps_shared_tiles_shared() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2048, "height": 1024, "background": "white"})).unwrap(); let distinct = |s: &Session| { let doc = &s.active().unwrap().doc; @@ -1484,7 +1484,7 @@ mod tests { } fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "mode": mode, "depth": depth})).unwrap(); s } @@ -1689,7 +1689,7 @@ mod tests { #[test] #[ignore] fn bench_cmyk_conversion_6016() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6016, "height": 6016, "mode": "rgb", "depth": 8})).unwrap(); s.edit("noise", |doc, _| { let r = doc.bounds(); @@ -1736,7 +1736,7 @@ mod settings_tests { #[test] fn color_settings_validate_and_report() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("edit.colorSettings", json!({})).unwrap(); assert_eq!(r["settings"]["workingRgb"], "srgb"); assert!(s.execute("edit.colorSettings", json!({"workingRgb": "coated-cmyk"})).is_err()); @@ -1746,7 +1746,7 @@ mod settings_tests { assert!(r["working"]["rgb"].as_str().unwrap().starts_with("Adobe RGB")); assert_eq!(s.color.settings.intent(), Intent::Perceptual); // Settings travel with the preferences file. - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(t.color.settings, s.color.settings); } @@ -1756,7 +1756,7 @@ mod settings_tests { #[test] fn open_question_asks_only_when_set_and_resolve_open_applies_each_answer() { - let mut s = Session::new(); + let mut s = crate::session(); // Ask When Opening off: nothing to ask, mismatched or missing. s.execute("edit.colorSettings", json!({"askOnMismatch": false, "askOnMissing": false})).unwrap(); assert!(s.color.open_question(&tagged("adobe-rgb-compat")).is_none()); @@ -1785,7 +1785,7 @@ mod settings_tests { #[test] fn open_policies() { - let mut s = Session::new(); + let mut s = crate::session(); // Preserve (default): an Adobe RGB file keeps its profile and asks. let (_, r) = s.open_document(tagged("adobe-rgb-compat"), None); assert_eq!((r["action"].as_str(), r["mismatch"].as_bool(), r["ask"].as_bool()), (Some("kept"), Some(true), Some(true))); @@ -1872,7 +1872,7 @@ mod settings_tests { let input = input_only_p3(); assert!(Builtin::DisplayP3.profile().can_be_destination()); assert!(!input.can_be_destination()); - let mut s = Session::new(); + let mut s = crate::session(); let mut d = tagged("srgb"); d.icc_profile = Some(input.to_bytes()); let (photo, r) = s.open_document(d, None); @@ -1916,7 +1916,7 @@ mod settings_tests { /// The tag survives a real JPEG: written without an ICC profile, read back, opened as sRGB. #[test] fn exif_srgb_jpeg_round_trip() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"workingRgb": "display-p3"})).unwrap(); // Embed Color Profile off: an untagged document is otherwise tagged sRGB on export (#9325). let mut opts = photocraft_io::ExportOptions::default(); @@ -1933,7 +1933,7 @@ mod settings_tests { /// Photoshop; Ignore EXIF Profile Tag opens it untagged (the working space). #[test] fn exif_srgb_tag_unless_ignored() { - let mut s = Session::new(); + let mut s = crate::session(); // Working sRGB: tagged sRGB, nothing to ask. let (_, r) = s.open_document(untagged_camera_file(Some(1)), None); assert_eq!((r["action"].as_str(), r["exif"].as_bool(), r.get("ask")), (Some("kept"), Some(true), None)); @@ -1969,7 +1969,7 @@ mod settings_tests { #[test] fn mode_conversion_uses_working_spaces() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"workingRgb": "rec2020"})).unwrap(); for depth in [8, 16, 32] { s.execute("file.new", json!({"width": 8, "height": 8, "mode": "gray", "depth": depth})).unwrap(); @@ -1985,7 +1985,7 @@ mod settings_tests { #[test] fn mismatch_resolution_command() { - let mut s = Session::new(); + let mut s = crate::session(); s.open_document(tagged("adobe-rgb-compat"), None); s.execute("color.profileMismatch", json!({"action": "convert"})).unwrap(); assert!(desc(&s.active().unwrap().doc).unwrap().starts_with("sRGB")); diff --git a/crates/engine/src/cmd/color_cmds/convert_profile_bitmap_tests.rs b/crates/engine-core/src/cmd/color_cmds/convert_profile_bitmap_tests.rs similarity index 92% rename from crates/engine/src/cmd/color_cmds/convert_profile_bitmap_tests.rs rename to crates/engine-core/src/cmd/color_cmds/convert_profile_bitmap_tests.rs index 0aa50d9fe1..8231006402 100644 --- a/crates/engine/src/cmd/color_cmds/convert_profile_bitmap_tests.rs +++ b/crates/engine-core/src/cmd/color_cmds/convert_profile_bitmap_tests.rs @@ -5,7 +5,7 @@ use super::*; fn bitmap() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); s.execute("image.mode.grayscale", json!({})).unwrap(); s.execute("image.mode.bitmap", json!({})).unwrap(); @@ -31,12 +31,12 @@ fn convert_to_profile_is_greyed_and_refused_for_bitmap() { #[test] fn convert_to_profile_stays_enabled_for_the_other_modes() { for (mode, depth) in [("rgb", 8), ("rgb", 16), ("rgb", 32), ("cmyk", 8), ("grayscale", 16), ("lab", 8), ("indexedColor", 8)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth, "background": "white"})).unwrap(); if mode != "rgb" { s.execute(&format!("image.mode.{mode}"), json!({})).unwrap(); } assert!(s.is_enabled("edit.convertToProfile"), "{mode} {depth}-bit"); } - assert!(!Session::new().is_enabled("edit.convertToProfile"), "no document"); + assert!(!crate::session().is_enabled("edit.convertToProfile"), "no document"); } diff --git a/crates/engine/src/cmd/color_cmds/convert_profile_same_tests.rs b/crates/engine-core/src/cmd/color_cmds/convert_profile_same_tests.rs similarity index 99% rename from crates/engine/src/cmd/color_cmds/convert_profile_same_tests.rs rename to crates/engine-core/src/cmd/color_cmds/convert_profile_same_tests.rs index dcf026ee62..4dff502cf7 100644 --- a/crates/engine/src/cmd/color_cmds/convert_profile_same_tests.rs +++ b/crates/engine-core/src/cmd/color_cmds/convert_profile_same_tests.rs @@ -5,7 +5,7 @@ use super::*; /// A 16×8 sRGB-tagged document with a red background. fn tagged() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 8, "background": "#c81e1e"})).unwrap(); s.execute("edit.assignProfile", json!({"profile": "srgb"})).unwrap(); assert!(s.active().unwrap().doc.icc_profile.is_some(), "tagged"); diff --git a/crates/engine/src/cmd/color_cmds/profile_dither.rs b/crates/engine-core/src/cmd/color_cmds/profile_dither.rs similarity index 100% rename from crates/engine/src/cmd/color_cmds/profile_dither.rs rename to crates/engine-core/src/cmd/color_cmds/profile_dither.rs diff --git a/crates/engine/src/cmd/color_replacement_history_name_tests.rs b/crates/engine-core/src/cmd/color_replacement_history_name_tests.rs similarity index 96% rename from crates/engine/src/cmd/color_replacement_history_name_tests.rs rename to crates/engine-core/src/cmd/color_replacement_history_name_tests.rs index 4f20d6783e..55b9963516 100644 --- a/crates/engine/src/cmd/color_replacement_history_name_tests.rs +++ b/crates/engine-core/src/cmd/color_replacement_history_name_tests.rs @@ -7,7 +7,7 @@ use serde_json::json; use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("tools.setColors", json!({"foreground": "#0000ff"})).unwrap(); s @@ -40,6 +40,7 @@ fn every_click_stroke_and_segment_is_one_color_replacement_tool_state() { #[test] fn recorded_steps_use_the_same_name() { + crate::install().unwrap(); let spec = crate::commands::find("paint.colorReplacement").expect("the command"); assert_eq!(spec.label, COLOR_REPLACEMENT_STEP); } diff --git a/crates/engine/src/cmd/color_replacement_modes_tests.rs b/crates/engine-core/src/cmd/color_replacement_modes_tests.rs similarity index 98% rename from crates/engine/src/cmd/color_replacement_modes_tests.rs rename to crates/engine-core/src/cmd/color_replacement_modes_tests.rs index b9c454fb33..421c70c57c 100644 --- a/crates/engine/src/cmd/color_replacement_modes_tests.rs +++ b/crates/engine-core/src/cmd/color_replacement_modes_tests.rs @@ -15,7 +15,7 @@ const INDEXED: &str = "Could not use the Color Replacement tool because it does /// A session with one 64 × 64 document of `mode` and `depth`, filled red. fn session(mode: ColorMode, depth: SampleType) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::with_background("t", Size::new(64, 64), mode, depth, Color::rgb(220.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0)), None); s.tools.foreground = [0.0, 0.0, 1.0, 1.0]; s diff --git a/crates/engine/src/cmd/color_to_alpha_cmds.rs b/crates/engine-core/src/cmd/color_to_alpha_cmds.rs similarity index 99% rename from crates/engine/src/cmd/color_to_alpha_cmds.rs rename to crates/engine-core/src/cmd/color_to_alpha_cmds.rs index ba8b1aebcc..6c9b76c545 100644 --- a/crates/engine/src/cmd/color_to_alpha_cmds.rs +++ b/crates/engine-core/src/cmd/color_to_alpha_cmds.rs @@ -128,7 +128,7 @@ mod tests { /// A document with a white Background and, when `layer`, a pixel layer on top; both filled /// with a black-to-white ramp (column 0 black, last column white). fn session(depth: u32, mode: &str, layer: bool) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth, "mode": mode})).unwrap(); if layer { s.execute("layer.new.layer", json!({})).unwrap(); @@ -236,12 +236,12 @@ mod tests { assert!(!s.is_enabled(ID)); for mode in ["cmyk", "lab"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "mode": mode})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); assert!(!s.is_enabled(ID), "{mode}"); } - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled(ID)); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/comps_cmds.rs b/crates/engine-core/src/cmd/comps_cmds.rs similarity index 100% rename from crates/engine/src/cmd/comps_cmds.rs rename to crates/engine-core/src/cmd/comps_cmds.rs diff --git a/crates/engine/src/cmd/comps_cmds/layer_comps_to_files_history_tests.rs b/crates/engine-core/src/cmd/comps_cmds/layer_comps_to_files_history_tests.rs similarity index 99% rename from crates/engine/src/cmd/comps_cmds/layer_comps_to_files_history_tests.rs rename to crates/engine-core/src/cmd/comps_cmds/layer_comps_to_files_history_tests.rs index f7022afcf4..ba73508950 100644 --- a/crates/engine/src/cmd/comps_cmds/layer_comps_to_files_history_tests.rs +++ b/crates/engine-core/src/cmd/comps_cmds/layer_comps_to_files_history_tests.rs @@ -4,7 +4,7 @@ use photocraft_geom::Rect; /// A 64 x 48 document with a red layer A and a blue layer B and three comps: both shown, B hidden, A hidden. fn session() -> (Session, LayerId, LayerId, Vec) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); let (a, b) = s .edit("setup", |doc, _| { diff --git a/crates/engine/src/cmd/comps_cmds/tests.rs b/crates/engine-core/src/cmd/comps_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/comps_cmds/tests.rs rename to crates/engine-core/src/cmd/comps_cmds/tests.rs index 79cbf4eb80..965d5fec48 100644 --- a/crates/engine/src/cmd/comps_cmds/tests.rs +++ b/crates/engine-core/src/cmd/comps_cmds/tests.rs @@ -4,7 +4,7 @@ use photocraft_doc::Layer; use photocraft_geom::Rect; fn session(depth: u32) -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); let (a, b) = s .edit("setup", |doc, _| { @@ -322,7 +322,7 @@ fn warnings_for_deleted_layers() { #[test] fn disabled_states_and_bad_params() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("layerComp.new")); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert!(s.is_enabled("layerComp.new")); @@ -373,7 +373,7 @@ fn export_comps_to_files_naming() { #[test] fn out_of_range_comp_ids_are_rejected_not_wrapped() { // #914: 2^32 + id used to wrap to a real comp. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let c = s.execute("layerComp.new", json!({"name": "Start"})).unwrap()["comp"].as_u64().unwrap(); let wrapped = (1u64 << 32) + c; @@ -486,7 +486,7 @@ fn reorder_comps_preserves_capture_and_applied_state_and_undoes() { #[test] fn reorder_comps_rejects_bad_indices_without_changes() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("layerComp.reorder")); s.execute("file.new", json!({"width":8, "height":8})).unwrap(); assert!(!s.is_enabled("layerComp.reorder")); diff --git a/crates/engine/src/cmd/contour_lib_cmds.rs b/crates/engine-core/src/cmd/contour_lib_cmds.rs similarity index 98% rename from crates/engine/src/cmd/contour_lib_cmds.rs rename to crates/engine-core/src/cmd/contour_lib_cmds.rs index 36ba5ac209..6e7a13ae06 100644 --- a/crates/engine/src/cmd/contour_lib_cmds.rs +++ b/crates/engine-core/src/cmd/contour_lib_cmds.rs @@ -239,7 +239,7 @@ mod tests { #[test] fn new_save_load_round_trips_and_names_stay_unique() { - let mut s = Session::new(); + let mut s = crate::session(); let r = new(&mut s, &json!({"contour": curve("x"), "name": "Ramp"})).unwrap(); assert_eq!(r["name"], "Ramp"); // A standard contour's name can't be shadowed; repeats get a suffix. @@ -263,10 +263,10 @@ mod tests { #[test] fn library_persists_with_the_presets() { - let mut s = Session::new(); + let mut s = crate::session(); new(&mut s, &json!({"contour": curve("x"), "name": "Mine"})).unwrap(); let saved = s.presets.to_json(&s); - let mut t = Session::new(); + let mut t = crate::session(); t.load_presets_json(saved); assert_eq!(t.presets.contours.len(), 1); assert_eq!(name_of(&t.presets.contours[0]), "Mine"); @@ -275,7 +275,7 @@ mod tests { #[test] fn bad_params_are_errors_not_panics() { - let mut s = Session::new(); + let mut s = crate::session(); for p in [json!({}), json!({"contour": 5}), json!({"contour": "Nope"}), json!({"contour": {"points": [[0, 0]]}}), json!({"contour": curve("x"), "name": 3})] { @@ -305,7 +305,7 @@ mod tests { } #[test] fn malformed_persisted_library_keeps_existing_contours() { - let mut s = Session::new(); + let mut s = crate::session(); new(&mut s, &json!({"contour": curve("x"), "name": "Existing"})).unwrap(); let before = s.presets.contours.clone(); for value in [json!(null), json!(3), json!("bad"), json!({})] { diff --git a/crates/engine/src/cmd/count_delete_group_tests.rs b/crates/engine-core/src/cmd/count_delete_group_tests.rs similarity index 97% rename from crates/engine/src/cmd/count_delete_group_tests.rs rename to crates/engine-core/src/cmd/count_delete_group_tests.rs index bdabca1c73..151cefc873 100644 --- a/crates/engine/src/cmd/count_delete_group_tests.rs +++ b/crates/engine-core/src/cmd/count_delete_group_tests.rs @@ -7,7 +7,7 @@ use crate::Session; /// Three groups, each with one marker, and the second one current. fn three_groups() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); for (i, name) in ["One", "Two", "Three"].iter().enumerate() { s.execute("count.newGroup", json!({"name": name})).unwrap(); @@ -52,7 +52,7 @@ fn deleting_another_group_keeps_the_current_one() { #[test] fn deleting_the_last_group_leaves_none() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("count.newGroup", json!({"name": "Only"})).unwrap(); s.execute("count.deleteGroup", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/count_history_names_tests.rs b/crates/engine-core/src/cmd/count_history_names_tests.rs similarity index 98% rename from crates/engine/src/cmd/count_history_names_tests.rs rename to crates/engine-core/src/cmd/count_history_names_tests.rs index 2cfa357ab4..ceaddece40 100644 --- a/crates/engine/src/cmd/count_history_names_tests.rs +++ b/crates/engine-core/src/cmd/count_history_names_tests.rs @@ -9,7 +9,7 @@ use crate::Session; /// A 100 × 100 document with one count group holding one marker at 10,10 (its first state is /// "Add Count Object"). fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("count.add", json!({"x": 10, "y": 10})).unwrap(); s @@ -29,7 +29,7 @@ fn named(s: &mut Session, id: &str, p: Value) -> String { #[test] fn marker_edits_are_add_drag_and_delete_count_object() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); // The first click makes "Count Group 1" too, still one "Add Count Object" step. assert_eq!(named(&mut s, "count.add", json!({"x": 10, "y": 10})), "Add Count Object"); diff --git a/crates/engine/src/cmd/count_record_label_tests.rs b/crates/engine-core/src/cmd/count_record_label_tests.rs similarity index 98% rename from crates/engine/src/cmd/count_record_label_tests.rs rename to crates/engine-core/src/cmd/count_record_label_tests.rs index 3b49b2dd38..57738be429 100644 --- a/crates/engine/src/cmd/count_record_label_tests.rs +++ b/crates/engine-core/src/cmd/count_record_label_tests.rs @@ -6,7 +6,7 @@ use serde_json::{Value, json}; use crate::Session; fn five_counts() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); for i in 0..5 { s.execute("count.add", json!({"x": 10 + 10 * i, "y": 10})).unwrap(); diff --git a/crates/engine/src/cmd/count_resize_tests.rs b/crates/engine-core/src/cmd/count_resize_tests.rs similarity index 97% rename from crates/engine/src/cmd/count_resize_tests.rs rename to crates/engine-core/src/cmd/count_resize_tests.rs index 7648ed0051..1b9a8346fd 100644 --- a/crates/engine/src/cmd/count_resize_tests.rs +++ b/crates/engine-core/src/cmd/count_resize_tests.rs @@ -9,7 +9,7 @@ use crate::Session; const POINT: [f64; 2] = [99.3, 99.7]; fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400})).unwrap(); s.execute("count.add", json!({"x": POINT[0], "y": POINT[1]})).unwrap(); s.execute("notes.add", json!({"x": 100, "y": 100})).unwrap(); @@ -67,7 +67,7 @@ fn crop_still_moves_count_points() { #[test] fn ruler_straighten_with_crop_moves_count_points_with_the_image() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400})).unwrap(); s.execute("count.add", json!({"x": 250, "y": 150})).unwrap(); s.execute("notes.add", json!({"x": 250, "y": 150})).unwrap(); @@ -81,7 +81,7 @@ fn ruler_straighten_with_crop_moves_count_points_with_the_image() { #[test] fn ruler_straighten_with_crop_asks_the_gate_for_its_rotation() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400})).unwrap(); // Straighten Layer is off for the Background (#12033). s.execute("layer.new.layer", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/cutout_cmds.rs b/crates/engine-core/src/cmd/cutout_cmds.rs similarity index 99% rename from crates/engine/src/cmd/cutout_cmds.rs rename to crates/engine-core/src/cmd/cutout_cmds.rs index 971519254a..c8e2d862a7 100644 --- a/crates/engine/src/cmd/cutout_cmds.rs +++ b/crates/engine-core/src/cmd/cutout_cmds.rs @@ -109,7 +109,7 @@ mod tests { use photocraft_doc::LayerId; fn session_with(w: u32, h: u32, depth: u32, px: impl Fn(u32, u32) -> [f32; 3]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -246,8 +246,8 @@ mod tests { #[test] fn remove_background_disabled_states_and_bad_params() { - assert!(!Session::new().is_enabled(CMD)); - assert!(Session::new().execute(CMD, json!({})).is_err()); + assert!(!crate::session().is_enabled(CMD)); + assert!(crate::session().execute(CMD, json!({})).is_err()); let (mut s, _) = disc(8); s.execute("type.create", json!({"text": "Hi", "size": 24, "x": 10, "y": 20})).unwrap(); diff --git a/crates/engine/src/cmd/direct_select_history_names_tests.rs b/crates/engine-core/src/cmd/direct_select_history_names_tests.rs similarity index 98% rename from crates/engine/src/cmd/direct_select_history_names_tests.rs rename to crates/engine-core/src/cmd/direct_select_history_names_tests.rs index 09d9082862..f0c6508ac8 100644 --- a/crates/engine/src/cmd/direct_select_history_names_tests.rs +++ b/crates/engine-core/src/cmd/direct_select_history_names_tests.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; use crate::Session; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "background": "white"})).unwrap(); // Knot 1 at (120, 40) is smooth, with handles at (100, 40) and (140, 40). let path = json!({"subpaths": [{"closed": true, "knots": [ @@ -80,6 +80,7 @@ fn an_unknown_step_name_is_refused_and_changes_nothing() { #[test] fn the_command_list_says_the_new_names() { + crate::install().unwrap(); let specs = crate::command_specs(); let spec = |id: &str| specs.iter().find(|c| c.id == id).unwrap(); assert_eq!(spec("path.moveHandle").label, "Drag Control Point"); diff --git a/crates/engine/src/cmd/distort_cmds.rs b/crates/engine-core/src/cmd/distort_cmds.rs similarity index 100% rename from crates/engine/src/cmd/distort_cmds.rs rename to crates/engine-core/src/cmd/distort_cmds.rs diff --git a/crates/engine/src/cmd/distort_cmds/tests.rs b/crates/engine-core/src/cmd/distort_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/distort_cmds/tests.rs rename to crates/engine-core/src/cmd/distort_cmds/tests.rs index 851b785814..a7e198f996 100644 --- a/crates/engine/src/cmd/distort_cmds/tests.rs +++ b/crates/engine-core/src/cmd/distort_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; /// 80×60 document, a new layer with a patterned 50×30 block at (10, 10). fn session(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -249,7 +249,7 @@ fn puppet_mesh_follows_the_outline_so_separate_shapes_move_separately() { // The mesh now follows the outline grown by the expansion: two meshes, and the unpinned one // stays put. for depth in [8u64, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 260, "height": 140, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -384,14 +384,14 @@ fn enabled_states() { assert!(!s.is_enabled(PUPPET_SMART) && !s.is_enabled(PERSPECTIVE_SMART)); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); assert!(!s.is_enabled(PUPPET) && !s.is_enabled(PERSPECTIVE)); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(!empty.is_enabled(LIQUIFY)); assert!(empty.execute(PUPPET, json!({"pins": []})).is_err()); } #[test] fn background_layer_is_floated_by_geometric_warps() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": 8})).unwrap(); s.execute(PUPPET, json!({"pins": [{"src": [20, 15], "dst": [25, 15]}], "mode": "rigid"})).unwrap(); let st = s.active().unwrap(); diff --git a/crates/engine/src/cmd/document_preset_cmds.rs b/crates/engine-core/src/cmd/document_preset_cmds.rs similarity index 97% rename from crates/engine/src/cmd/document_preset_cmds.rs rename to crates/engine-core/src/cmd/document_preset_cmds.rs index ccdaf45970..85d77dc4fc 100644 --- a/crates/engine/src/cmd/document_preset_cmds.rs +++ b/crates/engine-core/src/cmd/document_preset_cmds.rs @@ -416,7 +416,7 @@ mod tests { } fn reload(s: &Session) -> Session { - let mut next = Session::new(); + let mut next = crate::session(); next.load_prefs_json(&s.prefs_to_json()).unwrap(); next } @@ -425,7 +425,7 @@ mod tests { /// `file.new`; one saved without it (or before it existed) stays on the working space. #[test] fn the_color_profile_survives_save_reload_and_file_new() { - let mut s = Session::new(); + let mut s = crate::session(); let mut config = settings(); config["mode"] = json!("cmyk"); config["profile"] = json!("coated-cmyk"); @@ -434,7 +434,7 @@ mod tests { let next = reload(&s); let params = next.presets.documents[0].settings.command_params(); assert_eq!(params["profile"], "coated-cmyk"); - let mut s2 = Session::new(); + let mut s2 = crate::session(); s2.execute("file.new", params).unwrap(); assert!(s2.active().unwrap().doc.icc_profile.is_some()); let plain = saved(&mut s, "Plain", settings()); @@ -446,7 +446,7 @@ mod tests { fn every_field_survives_save_reload_and_file_new() { for mode in ["rgb", "gray", "cmyk", "lab"] { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); let mut config = settings(); config["mode"] = json!(mode); config["depth"] = json!(depth); @@ -482,7 +482,7 @@ mod tests { ("#ff0000", [1.0, 0.0, 0.0, 1.0]), ("backgroundColor", [0.125, 0.375, 0.625, 1.0]), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.tools.background = [0.125, 0.375, 0.625, 1.0]; saved(&mut s, "Background", json!({"width":4,"height":4,"background":background,"depth":32})); let mut s = reload(&s); @@ -500,7 +500,7 @@ mod tests { #[test] fn deletion_marks_preferences_dirty_and_survives_reload() { - let mut s = Session::new(); + let mut s = crate::session(); saved(&mut s, "Delete me", settings()); saved(&mut s, "Keep me", settings()); let mut s = reload(&s); @@ -516,14 +516,14 @@ mod tests { #[test] fn old_preferences_and_malformed_presets_keep_unrelated_settings() { - let mut original = Session::new(); + let mut original = crate::session(); original.edit_prefs(|p| p.general.beep_when_done = true); original.presets.tool_presets[0].name = "Unrelated tool preset".into(); let valid = saved(&mut original, "Keep me", settings()); for invalid in [json!("bad collection"), json!([false, {}, {"name":"broken","settings":{}}])] { let mut value = original.prefs_value(); value["presets"]["documents"] = invalid; - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&value.to_string()).unwrap(); assert!(s.prefs().general.beep_when_done); assert_eq!(s.presets.tool_presets[0].name, "Unrelated tool preset"); @@ -533,7 +533,7 @@ mod tests { let mut bad = valid.clone(); bad["settings"]["width"] = json!(0); value["presets"]["documents"] = json!([bad, valid, valid]); - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&value.to_string()).unwrap(); assert_eq!(s.presets.documents.len(), 1, "keep valid entries, discard bad/duplicate entries"); assert_eq!(s.presets.documents[0].name, "Keep me"); @@ -544,7 +544,7 @@ mod tests { } else { value["presets"].as_object_mut().unwrap().remove("documents"); } - let mut old = Session::new(); + let mut old = crate::session(); old.load_prefs_json(&value.to_string()).unwrap(); assert!(old.presets.documents.is_empty()); assert!(old.prefs().general.beep_when_done); @@ -553,7 +553,7 @@ mod tests { #[test] fn bad_input_and_duplicate_names_never_replace_or_mutate_a_snapshot() { - let mut s = Session::new(); + let mut s = crate::session(); let mut config = settings(); saved(&mut s, "Keep me", config.clone()); config["width"] = json!(99); @@ -596,7 +596,7 @@ mod tests { #[test] fn recent_lists_created_settings_newest_first_capped_and_survives_reload() { - let mut s = Session::new(); + let mut s = crate::session(); let add = |s: &mut Session, w: u32, unit: &str| s.execute("document.recent.add", json!({"settings":{"width":w,"height":10,"unit":unit}})); for w in 1..=MAX_RECENT as u32 + 5 { add(&mut s, w, "px").unwrap(); @@ -618,7 +618,7 @@ mod tests { assert_eq!(s.prefs.rev(), rev); let mut value = s.prefs_value(); value["presets"]["recent_documents"] = json!([{"width":-1}, recent[1], "junk", recent[1], recent[2]]); - let mut next = Session::new(); + let mut next = crate::session(); next.load_prefs_json(&value.to_string()).unwrap(); assert_eq!(next.presets.recent_documents.iter().map(|r| r.width).collect::>(), [25, 24]); assert!(next.documents().is_empty(), "recording never creates a document"); @@ -626,7 +626,7 @@ mod tests { #[test] fn a_rename_keeps_the_position_refuses_another_presets_name_and_allows_a_change_of_case() { - let mut s = Session::new(); + let mut s = crate::session(); for name in ["One", "Two", "Three"] { saved(&mut s, name, settings()); } @@ -645,7 +645,7 @@ mod tests { #[test] fn invalid_explicit_background_colour_does_not_create_a_document() { - let mut s = Session::new(); + let mut s = crate::session(); for color in [Value::Null, json!([1, 2]), json!([1, -1, 0]), json!("red")] { assert!(s.execute("file.new", json!({"background":"backgroundColor","backgroundColor":color})).is_err()); assert!(s.documents().is_empty()); @@ -656,7 +656,7 @@ mod tests { /// covers the largest new document (#2935), and such a document round-trips. #[test] fn the_largest_new_document_reopens_from_pcraft() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": MAX_DIMENSION, "height": MAX_DIMENSION, "background": "transparent"})).unwrap(); let doc = &s.active().unwrap().doc; let bytes = photocraft_format::save_to_bytes(doc, &Default::default()).unwrap(); diff --git a/crates/engine/src/cmd/droplet_skip_non_images_tests.rs b/crates/engine-core/src/cmd/droplet_skip_non_images_tests.rs similarity index 84% rename from crates/engine/src/cmd/droplet_skip_non_images_tests.rs rename to crates/engine-core/src/cmd/droplet_skip_non_images_tests.rs index 7bc3964c3c..b97f4e7121 100644 --- a/crates/engine/src/cmd/droplet_skip_non_images_tests.rs +++ b/crates/engine-core/src/cmd/droplet_skip_non_images_tests.rs @@ -10,14 +10,14 @@ fn tmp(name: &str) -> String { } fn small_png(path: &str) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 3, "background": "#808080"})).unwrap(); crate::file_cmds::save_doc(&s.active().unwrap().doc, path, None).unwrap(); } /// Makes `dir/Rotate.pcdroplet`, writing its output to `dir/out`. fn droplet(dir: &str) -> String { - let r = Session::new() + let r = crate::session() .execute( "file.automate.createDroplet", json!({"path": format!("{dir}/Rotate"), "steps": [["image.imageRotation.90cw", {}]], "format": "png", "output": format!("{dir}/out"), "shim": false}), @@ -33,7 +33,7 @@ fn a_dropped_text_file_is_skipped_and_the_image_is_processed() { std::fs::write(&txt, "just some notes").unwrap(); small_png(&png); let dp = droplet(&dir); - let r = Session::new().execute("file.automate.runDroplet", json!({"droplet": dp, "input": [txt, png]})).unwrap(); + let r = crate::session().execute("file.automate.runDroplet", json!({"droplet": dp, "input": [txt, png]})).unwrap(); assert_eq!(r["errors"], json!([]), "{r}"); assert_eq!(r["files"].as_array().unwrap().len(), 1, "{r}"); assert!(std::path::Path::new(&format!("{dir}/out/a.png")).exists()); @@ -46,7 +46,7 @@ fn a_dropped_broken_image_still_reports_its_error() { std::fs::write(&bad, "not a png").unwrap(); small_png(&png); let dp = droplet(&dir); - let r = Session::new().execute("file.automate.runDroplet", json!({"droplet": dp, "input": [bad, png]})).unwrap(); + let r = crate::session().execute("file.automate.runDroplet", json!({"droplet": dp, "input": [bad, png]})).unwrap(); assert_eq!(r["errors"].as_array().unwrap().len(), 1, "{r}"); assert!(r["errors"][0].to_string().contains("broken.png"), "{r}"); assert_eq!(r["files"].as_array().unwrap().len(), 1, "{r}"); @@ -60,7 +60,7 @@ fn a_folder_input_skips_non_images_as_before() { std::fs::write(format!("{input}/notes.txt"), "just some notes").unwrap(); small_png(&format!("{input}/a.png")); let dp = droplet(&dir); - let r = Session::new().execute("file.automate.runDroplet", json!({"droplet": dp, "input": [input]})).unwrap(); + let r = crate::session().execute("file.automate.runDroplet", json!({"droplet": dp, "input": [input]})).unwrap(); assert_eq!(r["errors"], json!([]), "{r}"); assert_eq!(r["files"].as_array().unwrap().len(), 1, "{r}"); } diff --git a/crates/engine/src/cmd/edit_cmds.rs b/crates/engine-core/src/cmd/edit_cmds.rs similarity index 100% rename from crates/engine/src/cmd/edit_cmds.rs rename to crates/engine-core/src/cmd/edit_cmds.rs diff --git a/crates/engine/src/cmd/edit_cmds/tests.rs b/crates/engine-core/src/cmd/edit_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/edit_cmds/tests.rs rename to crates/engine-core/src/cmd/edit_cmds/tests.rs index ead879d0d1..629c8fe2da 100644 --- a/crates/engine/src/cmd/edit_cmds/tests.rs +++ b/crates/engine-core/src/cmd/edit_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, a| { @@ -14,7 +14,7 @@ fn session() -> Session { #[test] fn new_clipboard_document_rejects_an_unrepresentable_origin() { - let mut s = Session::new(); + let mut s = crate::session(); let mut surface = Surface::new(PixelFormat::RGBA8); surface.write_pixel(i32::MIN, 0, &[1.0, 0.0, 0.0, 1.0]); *s.clipboard = Some(Clip { @@ -38,7 +38,7 @@ fn new_clipboard_document_rejects_an_unrepresentable_origin() { /// in another, even where their old position would fit (Photoshop's Paste). #[test] fn paste_centres_pixels_from_another_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap(); s.execute("select.all", json!({})).unwrap(); s.execute("edit.copy", json!({})).unwrap(); @@ -186,7 +186,7 @@ fn active_bounds(s: &Session) -> Rect { /// so a later Image Size by resolution scales from the right size. #[test] fn new_from_clipboard_keeps_the_source_resolution() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 40, "resolution": 300})).unwrap(); s.execute("select.all", json!({})).unwrap(); s.execute("edit.copy", json!({})).unwrap(); @@ -199,7 +199,7 @@ fn new_from_clipboard_keeps_the_source_resolution() { #[test] fn new_from_clipboard_and_paste_with_no_document() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("file.newFromClipboard") && !s.is_enabled("edit.paste"), "nothing copied yet"); assert!(s.execute("file.newFromClipboard", json!({})).is_err()); s.execute("file.new", json!({"width": 100, "height": 100, "depth": depth})).unwrap(); @@ -246,7 +246,7 @@ fn copy_paste_in_place_and_centred() { /// A `w`×`h` document with an opaque `cw`×`ch` image from another app on the clipboard. fn external_clip_session(w: i32, h: i32, cw: i32, ch: i32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); let mut surface = Surface::new(PixelFormat::RGBA8); surface.fill_rect(Rect::new(0, 0, cw, ch), &[1.0, 0.0, 0.0, 1.0]); @@ -362,7 +362,7 @@ fn copy_paste_between_documents() { fn paste_damages_only_the_pasted_layer() { let render = |s: &Session| photocraft_compose::render(&s.active().unwrap().doc, s.active().unwrap().doc.bounds()); for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 50, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 5, "y": 5, "width": 10, "height": 8})).unwrap(); @@ -399,7 +399,7 @@ fn paste_damages_only_the_pasted_layer() { /// #1035: a `depth`-bit document with a blue-grey square copied from layer `src` (at /// (5,5)-(15,15)) and an active layer `m` above it with a hide-all mask. fn mask_target_session(depth: u32) -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40, "depth": depth})).unwrap(); let src = LayerId(s.execute("layer.new.layer", json!({"name": "src"})).unwrap()["layer"].as_u64().unwrap()); s.execute("select.rect", json!({"x": 5, "y": 5, "width": 10, "height": 10})).unwrap(); @@ -496,7 +496,7 @@ fn mask_copy_takes_only_the_selection() { #[test] fn mask_copy_needs_a_mask_and_fails_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("edit.copy", json!({"target": "mask"})).is_err(), "no document"); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); assert!(s.execute("edit.copy", json!({"target": "mask"})).is_err(), "the layer has no mask"); @@ -620,7 +620,7 @@ fn transform_scale_grows_content() { fn cut_and_clear_on_the_background_fill_with_the_background_colour() { // The Background keeps its transparency lock: cutting fills with the background colour. let fresh = || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.tools.background = [1.0, 0.0, 0.0, 1.0]; s.execute("select.rect", json!({"x": 5, "y": 5, "width": 10, "height": 10})).unwrap(); @@ -651,7 +651,7 @@ fn layer_via_copy_of_a_background_keeps_colour_and_partial_selection() { // #668: lift reads only the selected area now; the result must be what converting the // whole layer gave: the colour, with the selection's coverage as alpha. for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth, "background": "#336699"})).unwrap(); s.edit("partial selection", |doc, _| { let mut m = photocraft_raster::Surface::new(PixelFormat::GRAY8); @@ -1057,7 +1057,7 @@ fn copy_paste_keeps_type_shape_and_group_layers() { #[test] fn cross_document_group_paste_renders_shapes_on_destination_canvas() { for (copy_to_document, depth) in [(false, 8), (true, 16)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":100,"height":100})).unwrap(); let mut ids = Vec::new(); for x in [10, 50] { @@ -1131,7 +1131,7 @@ fn paste_repairs_uncached_shapes_before_transform_and_effect_rendering() { #[test] fn copy_paste_keeps_fill_and_adjustment_layers() { for (depth, other) in [(8, 16), (16, 32), (32, 8)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 40, "depth": depth})).unwrap(); s.execute("layer.newFillLayer.gradient", json!({"from": "#000000", "to": "#ffffff", "angle": 0})).unwrap(); let LayerContent::Fill(fill) = active_content(&s) else { panic!("a fill layer") }; @@ -1163,7 +1163,7 @@ fn copy_paste_keeps_fill_and_adjustment_layers() { /// #2344: several adjustment layers, which show nothing alone, still copy and paste together. #[test] fn several_adjustment_layers_copy_together() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); let a = s.execute("layer.newAdjustmentLayer.levels", json!({})).unwrap()["layer"].as_u64().unwrap(); let b = s.execute("layer.newAdjustmentLayer.levels", json!({})).unwrap()["layer"].as_u64().unwrap(); @@ -1192,7 +1192,7 @@ fn merge_visible_keeps_hidden_layers() { #[test] fn auto_tone_stretches_a_low_contrast_layer() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64})).unwrap(); s.edit("grey ramp", |doc, _| { let surf = doc.layers[0].surface_mut().unwrap(); @@ -1305,7 +1305,7 @@ fn guides_are_undoable() { /// step, taking its colour along; a % position is of the new axis. #[test] fn move_guide_turns_a_guide() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); s.execute("view.newGuide", json!({"orientation": "horizontal", "position": 30, "color": "magenta"})).unwrap(); s.execute("view.newGuide", json!({"orientation": "horizontal", "position": 70})).unwrap(); @@ -1346,7 +1346,7 @@ fn ruler_origin_is_set_reset_and_undoable() { assert!(s.execute("view.setRulerOrigin", bad.clone()).is_err(), "{bad} is refused"); } assert_eq!(s.active().unwrap().doc.ruler_origin, [40.0, 12.5]); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute("view.setRulerOrigin", json!({"x": 1, "y": 2})).is_err()); assert!(empty.execute("view.resetRulerOrigin", json!({})).is_err()); } @@ -1360,7 +1360,7 @@ fn new_guide(s: &mut Session, orientation: &str, position: Value) -> f64 { #[test] fn guide_positions_take_photoshop_units() { - let mut s = Session::new(); + let mut s = crate::session(); // 4 × 2 inches at 100 ppi. s.execute("file.new", json!({"width": 400, "height": 200, "resolution": 100})).unwrap(); // Percent follows the guide's own axis: the width for a vertical guide, the height for a horizontal one. @@ -1386,7 +1386,7 @@ fn guide_positions_take_photoshop_units() { /// "300 / 2" → 150 (pixels), "1in + 10" → 792 (the bare 10 is in the first operand's unit). #[test] fn guide_positions_take_arithmetic() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400, "resolution": 72})).unwrap(); for (text, px) in [ ("100% / 3", 200.0), @@ -1411,7 +1411,7 @@ fn guide_positions_take_arithmetic() { /// numeric fields' own evaluator. #[test] fn guide_position_arithmetic_takes_the_unicode_minus() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400, "resolution": 72})).unwrap(); for (text, px) in [("100% − 50px", 550.0), ("−50px + 100", 50.0), ("1in − −10", 792.0), ("−100", -100.0)] { assert!((new_guide(&mut s, "vertical", json!(text)) - px).abs() < 1e-6, "{text}"); @@ -1421,7 +1421,7 @@ fn guide_position_arithmetic_takes_the_unicode_minus() { /// Text longer than the numeric fields' 1024-byte cap is refused before it is tokenised. #[test] fn guide_position_arithmetic_is_capped_at_1024_bytes() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400, "resolution": 72})).unwrap(); let fits = format!("{}100", "0 + ".repeat(255)); assert_eq!(fits.len(), 1023); @@ -1433,7 +1433,7 @@ fn guide_position_arithmetic_is_capped_at_1024_bytes() { #[test] fn new_guides_keep_their_own_colour_through_moves_deletes_and_undo() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); let color = |s: &Session, vertical: bool, p: f64| s.active().unwrap().doc.guides.color(vertical, p); // Without a colour a guide uses the preference colour, as ruler-drag guides always did. @@ -1462,7 +1462,7 @@ fn new_guides_keep_their_own_colour_through_moves_deletes_and_undo() { #[test] fn moving_one_of_two_coloured_guides_at_one_position_leaves_the_other_its_colour() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); for _ in 0..2 { s.execute("view.newGuide", json!({"orientation": "vertical", "position": 50, "color": "green"})).unwrap(); @@ -1481,7 +1481,7 @@ fn cyan_is_the_default_guide_colour_so_ruler_guides_read_as_cyan() { #[test] fn bad_guide_colours_are_refused_without_a_guide() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); let undo_before = s.active().unwrap().history.can_undo(); for bad in [json!("puce"), json!("#12345"), json!("#gggggg"), json!(""), json!(7), json!(null), json!(["cyan"])] { @@ -1494,7 +1494,7 @@ fn bad_guide_colours_are_refused_without_a_guide() { #[test] fn editing_a_guide_changes_what_is_given_in_one_undoable_step() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 10})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 20, "color": "magenta"})).unwrap(); @@ -1524,7 +1524,7 @@ fn editing_a_guide_changes_what_is_given_in_one_undoable_step() { /// the new orientation's extent. #[test] fn editing_a_guide_takes_arithmetic_in_its_position() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200, "resolution": 100})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 10})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 20})).unwrap(); @@ -1542,7 +1542,7 @@ fn editing_a_guide_takes_arithmetic_in_its_position() { #[test] fn bad_guide_edits_are_refused_without_a_history_step() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 10, "color": "green"})).unwrap(); let before = s.active().unwrap().doc.guides.clone(); @@ -1568,7 +1568,7 @@ fn bad_guide_edits_are_refused_without_a_history_step() { #[test] fn bad_guide_positions_are_refused_without_a_guide() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200, "resolution": 100})).unwrap(); let undo_before = s.active().unwrap().history.can_undo(); for bad in [ @@ -1701,7 +1701,7 @@ fn copy_shares_whole_tiles_with_the_layer() { /// Board "A" at (10, 10, 50, 50) holding a red square at (10..30)², and an empty board "B" at /// (200, 20, 240, 60), B active. fn two_boards() -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80})).unwrap(); let red = s.execute("layer.new.layer", json!({"name": "Red"})).unwrap()["layer"].as_u64().map(LayerId).unwrap(); s.edit("paint", |doc, _| { @@ -1826,7 +1826,7 @@ fn a_selection_copy_takes_the_active_layers_board_whatever_else_is_selected() { /// x = 10, and an area 9..11 wide whose middle (10) is on the right one (#10538 review). #[test] fn copy_merged_uses_the_true_middle_of_the_area() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20})).unwrap(); let left = s.execute("layer.new.artboard", json!({"rect": [0, 0, 10, 20], "name": "L"})).unwrap()["layer"].as_u64().map(LayerId).unwrap(); let right = s.execute("layer.new.artboard", json!({"rect": [10, 0, 10, 20], "name": "R"})).unwrap()["layer"].as_u64().map(LayerId).unwrap(); @@ -1857,7 +1857,7 @@ fn paste_with_a_locked_artboard_selected_is_not_moved_onto_it() { /// (30..40); the clip spans 9..11 (middle 10, on R) and moves by 20 to 29..31 (middle 30, on D). #[test] fn a_shifted_merged_clip_is_placed_inside_the_destination_board() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 50, "height": 20})).unwrap(); s.execute("layer.new.artboard", json!({"rect": [0, 0, 10, 20], "name": "L"})).unwrap(); let r = s.execute("layer.new.artboard", json!({"rect": [10, 0, 10, 20], "name": "R"})).unwrap()["layer"].as_u64().map(LayerId).unwrap(); @@ -1877,7 +1877,7 @@ fn a_shifted_merged_clip_is_placed_inside_the_destination_board() { /// x = 0. Truncating toward zero put it at 0, and the board took it in and clipped it. #[test] fn content_centred_just_left_of_a_board_is_not_placed_in_it() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20})).unwrap(); let b = s.execute("layer.new.artboard", json!({"rect": [0, 0, 20, 20], "name": "B"})).unwrap()["layer"].as_u64().map(LayerId).unwrap(); let place = |s: &mut Session, r: Rect| { diff --git a/crates/engine/src/cmd/edit_menu_cmds.rs b/crates/engine-core/src/cmd/edit_menu_cmds.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds.rs rename to crates/engine-core/src/cmd/edit_menu_cmds.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/caf_new_layer_name_tests.rs b/crates/engine-core/src/cmd/edit_menu_cmds/caf_new_layer_name_tests.rs similarity index 99% rename from crates/engine/src/cmd/edit_menu_cmds/caf_new_layer_name_tests.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/caf_new_layer_name_tests.rs index 3457863125..7274061b9c 100644 --- a/crates/engine/src/cmd/edit_menu_cmds/caf_new_layer_name_tests.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds/caf_new_layer_name_tests.rs @@ -5,7 +5,7 @@ use super::*; /// A 64 x 48 document with a striped Background and a selection over a red blob. fn caf_session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": 8, "background": "white"})).unwrap(); s.edit("stripes", |doc, active| { let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap(); diff --git a/crates/engine/src/cmd/edit_menu_cmds/content_aware.rs b/crates/engine-core/src/cmd/edit_menu_cmds/content_aware.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds/content_aware.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/content_aware.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/content_aware_scale.rs b/crates/engine-core/src/cmd/edit_menu_cmds/content_aware_scale.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds/content_aware_scale.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/content_aware_scale.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/fade.rs b/crates/engine-core/src/cmd/edit_menu_cmds/fade.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds/fade.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/fade.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/fade_dissolve_tests.rs b/crates/engine-core/src/cmd/edit_menu_cmds/fade_dissolve_tests.rs similarity index 98% rename from crates/engine/src/cmd/edit_menu_cmds/fade_dissolve_tests.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/fade_dissolve_tests.rs index 012b7cbc8f..1b531b1a36 100644 --- a/crates/engine/src/cmd/edit_menu_cmds/fade_dissolve_tests.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds/fade_dissolve_tests.rs @@ -13,7 +13,7 @@ fn bounds() -> Rect { /// The issue's test document: white Background plus an opaque layer `Paint` of four blocks and a /// yellow square. fn blocks_session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap(); s.edit("paint", |doc, active| { @@ -94,7 +94,7 @@ fn dissolve_at_100_is_normal_at_100_and_at_0_leaves_the_base() { /// included, or keeps the one before the blur, so the soft edge never becomes half as opaque. #[test] fn dissolve_picks_alpha_with_the_colour() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": 8, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "T"})).unwrap(); s.edit("paint", |doc, active| { diff --git a/crates/engine/src/cmd/edit_menu_cmds/fade_visibility_tests.rs b/crates/engine-core/src/cmd/edit_menu_cmds/fade_visibility_tests.rs similarity index 99% rename from crates/engine/src/cmd/edit_menu_cmds/fade_visibility_tests.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/fade_visibility_tests.rs index a534a927e0..e836db25cd 100644 --- a/crates/engine/src/cmd/edit_menu_cmds/fade_visibility_tests.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds/fade_visibility_tests.rs @@ -10,7 +10,7 @@ type Step = (&'static str, fn(LayerId, LayerId) -> Value); /// A white Background and a layer `Paint` with a black square, made active and blurred: /// (session, Background, Paint, Paint's edge pixel before the blur). fn blurred() -> (Session, LayerId, LayerId, Vec) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": 8, "background": "white"})).unwrap(); let bg = s.active().unwrap().active_layer.unwrap(); let paint = LayerId(s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap()["layer"].as_u64().unwrap()); diff --git a/crates/engine/src/cmd/edit_menu_cmds/find_replace.rs b/crates/engine-core/src/cmd/edit_menu_cmds/find_replace.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds/find_replace.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/find_replace.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/find_replace_change_tests.rs b/crates/engine-core/src/cmd/edit_menu_cmds/find_replace_change_tests.rs similarity index 99% rename from crates/engine/src/cmd/edit_menu_cmds/find_replace_change_tests.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/find_replace_change_tests.rs index f7e55a14b7..635503958f 100644 --- a/crates/engine/src/cmd/edit_menu_cmds/find_replace_change_tests.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds/find_replace_change_tests.rs @@ -9,7 +9,7 @@ fn text_of(s: &Session, id: LayerId) -> String { } fn new_doc_with_type(text: &str) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "depth": 8})).unwrap(); let id = LayerId(s.execute("type.create", json!({"text": text, "x": 2, "y": 12})).unwrap()["layer"].as_u64().unwrap()); (s, id) diff --git a/crates/engine/src/cmd/edit_menu_cmds/find_replace_order_tests.rs b/crates/engine-core/src/cmd/edit_menu_cmds/find_replace_order_tests.rs similarity index 99% rename from crates/engine/src/cmd/edit_menu_cmds/find_replace_order_tests.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/find_replace_order_tests.rs index 8bc8348e28..5f6a278d2a 100644 --- a/crates/engine/src/cmd/edit_menu_cmds/find_replace_order_tests.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds/find_replace_order_tests.rs @@ -1,7 +1,7 @@ use super::*; fn make_order_doc() -> (Session, [LayerId; 6], LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 500, "depth": 8, "background": "white"})).unwrap(); let id_of = |v: Value| LayerId(v["layer"].as_u64().unwrap()); diff --git a/crates/engine/src/cmd/edit_menu_cmds/presets.rs b/crates/engine-core/src/cmd/edit_menu_cmds/presets.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds/presets.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/presets.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/purge.rs b/crates/engine-core/src/cmd/edit_menu_cmds/purge.rs similarity index 100% rename from crates/engine/src/cmd/edit_menu_cmds/purge.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/purge.rs diff --git a/crates/engine/src/cmd/edit_menu_cmds/tests.rs b/crates/engine-core/src/cmd/edit_menu_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/edit_menu_cmds/tests.rs rename to crates/engine-core/src/cmd/edit_menu_cmds/tests.rs index 4b49b954eb..c2c83df2ee 100644 --- a/crates/engine/src/cmd/edit_menu_cmds/tests.rs +++ b/crates/engine-core/src/cmd/edit_menu_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_doc::vector::Subpath; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth, "background": "white"})).unwrap(); s } @@ -250,7 +250,7 @@ fn purge_commands() { fn purge_all_releases_prepared_brush_tips_even_without_a_document() { let _purge_test_guard = PURGE_TEST_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner); use photocraft_paint::{BrushContext, BrushSettings, Dab, GrayTile, TipShape}; - let mut s = Session::new(); + let mut s = crate::session(); let brush = BrushSettings { tip: TipShape::Sampled(GrayTile::from_fn(31, 17, |x, y| ((x + y) % 5) as f32 / 4.0)).into(), ..Default::default() }; let ctx = BrushContext::new(&brush); let dab = Dab::round(photocraft_geom::Point::new(12.5, 14.5), 10.0, 1.0); @@ -436,7 +436,7 @@ fn content_aware_fill_on_an_empty_layer_samples_the_composite() { #[test] fn content_aware_fill_on_an_empty_cmyk_layer_uses_the_layer_format() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 36, "mode": "cmyk", "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 16, "y": 12, "width": 12, "height": 10})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); @@ -454,7 +454,7 @@ fn content_aware_fill_on_an_empty_cmyk_layer_uses_the_layer_format() { fn content_aware_fill_samples_photoshops_window() { // A 50 px selection samples the 200 px square centred on it (Photoshop 25.4's overlay); // at the canvas edge the square slides inwards. Edit › Fill uses the same window. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400, "background": "white"})).unwrap(); for (x, y, want) in [(275, 175, [200, 100, 200, 200]), (10, 10, [0, 0, 200, 200])] { s.execute("select.rect", json!({"x": x, "y": y, "width": 50, "height": 50})).unwrap(); @@ -470,7 +470,7 @@ fn content_aware_fill_samples_photoshops_window() { fn content_aware_fill_takes_the_workspace_edits() { // The plan the workspace previews: lasso edits change the fill area (and the window follows), // sampling-brush strokes change what may be copied, also outside the window. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 275, "y": 175, "width": 50, "height": 50})).unwrap(); let st = s.active().unwrap(); @@ -714,7 +714,7 @@ fn define_custom_shape_and_preset_manager() { s.execute("brush.presets.save", json!({"name": "Mine"})).unwrap(); let out = s.execute("edit.presets.exportImportPresets", json!({"action": "export"})).unwrap(); assert_eq!(out["brushes"], 1, "built-ins are not exported by default"); - let mut t = Session::new(); + let mut t = crate::session(); let r = t.execute("edit.presets.exportImportPresets", json!({"action": "import", "data": out["data"].to_string()})).unwrap(); assert_eq!((r["brushes"].as_u64(), r["customShapes"].as_u64()), (Some(1), Some(1))); assert!(t.tools.presets.iter().any(|b| b.name == "Mine")); @@ -724,7 +724,7 @@ fn define_custom_shape_and_preset_manager() { #[test] fn preset_manager_brush_rename_follows_current_preset() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("brush.presets.setCurrent", json!({"name": "Chalk"})).unwrap(); s.execute("edit.presets.presetManager", json!({"action": "rename", "kind": "brushes", "name": "Chalk", "newName": "Chalky"})).unwrap(); assert_eq!(s.tools.current_preset.as_deref(), Some("Chalky")); @@ -733,7 +733,7 @@ fn preset_manager_brush_rename_follows_current_preset() { #[test] fn preset_manager_brush_rename_refuses_duplicate_name() { - let mut s = Session::new(); + let mut s = crate::session(); let before: Vec = s.tools.presets.iter().map(|b| b.name.clone()).collect(); let r = s.execute("edit.presets.presetManager", json!({"action": "rename", "kind": "brushes", "name": "Soft Round", "newName": "hard round"})); assert!(r.is_err(), "a case-insensitive duplicate name must be refused"); @@ -744,7 +744,7 @@ fn preset_manager_brush_rename_refuses_duplicate_name() { #[test] fn preset_manager_brush_delete_clears_current_preset() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("brush.presets.setCurrent", json!({"name": "Chalk"})).unwrap(); s.execute("edit.presets.presetManager", json!({"action": "delete", "kind": "brushes", "name": "Chalk"})).unwrap(); assert!(!s.tools.presets.iter().any(|b| b.name == "Chalk")); @@ -891,12 +891,12 @@ fn fade_allocation_failure_keeps_document_and_history() { #[test] fn tool_presets_round_trip_through_export_import() { - let mut source = Session::new(); + let mut source = crate::session(); source.execute("tool.presets.new", json!({"name":"2 : 3", "tool":"crop", "options":{"toolOptions":{"crop_ratio":"2:3"}}})).unwrap(); let exported = source.execute("edit.presets.exportImportPresets", json!({"action":"export"})).unwrap(); assert_eq!(exported["tools"], 1); assert_eq!(exported["data"]["toolPresets"][0]["name"], "2 : 3"); - let mut target = Session::new(); + let mut target = crate::session(); target.execute("tool.presets.new", json!({"name":"2 : 3", "tool":"crop", "options":{"toolOptions":{"crop_ratio":"1:1"}}})).unwrap(); for _ in 0..2 { let result = target.execute("edit.presets.exportImportPresets", json!({"action":"import", "data":exported["data"]})).unwrap(); @@ -913,7 +913,7 @@ fn tool_presets_round_trip_through_export_import() { #[test] fn tool_preset_import_is_validated_before_mutation_and_accepts_old_files() { - let mut s = Session::new(); + let mut s = crate::session(); let before = s.presets.tool_presets.clone(); for preset in [ json!({"name":"", "tool":"crop", "options":{}}), diff --git a/crates/engine/src/cmd/enabled.rs b/crates/engine-core/src/cmd/enabled.rs similarity index 100% rename from crates/engine/src/cmd/enabled.rs rename to crates/engine-core/src/cmd/enabled.rs diff --git a/crates/engine/src/cmd/eraser_cmds.rs b/crates/engine-core/src/cmd/eraser_cmds.rs similarity index 100% rename from crates/engine/src/cmd/eraser_cmds.rs rename to crates/engine-core/src/cmd/eraser_cmds.rs diff --git a/crates/engine/src/cmd/eraser_cmds/magic_eraser_mode_refusal_tests.rs b/crates/engine-core/src/cmd/eraser_cmds/magic_eraser_mode_refusal_tests.rs similarity index 98% rename from crates/engine/src/cmd/eraser_cmds/magic_eraser_mode_refusal_tests.rs rename to crates/engine-core/src/cmd/eraser_cmds/magic_eraser_mode_refusal_tests.rs index b56d839310..338463626a 100644 --- a/crates/engine/src/cmd/eraser_cmds/magic_eraser_mode_refusal_tests.rs +++ b/crates/engine-core/src/cmd/eraser_cmds/magic_eraser_mode_refusal_tests.rs @@ -18,7 +18,7 @@ const BITMAP: &str = "Could not use the magic eraser because it does not work wi /// click on it would wipe the canvas out - with a live selection. Both must survive a refusal. fn session(mode: photocraft_color::ColorMode, depth: SampleType) -> Session { let d = Document::with_background("palette", Size::new(64, 48), mode, depth, Color::WHITE); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(d, None); s.execute("select.rect", json!({"x": 4, "y": 4, "width": 20, "height": 20, "antiAlias": false})).unwrap(); s @@ -76,7 +76,7 @@ fn magic_eraser_refuses_indexed_and_bitmap_with_the_reference_alerts() { #[test] fn magic_eraser_still_erases_the_measured_modes_and_depths() { for (mode, depth) in [("rgb", 8), ("gray", 8), ("cmyk", 8), ("lab", 8), ("rgb", 16), ("rgb", 32)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "mode": mode, "depth": depth})).unwrap(); let h = s.active().unwrap().history.past_len(); let id = s.active().unwrap().active_layer.unwrap(); diff --git a/crates/engine/src/cmd/eraser_cmds/magic_eraser_tolerance_tests.rs b/crates/engine-core/src/cmd/eraser_cmds/magic_eraser_tolerance_tests.rs similarity index 99% rename from crates/engine/src/cmd/eraser_cmds/magic_eraser_tolerance_tests.rs rename to crates/engine-core/src/cmd/eraser_cmds/magic_eraser_tolerance_tests.rs index 4369282590..f9e3017b4a 100644 --- a/crates/engine/src/cmd/eraser_cmds/magic_eraser_tolerance_tests.rs +++ b/crates/engine-core/src/cmd/eraser_cmds/magic_eraser_tolerance_tests.rs @@ -17,7 +17,7 @@ fn hex([r, g, b]: [u8; 3]) -> String { } fn document(w: i32, h: i32, depth: u32, background: [u8; 3]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "mode": "rgb", "depth": depth, "background": hex(background)})).unwrap(); s } diff --git a/crates/engine/src/cmd/eraser_cmds/tests.rs b/crates/engine-core/src/cmd/eraser_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/eraser_cmds/tests.rs rename to crates/engine-core/src/cmd/eraser_cmds/tests.rs index 50d11699d9..e798605df3 100644 --- a/crates/engine/src/cmd/eraser_cmds/tests.rs +++ b/crates/engine-core/src/cmd/eraser_cmds/tests.rs @@ -6,7 +6,7 @@ const DEPTHS: [u32; 3] = [8, 16, 32]; /// White document with a black 20×20 square at (10, 10) on its Background layer. fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "mode": mode, "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20, "antiAlias": false})).unwrap(); s.execute("edit.fill", json!({"color": "#000000"})).unwrap(); @@ -157,7 +157,7 @@ fn magic_eraser_fails_gracefully() { }) .unwrap(); assert!(s.execute("paint.magicEraser", json!({"x": 2, "y": 2})).is_err()); - let mut e = Session::new(); + let mut e = crate::session(); assert!(e.execute("paint.magicEraser", json!({"x": 2, "y": 2})).is_err(), "no document"); } @@ -222,7 +222,7 @@ fn background_eraser_compares_against_picked_cmyk_inks() { const STAND_IN: &str = "#00aeef"; const CYAN: [f32; 4] = [1.0, 0.0, 0.0, 0.0]; let cyan_square = |key: &str| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "mode": "cmyk", "depth": 8})).unwrap(); s.execute("tools.setColors", json!({key: STAND_IN, format!("{key}Cmyk"): CYAN})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20, "antiAlias": false})).unwrap(); @@ -247,7 +247,7 @@ fn background_eraser_compares_against_picked_cmyk_inks() { // Other modes ignore the picked inks: the stand-in is compared as it always was. for mode in ["rgb", "gray", "lab"] { let run = |cmyk: bool| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "mode": mode, "depth": 8})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20, "antiAlias": false})).unwrap(); s.execute("edit.fill", json!({"color": STAND_IN})).unwrap(); @@ -294,7 +294,7 @@ fn background_eraser_fails_gracefully() { #[test] #[ignore] fn bench_magic_eraser_24mp() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000})).unwrap(); s.execute("select.rect", json!({"x": 1500, "y": 1000, "width": 3000, "height": 2000, "ellipse": true})).unwrap(); s.execute("edit.fill", json!({"color": "#204080"})).unwrap(); @@ -377,5 +377,5 @@ fn live_background_eraser_refuses_what_the_command_refuses() { { assert!(live_background_eraser(&s, &p).is_err(), "{p}"); } - assert!(live_background_eraser(&Session::new(), &json!({"points": [[0, 0]]})).is_err()); + assert!(live_background_eraser(&crate::session(), &json!({"points": [[0, 0]]})).is_err()); } diff --git a/crates/engine/src/cmd/export_preset_cmds.rs b/crates/engine-core/src/cmd/export_preset_cmds.rs similarity index 98% rename from crates/engine/src/cmd/export_preset_cmds.rs rename to crates/engine-core/src/cmd/export_preset_cmds.rs index d1115e5645..29bbd15809 100644 --- a/crates/engine/src/cmd/export_preset_cmds.rs +++ b/crates/engine-core/src/cmd/export_preset_cmds.rs @@ -299,14 +299,14 @@ mod tests { #[test] fn presets_round_trip_through_the_preferences_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.export.presets.save", json!({"name": " Web JPEG ", "settings": settings("pixels")})).unwrap(); let again = s.execute("file.export.presets.save", json!({"name": "web jpeg", "settings": settings("scale")})).unwrap(); assert_eq!(again["preset"]["settings"]["sizing"], "scale"); assert_eq!(s.presets.export_presets.len(), 1, "saving the same name replaces it"); let raw = s.prefs_to_json(); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&raw).unwrap(); let listed = restored.execute("file.export.presets.list", json!({})).unwrap(); let presets = listed["presets"].as_array().unwrap(); @@ -323,14 +323,14 @@ mod tests { restored.execute("file.export.presets.delete", json!({"name": "web jpeg"})).unwrap(); assert!(restored.execute("file.export.presets.list", json!({})).unwrap()["presets"].as_array().unwrap().is_empty()); let raw = restored.prefs_to_json(); - let mut after = Session::new(); + let mut after = crate::session(); after.load_prefs_json(&raw).unwrap(); assert!(after.presets.export_presets.is_empty()); } #[test] fn renaming_keeps_the_position_and_refuses_another_presets_name() { - let mut s = Session::new(); + let mut s = crate::session(); for name in ["one", "two", "three"] { s.execute("file.export.presets.save", json!({"name": name, "settings": settings("scale")})).unwrap(); } @@ -346,7 +346,7 @@ mod tests { #[test] fn bad_presets_are_rejected_and_a_damaged_entry_is_dropped() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("file.export.presets.save", json!({})).is_err()); assert!(s.execute("file.export.presets.save", json!({"name": " ", "settings": settings("scale")})).is_err()); assert!(s.execute("file.export.presets.save", json!({"name": "x", "settings": {"format": "bmp"}})).is_err()); diff --git a/crates/engine/src/cmd/exr_cmds.rs b/crates/engine-core/src/cmd/exr_cmds.rs similarity index 99% rename from crates/engine/src/cmd/exr_cmds.rs rename to crates/engine-core/src/cmd/exr_cmds.rs index 4dc8dc894f..2659f2d4e3 100644 --- a/crates/engine/src/cmd/exr_cmds.rs +++ b/crates/engine-core/src/cmd/exr_cmds.rs @@ -93,7 +93,7 @@ mod tests { use photocraft_doc::ColorMode; fn session() -> Session { - Session::new() + crate::session() } // The fixture writer mirrors the codecs tests: a small multi-part EXR via the `exr` diff --git a/crates/engine/src/cmd/extra_cmds.rs b/crates/engine-core/src/cmd/extra_cmds.rs similarity index 100% rename from crates/engine/src/cmd/extra_cmds.rs rename to crates/engine-core/src/cmd/extra_cmds.rs diff --git a/crates/engine/src/cmd/extra_cmds/tests.rs b/crates/engine-core/src/cmd/extra_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/extra_cmds/tests.rs rename to crates/engine-core/src/cmd/extra_cmds/tests.rs index d85e7c9585..5ead16b502 100644 --- a/crates/engine/src/cmd/extra_cmds/tests.rs +++ b/crates/engine-core/src/cmd/extra_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s @@ -148,7 +148,7 @@ fn stroke_widths_are_whole_opaque_pixels_like_photoshop() { for depth in [8, 16, 32] { for loc in ["center", "inside", "outside"] { for (param, w) in [(json!(1), 1), (json!(2), 2), (json!(3), 3), (json!(4), 4), (json!(5), 5), (json!(0.5), 1), (json!(2.5), 3)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 50, "height": 50, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); @@ -256,7 +256,7 @@ fn grid_selection(rows: &[&str], outside: bool) -> Vec { /// Strokes `mask` as the selection of a `w` × `h` layer and returns its alpha per pixel. fn stroke_alpha(mask: &[f32], w: usize, h: usize, depth: u32, params: Value) -> Vec { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("select", |doc, _| { @@ -308,7 +308,7 @@ fn a_hard_circle_strokes_like_photoshop() { // The selection: the `.` cells enclosed by the ring on each row. let mask = grid_selection(&rows, true); for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("select", |doc, _| { @@ -802,7 +802,7 @@ fn equalize_refuses_a_selected_area_only_that_is_not_a_boolean() { fn clouds_in_a_selection_are_the_canvas_clouds() { // Big enough that the canvas (cloud size 100 px) and the selection (16 px) size differently. let big = |depth: u32| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s @@ -959,7 +959,7 @@ fn show_only_without_a_snapshot_shows_every_layer() { assert_eq!(s.execute("layer.showOnly", json!({})).unwrap()["shownAlone"], false); assert!(doc(&s).layers.iter().all(|l| l.visible)); assert!(s.execute("layer.showOnly", json!({"layer": u64::MAX})).is_err()); - assert!(Session::new().execute("layer.showOnly", json!({})).is_err()); + assert!(crate::session().execute("layer.showOnly", json!({})).is_err()); } #[test] @@ -1138,7 +1138,7 @@ fn reveal_all_skips_erased_pixels() { // All grew the canvas to them although nothing there is visible. // No Background: its off-canvas pixels are opaque and would be revealed anyway. for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth, "background": "transparent"})).unwrap(); paint_square(&mut s, Rect::new(0, 0, 40, 30), [1.0, 0.0, 0.0, 1.0]); let erase = json!({"points": [[32, -10], [32, 40]], "size": 28, "erase": true, "brush": {"hardness": 1.0}}); diff --git a/crates/engine/src/cmd/face_cmds.rs b/crates/engine-core/src/cmd/face_cmds.rs similarity index 98% rename from crates/engine/src/cmd/face_cmds.rs rename to crates/engine-core/src/cmd/face_cmds.rs index 1d7ef45dd8..2ebdbbd3da 100644 --- a/crates/engine/src/cmd/face_cmds.rs +++ b/crates/engine-core/src/cmd/face_cmds.rs @@ -96,11 +96,9 @@ pub fn specs() -> Vec { mod tests { use serde_json::json; - use crate::Session; - #[test] fn detect_faces_reports_no_faces_on_a_plain_image_and_validates_params() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("image.detectFaces", json!({})).is_err(), "no document"); assert!(!s.is_enabled("image.detectFaces")); s.execute("file.new", json!({"width": 64, "height": 48, "background": "white"})).unwrap(); diff --git a/crates/engine/src/cmd/file_cmds.rs b/crates/engine-core/src/cmd/file_cmds.rs similarity index 99% rename from crates/engine/src/cmd/file_cmds.rs rename to crates/engine-core/src/cmd/file_cmds.rs index 6ce0a4a6d8..bbd6df8d0b 100644 --- a/crates/engine/src/cmd/file_cmds.rs +++ b/crates/engine-core/src/cmd/file_cmds.rs @@ -516,13 +516,13 @@ mod aces_exr_tests { let aces = craft_cms::Builtin::AcesCg.profile().to_bytes(); // Off (the default): io's linear-sRGB tagging stays. - let mut s = Session::new(); + let mut s = crate::session(); open_bytes_as(&mut s, "shot.exr", &bytes, None, None).unwrap(); let d = &s.active().unwrap().doc; assert_eq!(d.icc_profile.as_deref().map(|v| v.as_slice()), Some(linear.as_slice())); // On: the same file opens as ACEScg. - let mut s = Session::new(); + let mut s = crate::session(); s.prefs.edit(|p| p.file_handling.exr_aces_cg = true); open_bytes_as(&mut s, "shot.exr", &bytes, None, None).unwrap(); let d = &s.active().unwrap().doc; @@ -540,7 +540,7 @@ mod aces_exr_tests { let linear = craft_cms::Builtin::LinearSrgb.profile().to_bytes(); let aces = craft_cms::Builtin::AcesCg.profile().to_bytes(); for (on, want) in [(false, &linear), (true, &aces)] { - let mut s = Session::new(); + let mut s = crate::session(); s.prefs.edit(|p| p.file_handling.exr_aces_cg = on); let v = match s.start_open("shot.exr", OpenSource::Bytes(std::sync::Arc::clone(&bytes))).unwrap() { Started::Job(id) => s.wait_job(id).unwrap(), diff --git a/crates/engine/src/cmd/file_cmds/batch_log_format_tests.rs b/crates/engine-core/src/cmd/file_cmds/batch_log_format_tests.rs similarity index 94% rename from crates/engine/src/cmd/file_cmds/batch_log_format_tests.rs rename to crates/engine-core/src/cmd/file_cmds/batch_log_format_tests.rs index 02fb5cd32a..b46bb6eb62 100644 --- a/crates/engine/src/cmd/file_cmds/batch_log_format_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/batch_log_format_tests.rs @@ -54,7 +54,7 @@ fn a_folder_given_with_slashes_is_written_with_backslashes_on_windows() { let missing = format!("{dir}/in/missing.png"); let log = format!("{dir}/errors.txt"); let result = - Session::new().execute("file.automate.batch", json!({"steps": [], "input": [missing], "output": format!("{dir}/out"), "errorLog": log})).unwrap(); + crate::session().execute("file.automate.batch", json!({"steps": [], "input": [missing], "output": format!("{dir}/out"), "errorLog": log})).unwrap(); assert_eq!(result["errors"].as_array().map(Vec::len), Some(1), "{result}"); let text = decode_be(&std::fs::read(&log).unwrap()); let expected = format!("File: \"{}\"\r\n", missing.replace('/', "\\")); diff --git a/crates/engine/src/cmd/file_cmds/batch_naming.rs b/crates/engine-core/src/cmd/file_cmds/batch_naming.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/batch_naming.rs rename to crates/engine-core/src/cmd/file_cmds/batch_naming.rs diff --git a/crates/engine/src/cmd/file_cmds/batch_run.rs b/crates/engine-core/src/cmd/file_cmds/batch_run.rs similarity index 99% rename from crates/engine/src/cmd/file_cmds/batch_run.rs rename to crates/engine-core/src/cmd/file_cmds/batch_run.rs index 7b92b586fa..1110baf9e8 100644 --- a/crates/engine/src/cmd/file_cmds/batch_run.rs +++ b/crates/engine-core/src/cmd/file_cmds/batch_run.rs @@ -30,7 +30,7 @@ fn batch_rejects_a_non_path_input_before_writing() { std::fs::write(&input, bytes).unwrap(); for (cmd, format) in [("file.automate.batch", "png"), ("file.scripts.imageProcessor", "jpg")] { let output = dir.path().join(format); - let mut s = Session::new(); + let mut s = crate::session(); let err = s.execute(cmd, json!({"steps": [], "input": [&input, 17], "output": &output, "format": format})).unwrap_err(); assert!(matches!(&err, EngineError::BadParams { cmd: name, msg } if name == cmd && msg == "input file 2 must be a path string"), "{err}"); assert!(!output.exists()); @@ -1515,7 +1515,7 @@ mod action_history_tests { ("named-stopped", true, false, true, false, true), ] { OBSERVED.with(|seen| seen.borrow_mut().clear()); - let mut s = Session::new(); + let mut s = crate::session(); s.batch_history_observer = Some(observe); s.execute("actions.setHistory", json!({"singleState":single})).unwrap(); let mut steps = vec![ActionStep::new("layer.renameLayer", json!({"name":"Prefix"}))]; @@ -1569,7 +1569,7 @@ mod action_history_tests { .into_iter() .flat_map(|single| [false, true].into_iter().flat_map(move |parent| [false, true].into_iter().map(move |named| (single, parent, named)))) { - let mut s = Session::new(); + let mut s = crate::session(); for _ in 0..2 { s.execute("file.new", json!({"width":4,"height":4})).unwrap(); } @@ -1627,7 +1627,7 @@ mod action_history_tests { /// A Batch failure restores the library and leaves the caller's active history scope owned by the caller. fn opened_document_batch_error_restores_library_without_finishing_parent() { for parent in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":4,"height":4})).unwrap(); s.execute("actions.setHistory", json!({"singleState":true})).unwrap(); s.actions.list.push(Action::new("Original", vec![])).unwrap(); @@ -1682,7 +1682,7 @@ mod action_history_tests { let bytes = photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &Default::default()).unwrap(); let input = dir.path().join("input.png"); std::fs::write(&input, bytes).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("actions.setHistory", json!({"singleState":true})).unwrap(); let ctx = crate::jobs::JobCtx::new(); s.set_inline_job_ctx(Some(ctx.clone())); diff --git a/crates/engine/src/cmd/file_cmds/batch_serial_skip_failed_tests.rs b/crates/engine-core/src/cmd/file_cmds/batch_serial_skip_failed_tests.rs similarity index 97% rename from crates/engine/src/cmd/file_cmds/batch_serial_skip_failed_tests.rs rename to crates/engine-core/src/cmd/file_cmds/batch_serial_skip_failed_tests.rs index f428a85688..1947df1476 100644 --- a/crates/engine/src/cmd/file_cmds/batch_serial_skip_failed_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/batch_serial_skip_failed_tests.rs @@ -34,7 +34,7 @@ fn issue_folder(label: &str, with_text: bool) -> (String, String) { } fn run(input: &str, output: &str, with_text: bool, naming: Value) -> Vec { - let mut s = Session::new(); + let mut s = crate::session(); let p = json!({ "input": input, "output": output, "steps": [], "format": "same", "startingSerial": 5, "includeSubfolders": true, "includeNonImages": with_text, "flatOutput": true, "namingComponents": naming @@ -79,7 +79,7 @@ fn run_named(label: &str, files: &[&str], in_place: bool, start: u32, naming: &s } } let output = if in_place { input.clone() } else { join(&dir, "out") }; - let mut s = Session::new(); + let mut s = crate::session(); let p = json!({ "input": input, "output": output, "steps": [], "format": "same", "startingSerial": start, "includeNonImages": true, "naming": naming @@ -122,7 +122,7 @@ fn the_error_log_may_take_a_refused_inputs_name() { "input": input, "output": output, "steps": [], "format": "same", "includeNonImages": true, "naming": "{name}_{serial:3}.png", "errorLog": log }); - let result = Session::new().execute("file.automate.batch", p).unwrap(); + let result = crate::session().execute("file.automate.batch", p).unwrap(); let files: Vec = result["files"].as_array().unwrap().iter().map(|f| file_name(f.as_str().unwrap()).to_string()).collect(); assert_eq!(files, ["a_001.png", "c_002.png"]); assert_eq!(result["errors"].as_array().unwrap().len(), 2); diff --git a/crates/engine/src/cmd/file_cmds/export.rs b/crates/engine-core/src/cmd/file_cmds/export.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/export.rs rename to crates/engine-core/src/cmd/file_cmds/export.rs diff --git a/crates/engine/src/cmd/file_cmds/export_clut_cube_header_tests.rs b/crates/engine-core/src/cmd/file_cmds/export_clut_cube_header_tests.rs similarity index 99% rename from crates/engine/src/cmd/file_cmds/export_clut_cube_header_tests.rs rename to crates/engine-core/src/cmd/file_cmds/export_clut_cube_header_tests.rs index 6b1315f145..a4c55fcae5 100644 --- a/crates/engine/src/cmd/file_cmds/export_clut_cube_header_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/export_clut_cube_header_tests.rs @@ -3,7 +3,7 @@ use super::*; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); s diff --git a/crates/engine/src/cmd/file_cmds/export_clut_stack_tests.rs b/crates/engine-core/src/cmd/file_cmds/export_clut_stack_tests.rs similarity index 98% rename from crates/engine/src/cmd/file_cmds/export_clut_stack_tests.rs rename to crates/engine-core/src/cmd/file_cmds/export_clut_stack_tests.rs index d5633c5f92..2f89878c15 100644 --- a/crates/engine/src/cmd/file_cmds/export_clut_stack_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/export_clut_stack_tests.rs @@ -12,7 +12,7 @@ const GREEN: [f32; 4] = [0.0, 160.0 / 255.0, 0.0, 1.0]; /// The issue's document: 200 x 150 RGB/8, Background red on the left half and white on the /// right, an Invert adjustment layer on top. Returns the session and the Invert's id. fn session() -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 150})).unwrap(); { let st = s.active_mut().unwrap(); @@ -163,14 +163,14 @@ fn explicit_layers_and_the_selection_keep_the_adjustment_only_table() { #[test] fn small_and_large_canvases_never_panic() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1, "height": 1})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); let err = s.execute("file.export.colorLookupTables", json!({"size": 129})).unwrap_err(); assert!(err.to_string().contains("too small"), "{err}"); let e = entries(&mut s); assert!(near(at(&e, 2, 4, 5), input(2, 4, 5).map(|v| 1.0 - v)), "a 1 x 1 canvas takes one pass per entry"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 12000, "height": 9000})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); let e = entries(&mut s); @@ -221,7 +221,7 @@ fn a_huge_canvas_is_rendered_in_bounded_chunks() { /// inverse, with only chunked renders. #[test] fn a_huge_canvas_still_bakes_the_stack() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200_000, "height": 150_000})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); // The default 33 points: 35937 entries, each in a tile of its own at this size. diff --git a/crates/engine/src/cmd/file_cmds/image_processor_formats_tests.rs b/crates/engine-core/src/cmd/file_cmds/image_processor_formats_tests.rs similarity index 97% rename from crates/engine/src/cmd/file_cmds/image_processor_formats_tests.rs rename to crates/engine-core/src/cmd/file_cmds/image_processor_formats_tests.rs index 134acee8af..ca6a73be26 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_formats_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/image_processor_formats_tests.rs @@ -25,7 +25,7 @@ fn reopen(path: &Path) -> Result> { #[test] fn one_run_reopens_three_independently_sized_formats() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); document(&mut s, "Source", 16).unwrap(); s.execute("edit.assignProfile", json!({"profile": "display-p3"})).unwrap(); s.execute("select.all", json!({})).unwrap(); @@ -76,7 +76,7 @@ fn one_run_reopens_three_independently_sized_formats() { #[test] fn every_nonempty_format_combination_processes_all_open_documents() { - let mut s = Session::new(); + let mut s = crate::session(); document(&mut s, "First", 8).unwrap(); document(&mut s, "Second", 8).unwrap(); let formats = [("jpeg", "jpg"), ("psd", "psd"), ("tiff", "tif")]; @@ -100,7 +100,7 @@ fn every_nonempty_format_combination_processes_all_open_documents() { #[test] fn invalid_settings_fail_before_any_format_writes() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); document(&mut s, "Source", 8).unwrap(); for settings in [ json!({"jpeg": false, "psd": {"enabled": false}, "tiff": null}), @@ -122,7 +122,7 @@ fn invalid_settings_fail_before_any_format_writes() { #[test] fn folder_errors_identify_the_format_and_do_not_replace_sources() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); document(&mut s, "Source", 8).unwrap(); let source = dir.path().join("source.psd"); s.execute("file.saveACopy", json!({"path": source})).unwrap(); @@ -144,7 +144,7 @@ fn folder_errors_identify_the_format_and_do_not_replace_sources() { #[test] fn legacy_format_and_resize_parameters_still_work() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); document(&mut s, "Source", 8).unwrap(); let result = s .execute( diff --git a/crates/engine/src/cmd/file_cmds/image_processor_tests.rs b/crates/engine-core/src/cmd/file_cmds/image_processor_tests.rs similarity index 97% rename from crates/engine/src/cmd/file_cmds/image_processor_tests.rs rename to crates/engine-core/src/cmd/file_cmds/image_processor_tests.rs index 89381b61ee..2738151f3a 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/image_processor_tests.rs @@ -29,7 +29,7 @@ fn image_processor_current_uses_unsaved_edits_at_several_depths_without_changing let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("source.psd"); let output = dir.path().join("processed"); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, "Other", depth, "#0000ff").unwrap(); add(&mut s, "Current", depth, "#ff0000").unwrap(); s.execute("file.saveACopy", json!({"path": path})).unwrap(); @@ -71,7 +71,7 @@ fn image_processor_current_uses_unsaved_edits_at_several_depths_without_changing #[test] fn image_processor_current_accepts_an_untitled_document() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, "Untitled-1", 8, "#ff0000").unwrap(); let result = s.execute("file.scripts.imageProcessor", json!({"source": "current", "output": dir.path(), "format": "png"})).unwrap(); assert_eq!(result["files"].as_array().unwrap().len(), 1, "{result}"); @@ -85,7 +85,7 @@ fn image_processor_current_accepts_an_untitled_document() { #[test] fn image_processor_open_copies_every_document_and_reports_collisions_without_overwriting() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, "Same", 8, "#ff0000").unwrap(); add(&mut s, "Same", 8, "#0000ff").unwrap(); add(&mut s, "Other", 8, "#00ff00").unwrap(); @@ -113,7 +113,7 @@ fn image_processor_open_copies_every_document_and_reports_collisions_without_ove fn image_processor_current_cannot_replace_an_open_source_file() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("source.png"); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, "Source", 8, "#ff0000").unwrap(); s.execute("file.saveACopy", json!({"path": path})).unwrap(); let st = s.active_mut().unwrap(); @@ -132,7 +132,7 @@ fn image_processor_current_cannot_replace_an_open_source_file() { #[test] fn image_processor_open_sources_fail_gracefully_with_no_documents_or_bad_source_params() { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); for source in [json!("current"), json!("open"), json!("unknown"), json!(true), json!(7), json!([])] { assert!(s.execute("file.scripts.imageProcessor", json!({"source": source, "output": dir.path()})).is_err()); } @@ -153,7 +153,7 @@ fn image_processor_current_preserves_authorization_for_resize_commands() { if id == "image.imageSize" { Err(crate::EngineError::Other("resize denied".into())) } else { Ok(()) } } let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, "Untitled", 8, "#ffffff").unwrap(); s.authorize = Some(deny_resize); let result = s.execute("file.scripts.imageProcessor", json!({"source": "current", "output": dir.path(), "width": 20})).unwrap(); @@ -169,7 +169,7 @@ fn image_processor_current_preserves_authorization_for_resize_commands() { fn image_processor_open_sources_export_a_moved_selection_without_committing_it_in_the_original() { for source in ["current", "open"] { let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, "Moved", 8, "#ff0000").unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 4, "height": 4})).unwrap(); s.execute("select.float", json!({"dx": 10, "dy": 0})).unwrap(); @@ -200,7 +200,7 @@ fn image_processor_open_embeds_relative_links_from_each_documents_own_folder() { use photocraft_doc::{LayerContent, SmartSource}; let dir = tempfile::tempdir().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let mut sources = Vec::new(); for (name, color) in [("First", "#ff0000"), ("Second", "#0000ff")] { let folder = dir.path().join(name); @@ -263,7 +263,7 @@ fn image_processor_untitled_names_use_the_shared_filename_sanitizer() { ] { let dir = tempfile::tempdir().unwrap(); let output = dir.path().join("processed"); - let mut s = Session::new(); + let mut s = crate::session(); add(&mut s, name, 8, "#ff0000").unwrap(); let original = s.active().unwrap().doc.clone(); let result = s.execute("file.scripts.imageProcessor", json!({"source": source, "output": output, "format": format})).unwrap(); diff --git a/crates/engine/src/cmd/file_cmds/image_processor_unique_names_tests.rs b/crates/engine-core/src/cmd/file_cmds/image_processor_unique_names_tests.rs similarity index 91% rename from crates/engine/src/cmd/file_cmds/image_processor_unique_names_tests.rs rename to crates/engine-core/src/cmd/file_cmds/image_processor_unique_names_tests.rs index 9d9576a476..1a773fa706 100644 --- a/crates/engine/src/cmd/file_cmds/image_processor_unique_names_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/image_processor_unique_names_tests.rs @@ -7,8 +7,6 @@ use std::{ use serde_json::{Value, json}; -use crate::Session; - const COMMAND: &str = "file.scripts.imageProcessor"; const PIXELS: &[u8] = b"P6\n2 1\n255\n\xff\0\0\0\xff\0"; @@ -26,11 +24,11 @@ fn selects_the_first_free_suffix_and_reports_every_written_format() { for name in ["a.b.jpg", "a.b_1.jpg", "a.b_3.jpg", "a.b.tif"] { fs::write(output.join(name), name.as_bytes()).unwrap(); } - let result = Session::new().execute(COMMAND, json!({"input":[source],"output":output,"jpeg":{},"psd":{},"tiff":{}})).unwrap(); + let result = crate::session().execute(COMMAND, json!({"input":[source],"output":output,"jpeg":{},"psd":{},"tiff":{}})).unwrap(); let expected = ["a.b_2.jpg", "a.b.psd", "a.b_1.tif"]; assert_eq!(files(&result).unwrap(), expected.map(|name| output.join(name))); assert_eq!(result["errors"], json!([])); - let next = Session::new().execute(COMMAND, json!({"input":[source],"output":output,"format":"jpg"})).unwrap(); + let next = crate::session().execute(COMMAND, json!({"input":[source],"output":output,"format":"jpg"})).unwrap(); assert_eq!(files(&next).unwrap(), [output.join("a.b_4.jpg")]); assert_eq!(next["errors"], json!([])); for name in ["a.b.jpg", "a.b_1.jpg", "a.b_3.jpg", "a.b.tif"] { @@ -54,7 +52,7 @@ fn same_stem_inputs_get_separate_results_without_changing_shared_processing() { fs::create_dir_all(path.parent().unwrap()).unwrap(); fs::write(path, PIXELS).unwrap(); } - let mut session = Session::new(); + let mut session = crate::session(); let result = session.execute(COMMAND, json!({"input":[a,b],"output":output,"format":"png"})).unwrap(); assert_eq!(files(&result).unwrap(), [output.join("same.png"), output.join("same_1.png")]); assert_eq!(result["errors"], json!([])); @@ -84,7 +82,7 @@ fn concurrent_folder_runs_cannot_replace_each_others_results() { let workers: Vec<_> = (0..4) .map(|_| { scope.spawn(|| { - let mut session = Session::new(); + let mut session = crate::session(); gate.wait(); session.execute(COMMAND, params.clone()) }) @@ -117,7 +115,7 @@ fn directory_and_dangling_symlink_names_stay_occupied() { let counter = if cfg!(unix) { 2 } else { 1 }; #[cfg(unix)] std::os::unix::fs::symlink(output.join("missing.png"), output.join("example_1.png")).unwrap(); - let result = Session::new().execute(COMMAND, json!({"input":[source],"output":output,"format":"png"})).unwrap(); + let result = crate::session().execute(COMMAND, json!({"input":[source],"output":output,"format":"png"})).unwrap(); assert_eq!(files(&result).unwrap(), [output.join(format!("example_{counter}.png"))]); assert_eq!(result["errors"], json!([])); assert!(output.join("example.png").is_dir()); @@ -136,7 +134,7 @@ fn failed_input_does_not_claim_an_output_name() { fs::write(&corrupt, b"not an image").unwrap(); fs::write(&valid, PIXELS).unwrap(); let output = root.path().join("out"); - let result = Session::new().execute(COMMAND, json!({"input":[corrupt,valid],"output":output,"format":"png"})).unwrap(); + let result = crate::session().execute(COMMAND, json!({"input":[corrupt,valid],"output":output,"format":"png"})).unwrap(); assert_eq!(files(&result).unwrap(), [output.join("same.png")]); let errors = result["errors"].as_array().unwrap(); assert_eq!(errors.len(), 1); @@ -147,7 +145,7 @@ fn failed_input_does_not_claim_an_output_name() { #[test] fn current_and_open_document_sources_keep_their_output_naming() { let root = tempfile::tempdir().unwrap(); - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"name":"Current", "width":2, "height":2})).unwrap(); for source in ["current", "open"] { let out = root.path().join("Current.png"); diff --git a/crates/engine/src/cmd/file_cmds/info.rs b/crates/engine-core/src/cmd/file_cmds/info.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/info.rs rename to crates/engine-core/src/cmd/file_cmds/info.rs diff --git a/crates/engine/src/cmd/file_cmds/layers_to_files_index_tests.rs b/crates/engine-core/src/cmd/file_cmds/layers_to_files_index_tests.rs similarity index 97% rename from crates/engine/src/cmd/file_cmds/layers_to_files_index_tests.rs rename to crates/engine-core/src/cmd/file_cmds/layers_to_files_index_tests.rs index ab975852c1..58df619997 100644 --- a/crates/engine/src/cmd/file_cmds/layers_to_files_index_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/layers_to_files_index_tests.rs @@ -4,7 +4,7 @@ use super::*; /// Layers top to bottom: `Top`, `Hidden` (hidden), `Blue`, `Background`. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); for name in ["Blue", "Hidden", "Top"] { s.execute("layer.new.layer", json!({"name": name})).unwrap(); diff --git a/crates/engine/src/cmd/file_cmds/layers_to_files_png_names_tests.rs b/crates/engine-core/src/cmd/file_cmds/layers_to_files_png_names_tests.rs similarity index 98% rename from crates/engine/src/cmd/file_cmds/layers_to_files_png_names_tests.rs rename to crates/engine-core/src/cmd/file_cmds/layers_to_files_png_names_tests.rs index 1b1c105ff4..98158a6013 100644 --- a/crates/engine/src/cmd/file_cmds/layers_to_files_png_names_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/layers_to_files_png_names_tests.rs @@ -5,7 +5,7 @@ use super::*; /// Background, `Blue Half`, and a hidden layer `Hid den` on top. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Blue Half"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Hid den"})).unwrap(); diff --git a/crates/engine/src/cmd/file_cmds/layers_to_files_prefix_tests.rs b/crates/engine-core/src/cmd/file_cmds/layers_to_files_prefix_tests.rs similarity index 98% rename from crates/engine/src/cmd/file_cmds/layers_to_files_prefix_tests.rs rename to crates/engine-core/src/cmd/file_cmds/layers_to_files_prefix_tests.rs index a11e7aacf0..fc49124c55 100644 --- a/crates/engine/src/cmd/file_cmds/layers_to_files_prefix_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/layers_to_files_prefix_tests.rs @@ -3,7 +3,7 @@ use super::{Session, export_layers_report_with, export_layers_with, json}; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"name": "project.v2.psd", "width": 4, "height": 3, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({"name": "Type"})).unwrap(); s.execute("edit.fill", json!({"color": "#406080"})).unwrap(); diff --git a/crates/engine/src/cmd/file_cmds/load_stack_name_tests.rs b/crates/engine-core/src/cmd/file_cmds/load_stack_name_tests.rs similarity index 95% rename from crates/engine/src/cmd/file_cmds/load_stack_name_tests.rs rename to crates/engine-core/src/cmd/file_cmds/load_stack_name_tests.rs index 2580d58f57..88498bf365 100644 --- a/crates/engine/src/cmd/file_cmds/load_stack_name_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/load_stack_name_tests.rs @@ -1,13 +1,13 @@ //! File › Scripts › Load Files into Stack (#13996): the stack opens as a new unsaved "Untitled-N" //! document, not one named after the first file. -use crate::{EngineError, Session}; +use crate::EngineError; use photocraft_doc::{Layer, LayerContent}; use serde_json::json; /// Two textured PNGs named a_base.png and b_shift.png (texture, so Auto-Align finds features). fn two_files(dir: &std::path::Path) -> Result, Box> { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 72, "background": "#606060"}))?; s.edit("texture", |doc, active| { let surf = doc.layer_mut(active.ok_or(EngineError::NoDocument)?).and_then(Layer::surface_mut).ok_or(EngineError::NoDocument)?; @@ -31,7 +31,7 @@ fn two_files(dir: &std::path::Path) -> Result, Box String { fn a_text_file_opened_as_pcx_names_notes_txt_and_pcx() { let dir = tmp("pcx"); let path = write_notes(&dir); - let mut s = Session::new(); + let mut s = crate::session(); let msg = error_text(&mut s, &path, "pcx"); assert!(msg.contains("notes.txt"), "{msg}"); assert!(msg.contains("PCX"), "{msg}"); @@ -42,7 +42,7 @@ fn a_text_file_opened_as_pcx_names_notes_txt_and_pcx() { fn a_text_file_opened_as_raw_names_notes_txt_and_raw() { let dir = tmp("raw"); let path = write_notes(&dir); - let mut s = Session::new(); + let mut s = crate::session(); let msg = error_text(&mut s, &path, "raw"); assert!(msg.contains("notes.txt"), "{msg}"); assert!(msg.contains("RAW"), "{msg}"); @@ -54,7 +54,7 @@ fn a_text_file_opened_as_raw_names_notes_txt_and_raw() { fn an_unknown_as_value_is_a_parameter_error_naming_it() { let dir = tmp("bogus"); let path = write_notes(&dir); - let mut s = Session::new(); + let mut s = crate::session(); match s.execute("file.openAs", json!({"path": path, "as": "bogus"})) { Err(EngineError::BadParams { cmd, msg }) => { assert_eq!(cmd, "file.openAs"); @@ -71,7 +71,7 @@ fn every_camera_raw_and_affinity_extension_is_an_open_as_format() { // fall behind them: a text file asked to open as one fails to read, never as a parameter error. let dir = tmp("raw-exts"); let path = write_notes(&dir); - let mut s = Session::new(); + let mut s = crate::session(); for ext in photocraft_io::raw::EXTENSIONS.iter().chain(photocraft_io::affinity::EXTENSIONS) { let r = s.execute("file.openAs", json!({"path": path, "as": ext})); assert!(!matches!(r, Err(EngineError::BadParams { .. })), "{ext}: {r:?}"); @@ -85,7 +85,7 @@ fn a_png_opened_as_png_keeps_its_real_file_name() { let bytes = photocraft_codecs::encode(&img, photocraft_codecs::Format::Png, &Default::default()).unwrap(); let path = join(&dir, "photo one.png"); std::fs::write(&path, bytes).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAs", json!({"path": path, "as": "png"})).unwrap(); assert_eq!(s.documents().len(), 1); assert_eq!(s.active().unwrap().doc.name, "photo one.png"); diff --git a/crates/engine/src/cmd/file_cmds/open_as_smart_object.rs b/crates/engine-core/src/cmd/file_cmds/open_as_smart_object.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/open_as_smart_object.rs rename to crates/engine-core/src/cmd/file_cmds/open_as_smart_object.rs diff --git a/crates/engine/src/cmd/file_cmds/open_as_smart_object_tests.rs b/crates/engine-core/src/cmd/file_cmds/open_as_smart_object_tests.rs similarity index 95% rename from crates/engine/src/cmd/file_cmds/open_as_smart_object_tests.rs rename to crates/engine-core/src/cmd/file_cmds/open_as_smart_object_tests.rs index 436ab56d33..7069df83ed 100644 --- a/crates/engine/src/cmd/file_cmds/open_as_smart_object_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/open_as_smart_object_tests.rs @@ -24,7 +24,7 @@ fn write_png(dir: &str, name: &str, w: u32, h: u32) -> String { /// A two-layer 16-bit PSD at 300 ppi tagged with Display P3, made with the engine's own save. fn write_psd16(dir: &str, name: &str, w: u32, h: u32) -> String { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": 16})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("image.imageSize", json!({"resolution": 300, "resample": "none"})).unwrap(); @@ -64,7 +64,7 @@ fn embedded(s: &Session) -> (String, String, Arc>) { fn a_png_opens_as_an_untitled_document_with_one_embedded_smart_object() { let dir = tmp("png"); let path = write_png(&dir, "a_test.png", 64, 48); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); assert_eq!(r["name"], "a_test-1", "{r}"); assert_eq!(s.documents().len(), 1); @@ -89,7 +89,7 @@ fn a_png_opens_as_an_untitled_document_with_one_embedded_smart_object() { fn the_smart_object_shows_the_file() { let dir = tmp("pixels"); let path = write_png(&dir, "grad.png", 32, 16); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); let want = photocraft_compose::render(&imported(&path), Rect::new(0, 0, 32, 16)).px.clone(); let got = photocraft_compose::render(active(&s), Rect::new(0, 0, 32, 16)).px.clone(); @@ -100,7 +100,7 @@ fn the_smart_object_shows_the_file() { fn a_16_bit_psd_keeps_size_resolution_mode_depth_and_profile() { let dir = tmp("psd"); let path = write_psd16(&dir, "c.layered.psd", 40, 30); - let mut s = Session::new(); + let mut s = crate::session(); // The files were measured in the working spaces, where nothing asks; Preserve keeps Display P3. s.execute("edit.colorSettings", json!({"askOnMismatch": false})).unwrap(); s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); @@ -122,7 +122,7 @@ fn a_16_bit_psd_keeps_size_resolution_mode_depth_and_profile() { fn history_is_the_single_state_open_as_smart_object() { let dir = tmp("history"); let path = write_png(&dir, "a_test.png", 16, 16); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); let st = s.active().unwrap(); assert_eq!(st.history.entries(), ["Open As Smart Object"], "one state, as File > Open has"); @@ -133,7 +133,7 @@ fn history_is_the_single_state_open_as_smart_object() { fn the_opening_snapshot_shows_the_placed_smart_object() { let dir = tmp("snapshot"); let path = write_png(&dir, "a_test.png", 16, 16); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); let st = s.active().unwrap(); let first = st.snapshots().first().unwrap(); @@ -148,7 +148,7 @@ fn the_opening_snapshot_shows_the_placed_smart_object() { fn the_number_is_the_next_free_one_and_starts_again_after_they_close() { let dir = tmp("numbers"); let path = write_png(&dir, "a_test.png", 8, 8); - let mut s = Session::new(); + let mut s = crate::session(); for _ in 0..3 { s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); } @@ -164,7 +164,7 @@ fn the_number_is_the_next_free_one_and_starts_again_after_they_close() { fn a_plain_open_of_the_same_file_is_unchanged() { let dir = tmp("plain"); let path = write_png(&dir, "a_test.png", 8, 8); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); open_bytes_as(&mut s, &path, &std::fs::read(&path).unwrap(), None, Some(path.clone())).unwrap(); assert_eq!(names(&s), ["a_test-1", "a_test.png"]); @@ -176,7 +176,7 @@ fn several_files_open_one_document_each() { let dir = tmp("several"); let a = write_png(&dir, "a_test.png", 8, 8); let b = write_psd16(&dir, "d_other.psd", 12, 10); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"askOnMismatch": false})).unwrap(); s.execute("file.openAsSmartObject", json!({"path": a})).unwrap(); s.execute("file.openAsSmartObject", json!({"path": b})).unwrap(); @@ -194,7 +194,7 @@ fn a_missing_or_unreadable_file_is_an_error_not_a_crash() { std::fs::write(&junk, b"this is not an image").unwrap(); let text = join(&dir, "readme.txt"); std::fs::write(&text, b"hello").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); for path in [join(&dir, "missing.png"), junk, text] { let r = s.execute("file.openAsSmartObject", json!({"path": path})); assert!(r.is_err(), "{path}: {r:?}"); @@ -204,7 +204,7 @@ fn a_missing_or_unreadable_file_is_an_error_not_a_crash() { #[test] fn bad_params_are_errors() { - let mut s = Session::new(); + let mut s = crate::session(); for params in [json!({}), json!({"path": 7}), json!({"path": null})] { let r = s.execute("file.openAsSmartObject", params.clone()); assert!(r.is_err(), "{params}: {r:?}"); @@ -235,7 +235,7 @@ fn wait_event(s: &mut Session, id: crate::jobs::JobId) -> crate::jobs::JobEvent fn the_import_runs_as_a_job_when_started() { let dir = tmp("job"); let path = write_png(&dir, "a_test.png", 32, 24); - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s.start("file.openAsSmartObject", json!({"path": path})).unwrap()); assert!(s.documents().is_empty(), "nothing is admitted before the job is applied"); let e = wait_event(&mut s, id); @@ -251,10 +251,10 @@ fn the_colour_policy_matches_file_open() { let dir = tmp("policy"); let path = write_psd16(&dir, "c.layered.psd", 40, 30); let settings = json!({"askOnMismatch": false, "policyRgb": "convert"}); - let mut open = Session::new(); + let mut open = crate::session(); open.execute("edit.colorSettings", settings.clone()).unwrap(); open.execute("file.openAs", json!({"path": path})).unwrap(); - let mut so = Session::new(); + let mut so = crate::session(); so.execute("edit.colorSettings", settings).unwrap(); so.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); let (a, b) = (active(&open), active(&so)); @@ -267,7 +267,7 @@ fn the_colour_policy_matches_file_open() { fn ask_when_opening_holds_the_document_like_file_open() { let dir = tmp("ask"); let path = write_psd16(&dir, "c.layered.psd", 40, 30); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); assert_eq!(r["color"]["ask"], true, "{r}"); assert_eq!(r["smartObject"], true, "{r}"); @@ -283,7 +283,7 @@ fn ask_when_opening_holds_the_document_like_file_open() { fn the_reply_flags_a_smart_object_so_a_queued_document_keeps_its_history_label() { let dir = tmp("flag"); let path = write_png(&dir, "a_test.png", 16, 12); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); assert_eq!(r["smartObject"], true, "{r}"); } @@ -293,7 +293,7 @@ fn a_damaged_psd_is_held_for_confirmation_when_asked_and_opens_otherwise() { let dir = tmp("damaged"); let path = join(&dir, "d.psd"); std::fs::write(&path, crate::jobs::psd_open_fixture::make_psd(true)).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"askOnMismatch": false})).unwrap(); let r = s.execute("file.openAsSmartObject", json!({"path": path, "confirmDamage": true})).unwrap(); assert_eq!(r["damaged"], true, "{r}"); @@ -308,7 +308,7 @@ fn a_damaged_psd_is_held_for_confirmation_when_asked_and_opens_otherwise() { fn a_document_held_for_its_prompt_does_not_share_its_name_with_the_next() { let dir = tmp("held-name"); let path = write_psd16(&dir, "a_test.psd", 20, 20); - let mut s = Session::new(); + let mut s = crate::session(); let first = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); let second = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); assert_eq!(first["name"], "a_test-1"); @@ -319,7 +319,7 @@ fn a_document_held_for_its_prompt_does_not_share_its_name_with_the_next() { admit_as_smart_object(&mut s, a); admit_as_smart_object(&mut s, b); assert_eq!(names(&s), ["a_test-1", "a_test-2"]); - let mut t = Session::new(); + let mut t = crate::session(); let (c, _) = { let r = t.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); t.take_held_open(r["held"].as_u64().unwrap()).unwrap() @@ -339,7 +339,7 @@ fn a_document_held_for_its_prompt_does_not_share_its_name_with_the_next() { fn a_cancelled_hold_frees_its_number_for_the_one_admitted_after_it() { let dir = tmp("cancelled-hold"); let path = write_psd16(&dir, "photo.psd", 20, 20); - let mut s = Session::new(); + let mut s = crate::session(); let first = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); let second = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); assert_eq!((first["name"].as_str(), second["name"].as_str()), (Some("photo-1"), Some("photo-2"))); @@ -354,7 +354,7 @@ fn a_cancelled_hold_frees_its_number_for_the_one_admitted_after_it() { fn the_reply_names_the_document_as_admitted() { let dir = tmp("reply-name"); let path = write_psd16(&dir, "photo.psd", 20, 20); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"askOnMismatch": true})).unwrap(); let held = s.execute("file.openAsSmartObject", json!({"path": path})).unwrap(); assert_eq!(held["name"], "photo-1", "{held}"); diff --git a/crates/engine/src/cmd/file_cmds/paths.rs b/crates/engine-core/src/cmd/file_cmds/paths.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/paths.rs rename to crates/engine-core/src/cmd/file_cmds/paths.rs diff --git a/crates/engine/src/cmd/file_cmds/place_job_tests.rs b/crates/engine-core/src/cmd/file_cmds/place_job_tests.rs similarity index 99% rename from crates/engine/src/cmd/file_cmds/place_job_tests.rs rename to crates/engine-core/src/cmd/file_cmds/place_job_tests.rs index 8e96d9cb69..eadc0021c0 100644 --- a/crates/engine/src/cmd/file_cmds/place_job_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/place_job_tests.rs @@ -14,7 +14,7 @@ fn tmp(name: &str) -> String { } fn session(w: u32, h: u32, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); s } @@ -213,7 +213,7 @@ fn bad_input_as_a_place_job_fails_without_panicking() { assert_eq!(steps(&s), before); assert_eq!(s.active().unwrap().doc.layers.len(), 1); // Inline, a missing document is the same error as before. - let mut none = Session::new(); + let mut none = crate::session(); assert!(matches!(place_bytes(&mut none, "a.png", Vec::new(), None, &json!({})), Err(EngineError::NoDocument))); assert!(matches!(none.start_place_bytes("a.png", Vec::new(), None, json!({})), Err(EngineError::NoDocument))); } diff --git a/crates/engine/src/cmd/file_cmds/place_resolution_tests.rs b/crates/engine-core/src/cmd/file_cmds/place_resolution_tests.rs similarity index 99% rename from crates/engine/src/cmd/file_cmds/place_resolution_tests.rs rename to crates/engine-core/src/cmd/file_cmds/place_resolution_tests.rs index 9245e77c35..e132f3d575 100644 --- a/crates/engine/src/cmd/file_cmds/place_resolution_tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/place_resolution_tests.rs @@ -6,7 +6,7 @@ use super::*; /// A new `w` × `h` document at `ppi`. fn session(w: u32, h: u32, ppi: f64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "resolution": ppi, "depth": 8})).unwrap(); s } diff --git a/crates/engine/src/cmd/file_cmds/place_steps.rs b/crates/engine-core/src/cmd/file_cmds/place_steps.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/place_steps.rs rename to crates/engine-core/src/cmd/file_cmds/place_steps.rs diff --git a/crates/engine/src/cmd/file_cmds/processing.rs b/crates/engine-core/src/cmd/file_cmds/processing.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/processing.rs rename to crates/engine-core/src/cmd/file_cmds/processing.rs diff --git a/crates/engine/src/cmd/file_cmds/raw_open.rs b/crates/engine-core/src/cmd/file_cmds/raw_open.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/raw_open.rs rename to crates/engine-core/src/cmd/file_cmds/raw_open.rs diff --git a/crates/engine/src/cmd/file_cmds/save.rs b/crates/engine-core/src/cmd/file_cmds/save.rs similarity index 100% rename from crates/engine/src/cmd/file_cmds/save.rs rename to crates/engine-core/src/cmd/file_cmds/save.rs diff --git a/crates/engine/src/cmd/file_cmds/tests.rs b/crates/engine-core/src/cmd/file_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/file_cmds/tests.rs rename to crates/engine-core/src/cmd/file_cmds/tests.rs index 6d9f3b1018..cb90a52c4a 100644 --- a/crates/engine/src/cmd/file_cmds/tests.rs +++ b/crates/engine-core/src/cmd/file_cmds/tests.rs @@ -21,7 +21,7 @@ fn batch_resolves_action_by_name_and_detects_recursion() { let input = png(&dir, "in.png", 8, 8, "#ff0000"); let out = join(&dir, "out"); std::fs::create_dir_all(&out).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let mut action = crate::actions_cmds::Action::new("Scale", vec![ActionStep::new("image.imageSize", json!({"width":16,"height":16}))]); action.set = Some("Ops".into()); s.actions.list.push(action).unwrap(); @@ -45,7 +45,7 @@ fn batch_structured_names_keep_image_format_and_refuse_unsupported_save_routing( let input = png(&dir, "a.png", 3, 2, "#ff0000"); let output = join(&dir, "out"); std::fs::create_dir_all(&output).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let components = json!([{"component":"name"},{"text":".jpg"}]); let result = s .execute( @@ -103,7 +103,7 @@ fn batch_recorded_stop_for_errors_retains_earlier_outputs_and_stops_before_later let bad = join(&input, "b.txt"); std::fs::write(&bad, b"not an image").unwrap(); let last = png(&input, "c.png", 3, 2, "#0000ff"); - let mut s = Session::new(); + let mut s = crate::session(); for (mode, stop) in [("default", None), ("continue", Some(false)), ("stop", Some(true))] { let output = join(&dir, mode); let mut p = json!({"input":[first,bad,last],"output":output,"steps":[]}); @@ -198,7 +198,7 @@ fn batch_save_and_close_preserves_caller_and_failed_sources() { let caller_dir = join(&dir, "caller"); std::fs::create_dir_all(&caller_dir).unwrap(); let caller_path = png(&caller_dir, "caller.png", 7, 9, "#4488aa"); - let mut s = Session::new(); + let mut s = crate::session(); open_bytes_as(&mut s, "caller.png", &std::fs::read(&caller_path).unwrap(), None, Some(caller_path)).unwrap(); s.execute("select.all", json!({})).unwrap(); let caller_state = |s: &Session| { @@ -298,7 +298,7 @@ fn batch_save_and_close_keeps_tiff_layers() { source.execute("layer.new.layer", json!({"name":"Overlay"})).unwrap(); let names: Vec<_> = doc(&source).layers.iter().map(|layer| layer.name.clone()).collect(); save_doc(doc(&source), &path, super::save::SaveOpts { tiff_layers: true, ..Default::default() }).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let result = s.execute("file.automate.batch", json!({"input":[path],"destination":"saveAndClose","steps":[]})).unwrap(); assert!(result["errors"].as_array().unwrap().is_empty(), "{result}"); let bytes = std::fs::read(&path).unwrap(); @@ -395,7 +395,7 @@ fn batch_override_open_authorizes_effective_path_and_carries_failure_budget() { std::fs::create_dir_all(&output).unwrap(); let existing = png(&output, "b.png", 3, 2, "#4488aa"); let intact = std::fs::read(&existing).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(crate::actions_cmds::Action::new("Open", vec![ActionStep::new("file.openAs", json!({"path":"/recorded.png","as":"png"}))])).unwrap(); s.batch_open = Some(BatchOpen { path: first.clone(), sources: Vec::new(), raw_ppi: 300.0, read_only: false }); assert!(matches!(s.execute("file.openAs", json!([1])), Err(EngineError::BadParams { .. }))); @@ -433,7 +433,7 @@ fn batch_override_open_nested_binding_and_save_close_preserve_sources() { let output = join(&dir, "outer"); let inner = join(&dir, "inner"); let open = json!({"path":"/recorded.png","as":"png"}); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(crate::actions_cmds::Action::new("Open", vec![ActionStep::new("file.openAs", open.clone())])).unwrap(); let steps = json!([["actions.play",{"action":"Open"}], ["file.automate.batch",{"input":[second],"output":inner,"overrideOpen":true,"steps":[["file.openAs",open],["image.adjustments.invert",{}]]}], @@ -475,14 +475,14 @@ fn batch_override_open_nested_binding_and_save_close_preserve_sources() { fn batch_quiet_profile_open_uses_caller_policy_and_retains_diagnostics() { let dir = tmp("batch-quiet-profile"); let source = png(&dir, "a.png", 3, 2, "#4488aa"); - let mut fixture = Session::new(); + let mut fixture = crate::session(); fixture.execute("file.openAs", json!({"path":source})).unwrap(); fixture.execute("edit.assignProfile", json!({"profile":"display-p3"})).unwrap(); fixture.execute("file.saveACopy", json!({"path":source,"overwrite":true})).unwrap(); let original = std::fs::read(&source).unwrap(); let bad = join(&dir, "b.png"); std::fs::write(&bad, b"not an image").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"workingRgb":"srgb","policyRgb":"convert","askOnMismatch":true,"askOnMissing":true})).unwrap(); let prefs = serde_json::to_value(s.prefs()).unwrap(); let settings = s.color.settings.clone(); @@ -539,7 +539,7 @@ fn named_open_document_batch_keeps_cycle_context_and_live_recorder() { Ok(()) } for mutual in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":8,"height":8})).unwrap(); let nested = |name| ActionStep::new("file.automate.batch", json!({"source":"open","action":name})); s.actions.list = list_of(vec![ @@ -587,7 +587,7 @@ fn named_open_document_batch_uses_effective_recorded_parameters() { Ok(()) } for through_batch in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":200,"height":100})).unwrap(); let a = s.execute("layer.new.layer", json!({"name":"A"})).unwrap()["layer"].as_u64().unwrap(); let b = s.execute("layer.new.layer", json!({"name":"B"})).unwrap()["layer"].as_u64().unwrap(); @@ -621,7 +621,7 @@ fn named_open_document_batch_uses_effective_recorded_parameters() { fn structured_open_document_batch_guards_destinations_before_editing() { let dir = tmp("batch-open-collision-policy"); for structured in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); for color in ["#ff0000", "#0000ff"] { s.execute("file.new", json!({"width":2,"height":2,"background":color})).unwrap(); } @@ -660,14 +660,14 @@ fn background_recorded_batch_keeps_opening_and_destination_policies() { let dir = tmp("batch-recorded-background"); let source = png(&dir, "source.png", 3, 2, "#4488aa"); let other = png(&dir, "other.png", 3, 2, "#ff0000"); - let mut fixture = Session::new(); + let mut fixture = crate::session(); fixture.execute("file.openAs", json!({"path":source})).unwrap(); fixture.execute("edit.assignProfile", json!({"profile":"display-p3"})).unwrap(); fixture.execute("file.saveACopy", json!({"path":source,"overwrite":true})).unwrap(); let original = std::fs::read(&source).unwrap(); let missing = join(&dir, "missing.png"); let output = join(&dir, "out"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"workingRgb":"srgb","policyRgb":"convert","askOnMismatch":true,"askOnMissing":true})).unwrap(); let prefs = serde_json::to_value(s.prefs()).unwrap(); let settings = s.color.settings.clone(); @@ -720,7 +720,7 @@ fn batch_quiet_raw_applies_prior_settings_and_workflow_without_touching_inputs() settings.exposure = 1.0; let xmp = photocraft_io::camera_raw_xmp::save(&settings); std::fs::write(&sidecar, &xmp).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("prefs.set", json!({"path":"rawDefaults.resolution","value":240})).unwrap(); let prefs = serde_json::to_value(s.prefs()).unwrap(); let output = join(&dir, "out"); @@ -731,7 +731,7 @@ fn batch_quiet_raw_applies_prior_settings_and_workflow_without_touching_inputs() assert_eq!(actual.resolution_dpi, 240.0); let (expected, _) = photocraft_io::raw::import_raw_tuned("raw.dng", &bytes, &photocraft_io::raw::RawTuning { exposure: 1.0, ..Default::default() }).unwrap(); - let mut oracle = Session::new(); + let mut oracle = crate::session(); oracle.add_document(expected.document, None); oracle.execute("edit.convertToProfile", json!({"profile":s.prefs().raw_defaults.color_space.profile_id(),"intent":"relative"})).unwrap(); let area = Rect::new(0, 0, w as i32, h as i32); @@ -767,7 +767,7 @@ fn batch_quiet_raw_applies_the_sidecar_crop() { let crop = photocraft_io::camera_raw_xmp::Crop { top: 0.25, left: 0.125, bottom: 0.75, right: 0.625 }; let xmp = photocraft_io::camera_raw_xmp::save_with_crop(&photocraft_algo::camera_raw::CameraRaw::default(), Some(crop)); std::fs::write(join(&dir, "raw.xmp"), &xmp).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let output = join(&dir, "out"); let p = json!({"input":[path],"output":output,"format":"psd","suppressOpenOptions":true,"suppressWarnings":true,"steps":[]}); let result = s.execute("file.automate.batch", p).unwrap(); @@ -798,7 +798,7 @@ fn temporary_directories_with_the_same_label_are_isolated() { } fn session(w: u32, h: u32, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); s } @@ -809,7 +809,7 @@ fn doc(s: &Session) -> &Document { /// Writes a solid-colour PNG of `w × h` and returns its path. fn png(dir: &str, name: &str, w: u32, h: u32, color: &str) -> String { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": color})).unwrap(); let path = join(dir, name); save_doc(doc(&s), &path, None).unwrap(); @@ -837,7 +837,7 @@ fn batch_stop_on_error_reports_skipped_inputs_and_writes_the_error_log() { let missing = join(&dir, "missing.png"); let output = join(&dir, "out"); let log = join(&dir, "errors.txt"); - let result = Session::new() + let result = crate::session() .execute("file.automate.batch", json!({"steps": [], "input": [missing, good], "output": output, "stopOnError": true, "errorLog": log})) .unwrap(); assert_eq!(result["files"], json!([]), "{result}"); @@ -858,7 +858,7 @@ fn batch_writes_a_utf16_error_log_even_when_every_file_succeeds() { let input = png(&dir, "good.png", 8, 6, "#00ff00"); let output = join(&dir, "out"); let log = join(&dir, "errors.txt"); - let result = Session::new().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap(); + let result = crate::session().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap(); assert_eq!(result["errors"], json!([]), "{result}"); assert_eq!(result["errorLog"], json!(log)); assert_eq!(batch_log(&log), "Start Batch\r\n\r\nEnd Batch\r\n"); @@ -1176,7 +1176,7 @@ fn batch_error_log_cannot_replace_an_input_or_result() { let original = std::fs::read(&input).unwrap(); let output = join(&dir, "out"); for log in [input.clone(), join(&output, "source.png"), join(&output, "./source.png"), join(&output, "../out/source.png")] { - let error = Session::new().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); + let error = crate::session().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); assert!(error.to_string().contains("errorLog"), "{error}"); assert_eq!(std::fs::read(&input).unwrap(), original); assert!(!std::path::Path::new(&join(&output, "source.png")).exists()); @@ -1191,7 +1191,7 @@ fn batch_naming_rejects_an_input_alias_through_a_missing_parent() { let original = std::fs::read(&second).unwrap(); let output = join(&dir, "missing/.."); let error = - Session::new().execute("file.automate.batch", json!({"steps": [], "input": [first, second], "output": output, "naming": "b.{ext}"})).unwrap_err(); + crate::session().execute("file.automate.batch", json!({"steps": [], "input": [first, second], "output": output, "naming": "b.{ext}"})).unwrap_err(); assert!(error.to_string().contains("replace an input"), "{error}"); assert_eq!(std::fs::read(&second).unwrap(), original); assert!(!std::path::Path::new(&join(&dir, "missing")).exists()); @@ -1222,7 +1222,7 @@ fn batch_error_log_rejects_a_symlink_parent_alias() { symlink(join(&other, "child"), join(&dir, "link")).unwrap(); let output = other; let log = join(&dir, "link/../result.png"); - let error = Session::new().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); + let error = crate::session().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); assert!(error.to_string().contains("errorLog"), "{error}"); assert!(!std::path::Path::new(&join(&output, "result.png")).exists()); } @@ -1235,7 +1235,7 @@ fn batch_error_log_rejects_an_uncreated_output_alias() { std::fs::create_dir_all(join(&output, "alias")).unwrap(); let log = join(&output, "alias/../source.png"); assert!(same_destination(&log, join(&output, "source.png"))); - let error = Session::new().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); + let error = crate::session().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); assert!(error.to_string().contains("errorLog"), "{error}"); assert!(!std::path::Path::new(&join(&dir, "new-output/source.png")).exists()); } @@ -1274,7 +1274,7 @@ fn future_folder_case_variants_follow_the_nearest_existing_ancestor() { #[test] fn batch_open_source_edits_each_live_document_and_restores_the_active_one() { let dir = tmp("batch-open-documents"); - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"name": "First", "width": 8, "height": 6})).unwrap(); session.execute("file.new", json!({"name": "Second", "width": 12, "height": 5})).unwrap(); session.set_active(0); @@ -1297,7 +1297,7 @@ fn batch_open_source_edits_each_live_document_and_restores_the_active_one() { #[test] fn batch_open_source_exports_later_edits_if_saved_document_stays_active() { let dir = tmp("batch-open-save-point"); - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"name": "First", "width": 8, "height": 6})).unwrap(); session.execute("file.new", json!({"name": "Second", "width": 12, "height": 5})).unwrap(); let result = session @@ -1310,7 +1310,7 @@ fn batch_open_source_exports_later_edits_if_saved_document_stays_active() { ) .unwrap(); assert!(result["errors"].as_array().unwrap().is_empty(), "{result}"); - let mut opened = Session::new(); + let mut opened = crate::session(); opened.execute("file.openAs", json!({"path": join(&dir, "First.png"), "as": "png"})).unwrap(); assert_eq!((doc(&opened).size.width, doc(&opened).size.height), (5, 12), "the still-active saved document includes later edits"); } @@ -1318,7 +1318,7 @@ fn batch_open_source_exports_later_edits_if_saved_document_stays_active() { #[test] fn batch_open_source_save_as_then_close_ask_writes_the_result() { let dir = tmp("batch-open-save-close-ask"); - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"name": "First", "width": 8, "height": 6})).unwrap(); let result = session .execute( @@ -1334,7 +1334,7 @@ fn batch_open_source_save_as_then_close_ask_writes_the_result() { #[test] fn batch_open_source_refuses_a_result_that_replaces_another_open_file() { let dir = tmp("batch-open-replaces-input"); - let mut session = Session::new(); + let mut session = crate::session(); // Saved as PNG under its default name, `a.jpg`'s result is the open `a.png`'s file. for (name, format) in [("a.jpg", "jpg"), ("a.png", "png")] { let path = png(&dir, name, 8, 6, "#ff0000"); @@ -1350,7 +1350,7 @@ fn batch_open_source_refuses_a_result_that_replaces_another_open_file() { #[test] fn batch_open_source_save_step_leaves_an_unwritten_document_changed() { - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"name": "First", "width": 8, "height": 6})).unwrap(); let steps = json!([["image.adjustments.invert", {}], ["file.save", {}]]); // No destination: nothing is written. @@ -1376,7 +1376,7 @@ fn batch_error_log_rejects_a_dangling_link_to_a_planned_output() { let result = join(&output, "source.png"); let log = join(&dir, "errors.txt"); symlink(&result, &log).unwrap(); - let error = Session::new().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); + let error = crate::session().execute("file.automate.batch", json!({"steps": [], "input": [input], "output": output, "errorLog": log})).unwrap_err(); assert!(error.to_string().contains("errorLog"), "{error}"); assert!(!std::path::Path::new(&result).exists(), "the batch must not write before rejecting the alias"); } @@ -1462,7 +1462,7 @@ fn camera_raw_opens_as_16_bit_with_notes() { let (w, h) = (24, 16); let mut spec = DngSpec::cfa(w, h, mosaic(&scene(w, h), w, [0, 1, 1, 2], 0, 65535)); spec.as_shot_neutral = Some([0.5, 1.0, 0.7]); - let mut s = Session::new(); + let mut s = crate::session(); let r = open_bytes_as(&mut s, "IMG_0001.dng", &spec.build(), None, None).unwrap(); assert!(r["warnings"].as_array().is_some_and(|w| w.iter().any(|m| m.as_str().is_some_and(|m| m.contains("DNG")))), "{r}"); assert_eq!((doc(&s).size.width, doc(&s).size.height), (24, 16)); @@ -1489,7 +1489,7 @@ fn batch_same_format_saves_camera_raws_as_psd() { if let Some(naming) = naming { p["naming"] = json!(naming); } - let r = Session::new().execute("file.automate.batch", p).unwrap(); + let r = crate::session().execute("file.automate.batch", p).unwrap(); assert!(r["errors"].as_array().unwrap().is_empty(), "{naming:?}: {r}"); let mut files: Vec = r["files"].as_array().unwrap().iter().map(|f| f.as_str().unwrap().replace('\\', "/")).collect(); files.sort(); @@ -1517,7 +1517,7 @@ fn a_developed_raw_opens_at_the_raw_defaults_resolution() { } crate::jobs::Started::Done(_) => {} }; - let mut s = Session::new(); + let mut s = crate::session(); open_bytes_as(&mut s, "IMG_0001.dng", &raw, None, None).unwrap(); assert_eq!(doc(&s).resolution_dpi, 300.0, "the default"); s.execute("prefs.set", json!({"path": "rawDefaults.resolution", "value": 240})).unwrap(); @@ -1539,7 +1539,7 @@ fn revert_batch_and_stack_open_a_raw_at_the_raw_defaults_resolution() { let dir = tmp("raw-defaults-siblings"); let path = join(&dir, "IMG_0003.dng"); std::fs::write(&path, DngSpec::cfa(w, h, mosaic(&scene(w, h), w, [0, 1, 1, 2], 0, 65535)).build()).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("prefs.set", json!({"path": "rawDefaults.resolution", "value": 240})).unwrap(); open_bytes_as(&mut s, &path, &std::fs::read(&path).unwrap(), None, Some(path.clone())).unwrap(); s.execute("image.imageSize", json!({"resolution": 150, "resample": "none"})).unwrap(); @@ -1583,7 +1583,7 @@ fn revert_batch_and_stack_open_a_raw_at_the_raw_defaults_resolution() { fn revert_reloads_as_one_undoable_step() { let dir = tmp("revert"); let path = png(&dir, "a.png", 16, 12, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("file.revert")); let bytes = std::fs::read(&path).unwrap(); open_bytes_as(&mut s, &path, &bytes, None, Some(path.clone())).unwrap(); @@ -1656,7 +1656,7 @@ fn save_a_copy_refuses_the_documents_own_file() { let dir = tmp("copy-own"); let path = png(&dir, "own.png", 6, 4, "#ff0000"); let bytes = std::fs::read(&path).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open_bytes_as(&mut s, &path, &bytes, None, Some(path.clone())).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#00ff00"})).unwrap(); @@ -1999,7 +1999,7 @@ fn open_as_forces_the_decoder() { let path = png(&dir, "a.png", 6, 5, "#00ff00"); let renamed = join(&dir, "mystery.bin"); std::fs::copy(&path, &renamed).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAs", json!({"path": renamed, "as": "png"})).unwrap(); assert_eq!(doc(&s).size.width, 6); assert_eq!(doc(&s).name, "mystery.bin"); @@ -2112,7 +2112,7 @@ fn rotated_jpeg(dir: &str) -> String { fn rotated_jpegs_open_and_place_upright() { let dir = tmp("orientation"); let path = rotated_jpeg(&dir); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.openAs", json!({"path": path, "as": "jpg"})).unwrap(); assert_eq!((doc(&s).size.width, doc(&s).size.height), (20, 40)); assert!(composite(&s, 10, 5)[0] > 0.8 && composite(&s, 10, 35)[2] > 0.8, "red on top, blue below"); @@ -2400,7 +2400,7 @@ fn file_info_reads_camera_data_from_jpeg_and_psd_exif() { for name in ["x.jpg", "x.psd"] { let (bytes, _) = encode(doc(&s), name, None).unwrap(); let back = photocraft_io::import(name, &bytes).unwrap().document; - let mut t = Session::new(); + let mut t = crate::session(); t.add_document(back, None); assert_eq!(t.execute("file.fileInfo", json!({})).unwrap()["camera"], want, "{name}"); // Editing the description fields leaves the read-only camera data alone. @@ -2777,7 +2777,7 @@ fn flatten_all_layer_effects_keeps_masks() { let path = join(&dir, "masks.pcraft"); save_doc(doc(&s), &path, None).unwrap(); let bytes = std::fs::read(&path).unwrap(); - let mut s2 = Session::new(); + let mut s2 = crate::session(); open_bytes_as(&mut s2, "masks.pcraft", &bytes, None, None).unwrap(); let layers: Vec<_> = doc(&s2).walk().into_iter().map(|(_, _, l)| l).collect(); assert!(layers.iter().any(|l| l.mask == m1 && l.vector_mask == v1), "the raster and vector masks survive .pcraft"); @@ -2905,7 +2905,7 @@ fn layers_to_files_reports_groups_as_exports_and_failures_as_errors() { assert_eq!(export_layers_with(&s, ¶ms, |_, _| Ok(())).unwrap(), names, "legacy Rust helper remains compatible"); assert!(export_layers_report_with(&s, ¶ms, |_, _| Err(EngineError::Other("disk full".into()))).unwrap_err().to_string().contains("disk full")); assert!(export_layers_report_with(&s, &json!({"format": "not-a-format"}), |_, _| panic!("must not write")).is_err()); - assert!(export_layers_report_with(&Session::new(), ¶ms, |_, _| panic!("must not write")).is_err()); + assert!(export_layers_report_with(&crate::session(), ¶ms, |_, _| panic!("must not write")).is_err()); s.edit("Empty", |doc, _| { doc.layers.clear(); Ok(()) @@ -2996,7 +2996,7 @@ fn image_processor_scratch_sessions_answer_to_the_authorization_gate() { let input = join(&dir, "in"); std::fs::create_dir_all(&input).unwrap(); png(&input, "a.png", 40, 20, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); s.authorize = Some(deny_image); let out = join(&dir, "out"); let r = s.execute("file.scripts.imageProcessor", json!({"input": input, "output": out, "format": "jpg", "width": 20, "height": 20})).unwrap(); @@ -3013,7 +3013,7 @@ fn batch_save_points_answer_to_the_authorization_gate() { let input = join(&dir, "in"); std::fs::create_dir_all(&input).unwrap(); png(&input, "a.png", 8, 8, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); s.authorize = Some(deny_save); let out = join(&dir, "out"); let r = s.execute("file.automate.batch", json!({"steps": [["file.save", {}]], "input": input, "output": out, "format": "png"})).unwrap(); @@ -3030,7 +3030,7 @@ fn load_files_into_stack_and_image_processor_and_batch() { let a = png(&input, "a.png", 40, 20, "#ff0000"); let b = png(&input, "b.png", 30, 30, "#0000ff"); std::fs::write(join(&input, "notes.txt"), "not an image").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.scripts.loadFilesIntoStack", json!({"paths": [a, b]})).unwrap(); assert_eq!(r["layers"], 2); assert_eq!((doc(&s).size.width, doc(&s).size.height), (40, 30)); @@ -3087,7 +3087,7 @@ fn named_batch_cycles_stop_before_the_test_ceiling() { child["action"] = json!(if route == "self" || route == "play-parent" { "A" } else { "B" }); let first = if route == "play-child" { ActionStep::new("actions.play", json!({"action": "B"})) } else { ActionStep::new("file.automate.batch", child) }; - let mut s = Session::new(); + let mut s = crate::session(); if source == "open" { s.execute("file.openAs", json!({"path": input})).unwrap(); } @@ -3121,7 +3121,7 @@ fn named_batch_limits_nesting_and_keeps_the_callers_state() { let input = png(&dir, "red.png", 8, 8, "#ff0000"); let output = join(&dir, "out"); let params = json!({"action": "Invert", "source": source, "input": [input], "output": output, "format": "png"}); - let mut s = Session::new(); + let mut s = crate::session(); if source == "open" { s.execute("file.openAs", json!({"path": input})).unwrap(); } @@ -3163,7 +3163,7 @@ fn named_batch_charges_the_existing_budget_across_inputs_and_children() { let dir = tmp("named-batch-budget"); let input = png(&dir, "red.png", 8, 8, "#ff0000"); let output = join(&dir, "out"); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list.push(Action::new("Large", vec![ActionStep::new("image.adjustments.invert", json!({})); 100])).unwrap(); let result = s.execute("file.automate.batch", json!({"action": "Large", "input": vec![input.clone(); 1001], "output": output})).unwrap_err(); assert!(result.to_string().contains("step limit"), "{result}"); @@ -3206,7 +3206,7 @@ fn named_batch_allows_nested_work_and_preserves_authorization() { let output = join(&dir, &format!("out-{denied}")); let inner = join(&dir, &format!("inner-{denied}")); let child = json!({"action": "Leaf", "input": [input], "output": inner, "format": "png"}); - let mut s = Session::new(); + let mut s = crate::session(); s.actions.list = list_of(vec![ Action::new("Outer", vec![ActionStep::new("file.automate.batch", child)]), Action::new("Leaf", vec![ActionStep::new("image.adjustments.invert", json!({}))]), @@ -3238,7 +3238,7 @@ fn nested_batch_errors_stop_actions_but_direct_scripts_keep_results_and_continue let input = png(&dir, "red.png", 8, 8, "#ff0000"); let output = join(&dir, "out"); let batch = json!({"input": [input], "output": output, "steps": [["file.close", {}]]}); - let mut s = Session::new(); + let mut s = crate::session(); let result = s.execute("file.automate.batch", batch.clone()).unwrap(); assert_eq!(result["files"], json!([])); assert_eq!(result["errors"].as_array().unwrap().len(), 1); @@ -3268,7 +3268,7 @@ fn nested_batch_partial_failures_keep_outputs_and_stop_only_action_parents() { let corrupt = join(&dir, "corrupt.png"); std::fs::write(&corrupt, b"not a PNG").unwrap(); for caller in ["batch", "action", "script"] { - let mut s = Session::new(); + let mut s = crate::session(); let output = join(&dir, caller); let batch = json!({"input": [input, corrupt], "output": output, "steps": [], "format": "png"}); let steps = vec![ActionStep::new("file.automate.batch", batch.clone()), ActionStep::new("file.new", json!({"width": 2, "height": 2}))]; @@ -3310,7 +3310,7 @@ fn successful_nested_batch_allows_later_action_steps() { use crate::actions_cmds::Action; let dir = tmp("nested-batch-success"); let input = png(&dir, "red.png", 8, 8, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); let batch = json!({"input": [input], "output": join(&dir, "success"), "steps": [], "format": "png"}); s.actions .list @@ -3329,7 +3329,7 @@ fn nested_batches_retain_partial_results() { let input = png(&dir, "red.png", 8, 8, "#ff0000"); let corrupt = join(&dir, "corrupt.png"); std::fs::write(&corrupt, b"not a PNG").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); for (source, naming) in [("folder", None), ("folder", Some("{serial}")), ("open", None)] { let output = join( &dir, @@ -3486,7 +3486,7 @@ fn exported_selected_cube_round_trips_through_lookup_importer() { /// document's resolution; percent is of the target's width or height, by axis. #[test] fn guide_layouts_take_units() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1200, "height": 600, "resolution": 300})).unwrap(); let close = |a: &[f64], b: &[f64]| a.len() == b.len() && a.iter().zip(b).all(|(x, y)| (x - y).abs() < 0.01); // 1 cm at 300 ppi is 118.11 px; 0.25 in is 75 px. @@ -3607,7 +3607,7 @@ fn batch_naming_serial_keeps_same_named_inputs_and_their_pixels() { std::fs::create_dir_all(&second).unwrap(); let inputs = [png(&first, "photo.png", 8, 8, "#ff0000"), png(&second, "photo.png", 8, 8, "#0000ff")]; let out = join(&dir, "out"); - let mut s = Session::new(); + let mut s = crate::session(); let result = s .execute( "file.automate.batch", @@ -3633,7 +3633,7 @@ fn batch_reports_inputs_that_share_an_output_name() { let input = join(&dir, "in"); std::fs::create_dir_all(&input).unwrap(); png(&input, "a.png", 8, 8, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap(); save_doc(doc(&s), &join(&input, "a.jpg"), None).unwrap(); png(&input, "B.png", 8, 8, "#00ff00"); @@ -3741,7 +3741,7 @@ fn batch_include_all_subfolders() { png(&join(&input, "sub"), "b.png", 8, 8, "#00ff00"); png(&join(&input, "sub/deeper"), "a.png", 8, 8, "#0000ff"); png(&join(&input, "z"), "a.png", 8, 8, "#ffffff"); - let mut s = Session::new(); + let mut s = crate::session(); // Default: the top level only, as before. let out = join(&input, "batch"); let r = s.execute("file.automate.batch", json!({"steps": [], "input": input, "output": out, "format": "png"})).unwrap(); @@ -3834,7 +3834,7 @@ fn batch_subfolder_walk_survives_symlink_loops() { fn batch_naming_validates_the_whole_plan_before_writing() { let dir = tmp("naming-invalid"); let input = png(&dir, "source.png", 8, 8, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); for (index, extra) in [ json!({"naming": "../{name}"}), json!({"naming": "sub\\{name}"}), @@ -3867,7 +3867,7 @@ fn batch_naming_keeps_serial_positions_after_errors_and_captures_the_utc_date() let input = png(&dir, "good.png", 8, 8, "#0000ff"); let out = join(&dir, "out"); let before = crate::analysis_cmds::now_iso(); - let mut s = Session::new(); + let mut s = crate::session(); let result = s .execute( "file.automate.batch", @@ -3894,7 +3894,7 @@ fn batch_naming_later_result_replaces_the_earlier_one() { let red = png(&dir, "red.png", 8, 8, "#ff0000"); let blue = png(&dir, "blue.png", 8, 8, "#0000ff"); let out = join(&dir, "out"); - let mut s = Session::new(); + let mut s = crate::session(); let result = s .execute( "file.automate.batch", @@ -3914,7 +3914,7 @@ fn batch_naming_rejects_outputs_that_replace_inputs_before_processing() { let first = png(&dir, "002.png", 8, 8, "#ff0000"); let second = png(&dir, "001.png", 8, 8, "#0000ff"); let before = [std::fs::read(&first).unwrap(), std::fs::read(&second).unwrap()]; - let mut s = Session::new(); + let mut s = crate::session(); // Without preflight, processing 002 first writes 001, so the next input's original pixels // are lost before it is read. The full plan must be rejected without writing either file. let error = s @@ -3939,7 +3939,7 @@ fn batch_saves_at_the_recorded_save_so_a_close_after_it_keeps_the_result() { let dir = tmp("batch-save-close"); let red = png(&dir, "red.png", 8, 8, "#ff0000"); let saved = |out: &str| photocraft_io::import("red.png", &std::fs::read(join(out, "red.png")).unwrap()).unwrap().document; - let mut s = Session::new(); + let mut s = crate::session(); let out = join(&dir, "close"); let steps = json!([["image.adjustments.invert", {}], ["file.saveAs", {}], ["file.close", {}]]); let r = s.execute("file.automate.batch", json!({"input": [red], "output": out, "format": "png", "steps": steps})).unwrap(); @@ -3973,7 +3973,7 @@ fn batch_save_as_then_close_that_asks_processes_every_file() { let input = vec![png(&dir, "red.png", 8, 8, "#ff0000"), png(&dir, "blue.png", 8, 8, "#0000ff")]; let out = join(&dir, "out"); let steps = json!([["image.adjustments.invert", {}], ["file.saveAs", {}], ["file.close", {"save": "ask"}]]); - let r = Session::new().execute("file.automate.batch", json!({"input": input, "output": out, "format": "png", "steps": steps})).unwrap(); + let r = crate::session().execute("file.automate.batch", json!({"input": input, "output": out, "format": "png", "steps": steps})).unwrap(); assert_eq!(r["errors"], json!([]), "{r}"); assert_eq!(r["files"].as_array().unwrap().len(), 2, "{r}"); let red = photocraft_io::import("red.png", &std::fs::read(join(&out, "red.png")).unwrap()).unwrap().document; @@ -3981,7 +3981,7 @@ fn batch_save_as_then_close_that_asks_processes_every_file() { // A Save a Copy doesn't save the document itself: the Close that asks still refuses it. let out = join(&dir, "copy"); let steps = json!([["image.adjustments.invert", {}], ["file.saveACopy", {}], ["file.close", {"save": "ask"}]]); - let r = Session::new().execute("file.automate.batch", json!({"input": input, "output": out, "format": "png", "steps": steps})).unwrap(); + let r = crate::session().execute("file.automate.batch", json!({"input": input, "output": out, "format": "png", "steps": steps})).unwrap(); assert_eq!(r["files"], json!([]), "{r}"); assert_eq!(r["errors"].as_array().unwrap().len(), 2, "{r}"); } @@ -4000,7 +4000,7 @@ fn batch_saves_the_document_active_at_the_save_not_the_one_left_after_it() { ["file.close", {}], ["image.adjustments.invert", {}] ]); - let r = Session::new().execute("file.automate.batch", json!({"input": [red], "output": out, "format": "png", "steps": steps})).unwrap(); + let r = crate::session().execute("file.automate.batch", json!({"input": [red], "output": out, "format": "png", "steps": steps})).unwrap(); assert_eq!(r["errors"], json!([]), "{r}"); let saved = photocraft_io::import("red.png", &std::fs::read(join(&out, "red.png")).unwrap()).unwrap().document; assert_eq!((saved.size.width, saved.size.height), (4, 4)); @@ -4014,7 +4014,7 @@ fn batch_saves_the_document_active_at_the_save_not_the_one_left_after_it() { fn batch_applies_the_steps_after_a_save_while_its_document_is_open() { let dir = tmp("batch-save-then-edit"); let red = png(&dir, "red.png", 8, 8, "#ff0000"); - let mut s = Session::new(); + let mut s = crate::session(); let out = join(&dir, "edited"); let steps = json!([["file.saveAs", {}], ["image.adjustments.invert", {}]]); let r = s.execute("file.automate.batch", json!({"input": [red], "output": out, "format": "png", "steps": steps})).unwrap(); @@ -4077,13 +4077,13 @@ fn folder_listing_takes_every_format_photocraft_opens() { #[test] fn batch_save_and_close_refuses_a_source_it_would_save_in_another_format() { let dir = tmp("batch-save-close-cin"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "#ff0000"})).unwrap(); let cin = join(&dir, "a.cin"); save_doc(doc(&s), &cin, None).unwrap(); let png_path = png(&dir, "b.png", 8, 8, "#ff0000"); let (cin_before, png_before) = (std::fs::read(&cin).unwrap(), std::fs::read(&png_path).unwrap()); - let r = Session::new() + let r = crate::session() .execute("file.automate.batch", json!({"input": dir, "destination": "saveAndClose", "steps": [["image.adjustments.invert", {}]]})) .unwrap(); let errors = r["errors"].as_array().unwrap(); @@ -4100,14 +4100,14 @@ fn batch_folder_processes_netpbm_and_dds_files() { let dir = tmp("batch-folder-formats"); let src = join(&dir, "in"); std::fs::create_dir_all(&src).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "#ff0000"})).unwrap(); for name in ["a.pam", "b.pfm", "c.dds"] { save_doc(doc(&s), &join(&src, name), None).unwrap(); } std::fs::write(join(&src, "notes.txt"), b"not an image").unwrap(); let out = join(&dir, "out"); - let r = Session::new().execute("file.automate.batch", json!({"steps": [], "input": src, "output": out, "format": "png"})).unwrap(); + let r = crate::session().execute("file.automate.batch", json!({"steps": [], "input": src, "output": out, "format": "png"})).unwrap(); assert!(r["errors"].as_array().unwrap().is_empty(), "{r}"); let mut files: Vec = r["files"].as_array().unwrap().iter().map(|f| file_name(f.as_str().unwrap())).collect(); files.sort(); @@ -4159,7 +4159,7 @@ fn save_a_copy_writes_the_tiff_compression_asked_for() { #[test] fn save_a_copy_writes_the_tiff_pyramid_and_transparency_asked_for() { let dir = tmp("tiff-options"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100, "background": "transparent"})).unwrap(); let out = join(&dir, "p.tif"); s.execute("file.saveACopy", json!({"path": out, "tiffPyramid": true})).unwrap(); @@ -4210,7 +4210,7 @@ fn a_droplet_that_runs_itself_stops_at_the_nesting_limit() { let out = join(&dir, "out"); let step = json!(["file.automate.runDroplet", {"droplet": droplet, "input": [input], "output": out}]); std::fs::write(&droplet, json!({"photocraftDroplet": 1, "name": "self", "action": {"steps": [step]}, "options": {"format": "png"}}).to_string()).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); // Each level runs the next in a scratch session; the innermost is refused, so this returns. let r = s.execute("file.automate.runDroplet", json!({"droplet": droplet, "input": [input], "output": out})).unwrap(); assert_eq!(s.actions.batch_depth, 0); @@ -4265,7 +4265,7 @@ fn approve_memory_validates_parameters_and_unknown_ids() { #[test] fn approve_memory_cancels_and_removes_pending_preflight() { - let mut s = Session::new(); + let mut s = crate::session(); let id = s .store_pending_preflight(crate::jobs::PendingPsdPreflight { id: 0, @@ -4291,7 +4291,7 @@ fn approve_memory_refuses_when_source_changes_before_confirmation() { let path = join(&dir, "change.psd"); std::fs::write(&path, b"initial content").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let src = crate::jobs::OpenSource::Path(path.clone()); let fp = crate::jobs::SourceFingerprint::of(&src).unwrap(); let id = s @@ -4318,7 +4318,7 @@ fn approve_memory_refuses_when_source_changes_before_confirmation() { #[test] fn approve_memory_refuses_when_available_ram_decreases() { let gb = 1u64 << 30; - let mut s = Session::new(); + let mut s = crate::session(); let src = crate::jobs::OpenSource::Bytes(std::sync::Arc::new(vec![0; 16])); let fp = crate::jobs::SourceFingerprint::of(&src).unwrap(); let id = s @@ -4345,7 +4345,7 @@ fn approve_memory_refuses_when_available_ram_decreases() { #[test] fn pending_preflights_cap_fails_closed() { - let mut s = Session::new(); + let mut s = crate::session(); let src = crate::jobs::OpenSource::Bytes(std::sync::Arc::new(vec![0; 4])); let fp = crate::jobs::SourceFingerprint::of(&src).unwrap(); for i in 0..crate::Session::MAX_PENDING_PREFLIGHTS { @@ -4398,7 +4398,7 @@ fn memory_preflight(name: &str, source: crate::jobs::OpenSource) -> crate::jobs: #[test] fn pending_preflights_bound_retained_bytes_and_charge_a_shared_buffer_once() { - let mut s = Session::new(); + let mut s = crate::session(); let cap = 100; let a_src = crate::jobs::OpenSource::Bytes(std::sync::Arc::new(vec![0u8; 40])); let b_src = crate::jobs::OpenSource::Bytes(std::sync::Arc::new(vec![0u8; 40])); @@ -4428,7 +4428,7 @@ fn pending_preflights_bound_retained_bytes_and_charge_a_shared_buffer_once() { #[test] fn pending_preflights_charge_the_retained_allocation_not_the_visible_length() { - let mut s = Session::new(); + let mut s = crate::session(); let cap = 100; // Room for 128 bytes but one byte of contents: what stays resident is the allocation, so a // cap that fits the contents must still refuse it. @@ -4474,7 +4474,7 @@ fn pending_preflights_charge_the_retained_allocation_not_the_visible_length() { #[test] fn approve_memory_is_neither_journaled_nor_recorded_in_an_action() { - let mut s = Session::new(); + let mut s = crate::session(); let id = s.store_pending_preflight(memory_preflight("cancel.psd", crate::jobs::OpenSource::Bytes(std::sync::Arc::new(vec![0u8; 4])))).unwrap(); s.execute("actions.record", json!({"name": "Memory approvals"})).unwrap(); let r = s.execute("file.approveMemory", json!({"id": id, "approve": false})).unwrap(); @@ -4488,7 +4488,7 @@ fn approve_memory_is_neither_journaled_nor_recorded_in_an_action() { #[test] fn approve_memory_releases_the_preflight_when_the_hard_limit_refuses_it() { let gb = 1u64 << 30; - let mut s = Session::new(); + let mut s = crate::session(); let preflight = crate::jobs::PendingPsdPreflight { required: 8 * gb, soft_limit: 6 * gb, @@ -4518,7 +4518,7 @@ fn open_as_and_place_keep_the_typed_hard_budget_fields() { let gb = 1u64 << 30; let dir = tmp("hard_budget"); let path = join(&dir, "big.psd"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 4, "height": 4, "depth": 8})).unwrap(); std::fs::write(&path, photocraft_io::export(&src.active().unwrap().doc, "x.psd", &Default::default()).unwrap().bytes).unwrap(); // An estimate over the resolved hard ceiling is refused, and no approval raises the ceiling. @@ -4528,7 +4528,7 @@ fn open_as_and_place_keep_the_typed_hard_budget_fields() { assert!(hard < u64::MAX); photocraft_io::memory::with_mock_memory(snap, || { photocraft_io::psd_budget::with_test_estimate_charge(hard + 1, || { - let mut s = Session::new(); + let mut s = crate::session(); let err = s.execute("file.openAs", json!({"path": path.clone(), "approveHighMemory": true})).unwrap_err(); match &err { EngineError::PsdHardBudget { name, required, limit, .. } => { @@ -4733,7 +4733,7 @@ fn save_and_close_refuses_a_read_only_source() { p["overrideOpen"] = json!(true); p["steps"] = json!([["file.openAs", {"path": join(&dir, "elsewhere.png")}]]); } - let result = Session::new().execute("file.automate.batch", p).unwrap(); + let result = crate::session().execute("file.automate.batch", p).unwrap(); let error = result["errors"][0]["error"].as_str().unwrap_or_default(); assert!(error.contains("cannot replace this source"), "overrideOpen {override_open}: {result}"); assert_eq!(std::fs::read(&source).unwrap(), bytes, "overrideOpen {override_open}: the source is unchanged"); diff --git a/crates/engine/src/cmd/fill_cmds.rs b/crates/engine-core/src/cmd/fill_cmds.rs similarity index 100% rename from crates/engine/src/cmd/fill_cmds.rs rename to crates/engine-core/src/cmd/fill_cmds.rs diff --git a/crates/engine/src/cmd/fill_cmds/tests.rs b/crates/engine-core/src/cmd/fill_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/fill_cmds/tests.rs rename to crates/engine-core/src/cmd/fill_cmds/tests.rs index 8247c78c8c..69ebe30f58 100644 --- a/crates/engine/src/cmd/fill_cmds/tests.rs +++ b/crates/engine-core/src/cmd/fill_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use serde_json::json; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "background": "transparent"})).unwrap(); s } @@ -88,7 +88,7 @@ fn opacity_mode_and_preserve_transparency() { fn opaque_dissolve_fill_covers_the_largest_noise_sample_at_every_depth() { // (8, 246) hashes to the largest noise sample: it must still be below full coverage. for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 9, "height": 247, "depth": depth, "background": "transparent"})).unwrap(); s.execute(CMD, json!({"contents": "white", "mode": "dissolve", "opacity": 0})).unwrap(); assert_eq!(px(&s, 8, 246)[3], 0.0, "{depth}-bit zero-opacity fill"); @@ -109,7 +109,7 @@ fn preserve_transparency_blends_source_atop_on_semi_transparent_pixels() { // colour moved halfway, at every depth and in non-Normal modes too (#5783). for depth in [8, 16, 32] { for mode in ["normal", "multiply"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth, "background": "transparent"})).unwrap(); s.execute(CMD, json!({"contents": "white", "opacity": 50})).unwrap(); s.execute(CMD, json!({"contents": "black", "opacity": 50, "mode": mode, "preserveTransparency": true})).unwrap(); @@ -144,7 +144,7 @@ fn history_pattern_and_content_aware() { #[test] fn history_fill_reads_a_source_when_its_pixels_were_locked() { // Given a white layer locked in history state 1, then unlocked and filled red. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); s.execute("layer.lockLayers", json!({"pixels": true})).unwrap(); s.execute("layer.lockLayers", json!({"pixels": false})).unwrap(); @@ -161,7 +161,7 @@ fn history_fill_reads_a_source_when_its_pixels_were_locked() { #[test] fn history_fill_refuses_a_locked_destination_when_source_is_unlocked() { // Given an unlocked white source and a red, currently locked destination. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); s.execute(CMD, json!({"color": "#ff0000"})).unwrap(); s.execute("layer.lockLayers", json!({"pixels": true})).unwrap(); @@ -178,7 +178,7 @@ fn history_fill_refuses_a_locked_destination_when_source_is_unlocked() { #[test] #[ignore] fn timing_24mp() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute(CMD, json!({"contents": "white"})).unwrap(); @@ -301,7 +301,7 @@ fn content_aware_huge_extent_is_an_error() { /// they were (shared with the history), instead of storing a copy of each (#4517). #[test] fn unselected_tiles_stay_shared() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1024, "height": 1024, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#336699"})).unwrap(); diff --git a/crates/engine/src/cmd/fill_key_cmds.rs b/crates/engine-core/src/cmd/fill_key_cmds.rs similarity index 99% rename from crates/engine/src/cmd/fill_key_cmds.rs rename to crates/engine-core/src/cmd/fill_key_cmds.rs index b2135984e2..ea18dbf1e6 100644 --- a/crates/engine/src/cmd/fill_key_cmds.rs +++ b/crates/engine-core/src/cmd/fill_key_cmds.rs @@ -168,7 +168,7 @@ mod tests { } fn session_at(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 6, "background": "transparent", "depth": depth})).unwrap(); s.execute("tools.setColors", json!({"foreground": "#ff0000", "background": "#0000ff"})).unwrap(); s @@ -271,7 +271,7 @@ mod tests { #[test] fn locked_layer_and_no_document_are_errors() { - let mut s = Session::new(); + let mut s = crate::session(); for id in IDS { assert!(s.execute(id, json!({})).is_err(), "{id} without a document"); } @@ -288,7 +288,7 @@ mod tests { #[test] #[ignore] fn fill_keys_24mp() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000})).unwrap(); for (id, sel) in [("edit.fillForeground", false), ("edit.fillBackgroundPreserve", false), ("edit.fillForeground", true)] { if sel { @@ -311,7 +311,7 @@ mod tests { /// whatever its sRGB stand-in converts back to (100/28/0/17). #[test] fn cmyk_pick_fills_a_cmyk_document_with_the_picked_inks() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.execute("image.mode.cmyk", json!({})).unwrap(); let rgb = photocraft_color::convert::cmyk_to_rgb([1.0, 0.0, 0.0, 0.0]).map(|c| c.clamp(0.0, 1.0)); @@ -331,6 +331,7 @@ mod tests { #[test] fn registered_with_photoshop_default_shortcuts() { + crate::install().unwrap(); let sc = |id| crate::commands::find(id).and_then(|c| c.shortcut); assert_eq!(sc("edit.fillForeground"), Some("Alt+Backspace")); assert_eq!(sc("edit.fillBackground"), Some("Cmd+Backspace")); diff --git a/crates/engine/src/cmd/float_cmds.rs b/crates/engine-core/src/cmd/float_cmds.rs similarity index 100% rename from crates/engine/src/cmd/float_cmds.rs rename to crates/engine-core/src/cmd/float_cmds.rs diff --git a/crates/engine/src/cmd/float_cmds/tests.rs b/crates/engine-core/src/cmd/float_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/float_cmds/tests.rs rename to crates/engine-core/src/cmd/float_cmds/tests.rs index 1a9ebe332d..1102e976a5 100644 --- a/crates/engine/src/cmd/float_cmds/tests.rs +++ b/crates/engine-core/src/cmd/float_cmds/tests.rs @@ -5,7 +5,7 @@ use super::*; /// An 80×60 transparent document whose layer is painted red over (10..30)²; (10..30)² selected. fn session() -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "background": "transparent"})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); s.edit("paint", |doc, _| { @@ -104,7 +104,7 @@ fn history_panel_steps_put_the_piece_back_and_keep_the_redo_states() { #[test] fn needs_a_selection_and_an_unlocked_pixel_layer() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); assert!(!s.is_enabled("select.float"), "no selection"); s.execute("select.all", json!({})).unwrap(); @@ -118,7 +118,7 @@ fn needs_a_selection_and_an_unlocked_pixel_layer() { /// On the Background, which can't hold transparency, the hole takes the background colour. #[test] fn on_the_background_the_hole_takes_the_background_colour() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.tools.background = [0.0, 0.0, 1.0, 1.0]; let id = s.active().unwrap().active_layer.unwrap(); @@ -135,7 +135,7 @@ fn on_the_background_the_hole_takes_the_background_colour() { #[test] fn a_copy_leaves_the_original_at_every_depth_in_one_undo_step() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "background": "transparent", "depth": depth})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); @@ -156,7 +156,7 @@ fn a_copy_leaves_the_original_at_every_depth_in_one_undo_step() { #[test] #[ignore] fn float_drag_bench() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, a| { @@ -231,7 +231,7 @@ fn cutting_an_untouched_part_of_the_mask_moves_it_and_leaves_the_background_colo /// whole, leaving nothing behind (Photoshop); a half selection of an opaque pixel still splits it. #[test] fn a_layers_own_transparency_floats_its_soft_pixels_whole() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "background": "transparent"})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); s.edit("paint", |doc, _| { @@ -279,7 +279,7 @@ fn doc_rect(w: i32, h: i32) -> Rect { #[test] fn float_shares_interior_tiles_on_cut_and_place() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1024, "height": 1024})).unwrap(); s.tools.background = [0.2, 0.4, 0.8, 1.0]; let id = s.active().unwrap().active_layer.unwrap(); @@ -317,7 +317,7 @@ fn float_shares_interior_tiles_on_cut_and_place() { #[test] fn float_feathered_selection_preserves_partial_alpha_across_depths() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 80, "background": "transparent", "depth": depth})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); s.edit("paint", |doc, _| { @@ -348,7 +348,7 @@ fn selected(d: &Document, x: i32, y: i32) -> f32 { fn moving_shrinks_the_selection_to_the_moved_pixels_at_every_depth() { for depth in [8, 16, 32] { for copy in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "background": "transparent", "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); @@ -401,7 +401,7 @@ fn the_outline_is_what_the_moved_pixels_took() { #[test] fn the_selection_just_moves_without_transparency_to_shrink_to() { // The Background. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("select.rect", json!({"x": 5, "y": 5, "width": 10, "height": 10})).unwrap(); s.execute("select.float", json!({"dx": 15, "dy": 0})).unwrap(); @@ -433,7 +433,7 @@ fn the_selection_just_moves_without_transparency_to_shrink_to() { #[test] fn moving_again_from_the_shrunk_selection_leaves_no_edge_behind() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 100, "background": "transparent", "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 20, "y": 20, "width": 50, "height": 40, "ellipse": true})).unwrap(); s.execute("edit.fill", json!({"color": "#0000ff"})).unwrap(); @@ -594,7 +594,7 @@ fn a_command_refused_on_a_hidden_layer_leaves_the_piece_floating() { #[test] fn a_command_refused_for_the_colour_mode_leaves_the_piece_floating() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("image.mode.indexedColor", json!({"palette": "exact", "dither": "none", "forced": "none"})).unwrap(); s.execute("select.rect", json!({"x": 5, "y": 5, "width": 10, "height": 10})).unwrap(); @@ -612,7 +612,7 @@ fn a_command_refused_for_the_colour_mode_leaves_the_piece_floating() { /// (#12032) and leaves the moved piece floating. #[test] fn a_magic_eraser_click_refused_in_indexed_color_leaves_the_piece_floating() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("image.mode.indexedColor", json!({"palette": "exact", "dither": "none", "forced": "none"})).unwrap(); s.execute("select.rect", json!({"x": 5, "y": 5, "width": 10, "height": 10})).unwrap(); diff --git a/crates/engine/src/cmd/font_library_cmds.rs b/crates/engine-core/src/cmd/font_library_cmds.rs similarity index 100% rename from crates/engine/src/cmd/font_library_cmds.rs rename to crates/engine-core/src/cmd/font_library_cmds.rs diff --git a/crates/engine/src/cmd/font_library_cmds/tests.rs b/crates/engine-core/src/cmd/font_library_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/font_library_cmds/tests.rs rename to crates/engine-core/src/cmd/font_library_cmds/tests.rs index c31c65353a..26eae93a5e 100644 --- a/crates/engine/src/cmd/font_library_cmds/tests.rs +++ b/crates/engine-core/src/cmd/font_library_cmds/tests.rs @@ -3,7 +3,7 @@ use serde_json::json; use super::*; fn session() -> Session { - Session::new() + crate::session() } #[test] @@ -72,6 +72,7 @@ fn bad_params_are_errors_and_change_nothing() { #[test] fn font_library_edits_are_not_recorded_into_actions() { + crate::install().unwrap(); // Playing an action back must not rewrite the user's favourite fonts. for id in ["type.font.favorite", "type.font.library"] { assert!(!crate::actions_cmds::replayable(id), "{id}"); diff --git a/crates/engine/src/cmd/frame_cmds.rs b/crates/engine-core/src/cmd/frame_cmds.rs similarity index 100% rename from crates/engine/src/cmd/frame_cmds.rs rename to crates/engine-core/src/cmd/frame_cmds.rs diff --git a/crates/engine/src/cmd/frame_cmds/content_name_tests.rs b/crates/engine-core/src/cmd/frame_cmds/content_name_tests.rs similarity index 99% rename from crates/engine/src/cmd/frame_cmds/content_name_tests.rs rename to crates/engine-core/src/cmd/frame_cmds/content_name_tests.rs index 70d28d988a..ab1e3ea809 100644 --- a/crates/engine/src/cmd/frame_cmds/content_name_tests.rs +++ b/crates/engine-core/src/cmd/frame_cmds/content_name_tests.rs @@ -7,7 +7,7 @@ use photocraft_geom::Rect; /// The issue's document: 600 x 400 px with a white Background, pixel layers Red (100 x 80 at /// 50,50) and Blue, and an empty pixel layer on top. fn session() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 600, "height": 400})).unwrap(); let (red, blue) = s .edit("setup", |doc, _| { diff --git a/crates/engine/src/cmd/frame_cmds/tests.rs b/crates/engine-core/src/cmd/frame_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/frame_cmds/tests.rs rename to crates/engine-core/src/cmd/frame_cmds/tests.rs index d399af33cf..d672a24ff9 100644 --- a/crates/engine/src/cmd/frame_cmds/tests.rs +++ b/crates/engine-core/src/cmd/frame_cmds/tests.rs @@ -3,7 +3,7 @@ use photocraft_doc::{Layer, LayerContent}; use photocraft_geom::Rect; fn session() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60})).unwrap(); let (a, b) = s .edit("setup", |doc, _| { @@ -112,7 +112,7 @@ fn new_frame_takes_a_type_layer() { #[test] fn needs_a_selected_layer() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("layer.new.frameFromLayers", json!({})).is_err()); } @@ -126,7 +126,7 @@ impl TestMask { #[test] fn frame_and_smart_image_transform_independently_at_every_depth() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":80,"height":60,"depth":depth})).unwrap(); let source = s .edit("Image", |doc, _| { @@ -184,7 +184,7 @@ fn frame_placement_covers_and_replaces_with_one_undo() { fn frame_shapes_strokes_and_editability_survive_native_and_psd() { for depth in [8, 16, 32] { for shape in ["rectangle", "ellipse", "triangle", "polygon", "custom"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":64,"height":48,"depth":depth,"background":"transparent"})).unwrap(); let p = json!({"x":12,"y":10,"width":32,"height":24,"shape":shape,"sides":6, "path":{"subpaths":[{"closed":true,"knots":[[0,0],[100,0],[50,100]]}]},"stroke":{"color":"#ff0000","width":3,"align":"outside"}}); @@ -323,7 +323,7 @@ fn copying_an_image_into_a_frame_preserves_the_source_and_undoes_together() { #[test] fn empty_frame_placeholders_do_not_schedule_canvas_sized_composites() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":6000,"height":4000})).unwrap(); let frame = LayerId(s.execute("layer.new.frame", json!({"x":100,"y":100,"width":5800,"height":3800})).unwrap()["layer"].as_u64().unwrap()); let st = s.active().unwrap(); diff --git a/crates/engine/src/cmd/fx_view_cmds.rs b/crates/engine-core/src/cmd/fx_view_cmds.rs similarity index 99% rename from crates/engine/src/cmd/fx_view_cmds.rs rename to crates/engine-core/src/cmd/fx_view_cmds.rs index 7031d4c7b6..b28c957b06 100644 --- a/crates/engine/src/cmd/fx_view_cmds.rs +++ b/crates/engine-core/src/cmd/fx_view_cmds.rs @@ -86,7 +86,7 @@ mod tests { use super::*; fn session() -> (Session, u64, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let a = s.execute("layer.new.layer", json!({"name": "a"})).unwrap()["layer"].as_u64().unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#ff0000"})).unwrap(); @@ -163,7 +163,7 @@ mod tests { ] { assert!(s.execute(ID, p.clone()).is_err(), "{p}"); } - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute(ID, json!({})).is_err()); empty.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert!(empty.execute(ID, json!({"all": true})).is_err(), "no effects: disabled"); diff --git a/crates/engine/src/cmd/fx_visibility_cmds.rs b/crates/engine-core/src/cmd/fx_visibility_cmds.rs similarity index 99% rename from crates/engine/src/cmd/fx_visibility_cmds.rs rename to crates/engine-core/src/cmd/fx_visibility_cmds.rs index dadb8f888b..3e34ffbf33 100644 --- a/crates/engine/src/cmd/fx_visibility_cmds.rs +++ b/crates/engine-core/src/cmd/fx_visibility_cmds.rs @@ -78,7 +78,7 @@ mod tests { /// A red layer with a drop shadow and a blue colour overlay, and the background (no effects). fn session() -> (Session, u64, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id.0; let a = s.execute("layer.new.layer", json!({"name": "a"})).unwrap()["layer"].as_u64().unwrap(); @@ -189,7 +189,7 @@ mod tests { assert!(s.execute(ID, p.clone()).is_err(), "{p}"); } assert_eq!(state(&s, a), before, "a refused call changes nothing"); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute(ID, json!({})).is_err()); empty.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert!(empty.execute(ID, json!({})).is_err(), "no effects: disabled"); diff --git a/crates/engine/src/cmd/gallery_cmds.rs b/crates/engine-core/src/cmd/gallery_cmds.rs similarity index 100% rename from crates/engine/src/cmd/gallery_cmds.rs rename to crates/engine-core/src/cmd/gallery_cmds.rs diff --git a/crates/engine/src/cmd/gallery_cmds/tests.rs b/crates/engine-core/src/cmd/gallery_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/gallery_cmds/tests.rs rename to crates/engine-core/src/cmd/gallery_cmds/tests.rs index 064bddca3c..849f8e943d 100644 --- a/crates/engine/src/cmd/gallery_cmds/tests.rs +++ b/crates/engine-core/src/cmd/gallery_cmds/tests.rs @@ -7,7 +7,7 @@ const W: i32 = 40; const H: i32 = 32; fn session(depth: u32, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth, "mode": mode})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("pattern", |doc, active| { diff --git a/crates/engine/src/cmd/gradient_alpha_method_tests.rs b/crates/engine-core/src/cmd/gradient_alpha_method_tests.rs similarity index 97% rename from crates/engine/src/cmd/gradient_alpha_method_tests.rs rename to crates/engine-core/src/cmd/gradient_alpha_method_tests.rs index 2603061025..b1314c2c0d 100644 --- a/crates/engine/src/cmd/gradient_alpha_method_tests.rs +++ b/crates/engine-core/src/cmd/gradient_alpha_method_tests.rs @@ -8,7 +8,7 @@ use serde_json::{Value, json}; use crate::Session; fn drawn(extra: Value) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "transparent"})).unwrap(); let mut p = json!({"gradient": "Foreground to Transparent", "from": [100, 300], "to": [700, 300], "dither": false}); for (k, v) in extra.as_object().unwrap() { @@ -46,7 +46,7 @@ fn without_a_method_the_ramp_stays_straight() { #[test] fn opaque_gradients_paint_the_same_with_a_method() { let paint = |extra: Value| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 8, "background": "white"})).unwrap(); let mut p = json!({"colors": ["#000000", "#ffffff"], "from": [0, 4], "to": [64, 4], "dither": false}); for (k, v) in extra.as_object().unwrap() { @@ -81,7 +81,7 @@ fn unmeasured_methods_and_smoothness_keep_todays_ramp() { } fn drawn_colors(colors: Value) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "transparent"})).unwrap(); let p = json!({"colors": colors, "transparency": [[0, 100], [1, 0]], "method": "smooth", "from": [100, 300], "to": [700, 300], "dither": false}); s.execute("paint.gradient", p).unwrap(); diff --git a/crates/engine/src/cmd/gradient_fill_cmds.rs b/crates/engine-core/src/cmd/gradient_fill_cmds.rs similarity index 100% rename from crates/engine/src/cmd/gradient_fill_cmds.rs rename to crates/engine-core/src/cmd/gradient_fill_cmds.rs diff --git a/crates/engine/src/cmd/gradient_fill_cmds/tests.rs b/crates/engine-core/src/cmd/gradient_fill_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/gradient_fill_cmds/tests.rs rename to crates/engine-core/src/cmd/gradient_fill_cmds/tests.rs index 12db3308d3..32bdc92d66 100644 --- a/crates/engine/src/cmd/gradient_fill_cmds/tests.rs +++ b/crates/engine-core/src/cmd/gradient_fill_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use crate::Session; fn session(depth: u32, background: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": depth, "background": background})).unwrap(); s } @@ -249,7 +249,7 @@ fn classic_gradient_still_paints_pixels() { #[test] fn commands_fail_gracefully() { - let mut empty = Session::new(); + let mut empty = crate::session(); for id in [CREATE, SET, STOP, GET] { assert!(empty.execute(id, json!({"from": [0, 0], "to": [1, 1]})).is_err(), "{id} without a document"); } @@ -334,7 +334,7 @@ fn a_clamped_handle_drag_leaves_the_other_handle_alone() { for style in STYLES { for (from, to, short, short_start) in [([14.0, 16.0], [34.0, 16.0], [15.0, 16.0], [33.0, 16.0]), ([24.0, 6.0], [24.0, 26.0], [24.0, 7.0], [24.0, 25.0])] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 480, "height": 320})).unwrap(); s.execute(CREATE, json!({"from": from, "to": to, "style": style})).unwrap(); // End dragged almost onto the start: below 1 % on this larger canvas. @@ -345,7 +345,7 @@ fn a_clamped_handle_drag_leaves_the_other_handle_alone() { let e = pt(&g, "to"); assert!((e[0] - from[0]) * (short[0] - from[0]) >= 0.0 && (e[1] - from[1]) * (short[1] - from[1]) >= 0.0, "{style}: {e:?}"); // And the same for the start handle. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 480, "height": 320})).unwrap(); s.execute(CREATE, json!({"from": from, "to": to, "style": style})).unwrap(); let g = s.execute(SET, json!({"from": short_start})).unwrap(); diff --git a/crates/engine/src/cmd/gradient_fill_selection_tests.rs b/crates/engine-core/src/cmd/gradient_fill_selection_tests.rs similarity index 99% rename from crates/engine/src/cmd/gradient_fill_selection_tests.rs rename to crates/engine-core/src/cmd/gradient_fill_selection_tests.rs index 838b216397..86a314cede 100644 --- a/crates/engine/src/cmd/gradient_fill_selection_tests.rs +++ b/crates/engine-core/src/cmd/gradient_fill_selection_tests.rs @@ -10,7 +10,7 @@ use crate::Session; /// Creates an 800x600 white-background test session at the given bit depth. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "depth": depth, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/group_view_cmds.rs b/crates/engine-core/src/cmd/group_view_cmds.rs similarity index 98% rename from crates/engine/src/cmd/group_view_cmds.rs rename to crates/engine-core/src/cmd/group_view_cmds.rs index 6e004dbedc..38aca76f9b 100644 --- a/crates/engine/src/cmd/group_view_cmds.rs +++ b/crates/engine-core/src/cmd/group_view_cmds.rs @@ -98,7 +98,7 @@ mod tests { use super::*; fn session() -> (Session, u64, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({"name": "deep"})).unwrap(); let inner = s.execute("layer.groupLayers", json!({"name": "inner"})).unwrap()["layer"].as_u64().unwrap(); @@ -157,7 +157,7 @@ mod tests { ] { assert!(s.execute(ID, p.clone()).is_err(), "{p}"); } - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute(ID, json!({})).is_err()); empty.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert!(empty.execute(ID, json!({"all": true})).is_err(), "no groups: disabled"); diff --git a/crates/engine/src/cmd/history_brush_format_mismatch_tests.rs b/crates/engine-core/src/cmd/history_brush_format_mismatch_tests.rs similarity index 99% rename from crates/engine/src/cmd/history_brush_format_mismatch_tests.rs rename to crates/engine-core/src/cmd/history_brush_format_mismatch_tests.rs index 55f4d6cce1..1f39e60af4 100644 --- a/crates/engine/src/cmd/history_brush_format_mismatch_tests.rs +++ b/crates/engine-core/src/cmd/history_brush_format_mismatch_tests.rs @@ -12,7 +12,7 @@ const DEPTH: &str = "Could not use the history brush because the current bit dep /// Rows Open (white), Fill (red): row 1 is the red state. fn session(mode: &str, depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 16, "mode": mode, "depth": depth, "background": "white"})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s diff --git a/crates/engine/src/cmd/history_cmds.rs b/crates/engine-core/src/cmd/history_cmds.rs similarity index 99% rename from crates/engine/src/cmd/history_cmds.rs rename to crates/engine-core/src/cmd/history_cmds.rs index 0a5c2f186a..5654ecff2a 100644 --- a/crates/engine/src/cmd/history_cmds.rs +++ b/crates/engine-core/src/cmd/history_cmds.rs @@ -332,7 +332,7 @@ mod tests { /// A document with three steps after Open: entries Open, New Layer, Fill, Fill. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); @@ -385,7 +385,7 @@ mod tests { #[test] fn delete_state_refuses_the_oldest_state_and_bad_params() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("history.deleteState", json!({})).is_err(), "no document"); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert!(!s.is_enabled("history.deleteState"), "only the opening state"); @@ -468,7 +468,7 @@ mod tests { assert_eq!(entries(&s), history_before, "Undo restores the cleared states"); assert_eq!(snapshots(&s), kept_snapshots, "Undo also preserves every snapshot"); assert_eq!(top_pixel(&s), pixel); - assert!(Session::new().execute("history.clear", json!({})).is_err(), "no document"); + assert!(crate::session().execute("history.clear", json!({})).is_err(), "no document"); } #[test] @@ -575,7 +575,7 @@ mod tests { /// History has dropped its oldest states. #[test] fn a_document_starts_with_a_first_snapshot_of_itself() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); let name = s.active().unwrap().doc.name.clone(); assert_eq!(snapshots(&s), json!([{"id": 0, "name": name}])); @@ -591,7 +591,7 @@ mod tests { #[test] fn snapshot_commands_refuse_bad_params() { - let mut s = Session::new(); + let mut s = crate::session(); for (cmd, p) in [ ("history.newSnapshot", json!({})), ("history.selectSnapshot", json!({"snapshot": 1})), @@ -628,7 +628,7 @@ mod tests { #[test] fn new_document_refuses_bad_params() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("history.newDocument", json!({})).is_err(), "no document"); let mut s = session(); for p in [json!({"state": -1}), json!({"state": 99}), json!({"state": "x"}), json!({"state": f64::NAN.to_string()})] { diff --git a/crates/engine/src/cmd/history_menu_cmds.rs b/crates/engine-core/src/cmd/history_menu_cmds.rs similarity index 99% rename from crates/engine/src/cmd/history_menu_cmds.rs rename to crates/engine-core/src/cmd/history_menu_cmds.rs index 1d16a00860..b36bb2f5e6 100644 --- a/crates/engine/src/cmd/history_menu_cmds.rs +++ b/crates/engine-core/src/cmd/history_menu_cmds.rs @@ -106,7 +106,7 @@ mod tests { /// A document with three steps after Open: entries Open, New Layer, Fill, Fill. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); @@ -230,7 +230,7 @@ mod tests { #[test] fn history_menu_commands_refuse_without_a_document_and_ignore_odd_params() { - let mut s = Session::new(); + let mut s = crate::session(); for id in ["history.stepForward", "history.stepBackward", "history.clear"] { assert!(!s.is_enabled(id), "{id}"); assert!(s.execute(id, json!({})).is_err(), "{id} without a document"); diff --git a/crates/engine/src/cmd/history_options_cmds.rs b/crates/engine-core/src/cmd/history_options_cmds.rs similarity index 98% rename from crates/engine/src/cmd/history_options_cmds.rs rename to crates/engine-core/src/cmd/history_options_cmds.rs index 00c2679d1b..034726e4d8 100644 --- a/crates/engine/src/cmd/history_options_cmds.rs +++ b/crates/engine-core/src/cmd/history_options_cmds.rs @@ -210,7 +210,7 @@ mod tests { /// A document with a layer above the background: entries Open, New Layer. fn doc() -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let id = s.active().unwrap().active_layer.unwrap().0; @@ -219,7 +219,7 @@ mod tests { #[test] fn defaults_match_photoshop_and_round_trip_through_prefs() { - let mut s = Session::new(); + let mut s = crate::session(); let defaults = json!({ "automaticallyCreateFirstSnapshot": true, "automaticallyCreateNewSnapshotWhenSaving": false, @@ -238,22 +238,22 @@ mod tests { assert_eq!(s.execute("prefs.get", json!({"path": "historyOptions.allowNonLinearHistory"})).unwrap(), json!(true)); // Saved and restored with the other preferences. let saved = s.prefs_to_json(); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&saved).unwrap(); assert_eq!(current(&t), r); // prefs.set and prefs.reset reach them too. t.execute("prefs.set", json!({"path": "historyOptions.allowNonLinearHistory", "value": false})).unwrap(); assert_eq!(t.execute(CMD, Value::Null).unwrap()["allowNonLinearHistory"], json!(false)); t.execute("prefs.reset", json!({"path": "historyOptions"})).unwrap(); - assert_eq!(current(&t), current(&Session::new())); + assert_eq!(current(&t), current(&crate::session())); // Older preference files without the section load with the defaults. t.load_prefs_json("{}").unwrap(); - assert_eq!(current(&t), current(&Session::new())); + assert_eq!(current(&t), current(&crate::session())); } #[test] fn bad_params_are_refused_and_change_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); let before = current(&s); for p in [ json!({"allowNonLinearHistory": "yes"}), @@ -407,7 +407,7 @@ mod tests { #[test] fn non_linear_history_keeps_later_states_and_delete_removes_only_one() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute(CMD, json!({"allowNonLinearHistory": true})).unwrap(); for c in ["#ff0000", "#00ff00", "#0000ff"] { @@ -454,7 +454,7 @@ mod tests { /// PNG bytes of a small image, to open. fn png() -> Vec { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 6})).unwrap(); crate::file_cmds::encode(&s.active().unwrap().doc, "a.png", None::).unwrap().0 } @@ -464,7 +464,7 @@ mod tests { /// camera's first snapshot is still "Snapshot 1". #[test] fn first_snapshot_follows_the_option_on_new_and_open() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let name = s.active().unwrap().doc.name.clone(); assert_eq!(snapshot_names(&s), [name]); @@ -489,7 +489,7 @@ mod tests { /// history state. #[test] fn a_save_adds_a_snapshot_only_with_the_option() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert_eq!(snapshot_on_save(&mut s), None); assert_eq!(snapshot_names(&s).len(), 1, "only the first snapshot"); @@ -516,7 +516,7 @@ mod tests { assert_eq!(s.active().unwrap().doc.layers[0].surface().unwrap().rgba(1, 1), [1.0, 0.0, 0.0, 1.0]); assert!(second > id); // No document: nothing to do, no panic. - let mut empty = Session::new(); + let mut empty = crate::session(); empty.execute(CMD, json!({"automaticallyCreateNewSnapshotWhenSaving": true})).unwrap(); assert_eq!(snapshot_on_save(&mut empty), None); } @@ -525,7 +525,7 @@ mod tests { /// change, or deleting the previous save's snapshot, makes the next save add one again. #[test] fn saving_an_unchanged_document_adds_no_duplicate_snapshot() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute(CMD, json!({"automaticallyCreateNewSnapshotWhenSaving": true})).unwrap(); let first = snapshot_on_save(&mut s).unwrap(); @@ -547,7 +547,7 @@ mod tests { #[test] fn show_new_snapshot_dialog_reads_the_option() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!show_new_snapshot_dialog(&s)); s.execute("prefs.set", json!({"path": "historyOptions.showNewSnapshotDialogByDefault", "value": true})).unwrap(); assert!(show_new_snapshot_dialog(&s)); @@ -559,7 +559,7 @@ mod tests { /// hides the layer again, and Redo shows it (the step changed it, #3535's rule). #[test] fn selecting_a_snapshot_undoes_its_own_visibility_change() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let id = s.active().unwrap().active_layer.unwrap().0; // Red, not the white document as opened (`red` only reads the red channel). @@ -586,7 +586,7 @@ mod tests { /// nothing to delete there. #[test] fn non_linear_delete_is_enabled_while_the_oldest_state_is_current() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); for c in ["#ff0000", "#00ff00"] { s.execute("edit.fill", json!({"color": c})).unwrap(); @@ -610,7 +610,7 @@ mod tests { /// (clean) document stays clean; deleting the current state steps back and modifies it. #[test] fn non_linear_delete_of_another_state_keeps_a_clean_document_clean() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute(CMD, json!({"allowNonLinearHistory": true})).unwrap(); for c in ["#ff0000", "#00ff00", "#0000ff", "#808080"] { @@ -660,7 +660,7 @@ mod tests { /// still refuses one past the current state. #[test] fn non_linear_delete_removes_a_later_state() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); for c in ["#ff0000", "#00ff00", "#0000ff"] { s.execute("edit.fill", json!({"color": c})).unwrap(); diff --git a/crates/engine/src/cmd/history_select_cmds.rs b/crates/engine-core/src/cmd/history_select_cmds.rs similarity index 99% rename from crates/engine/src/cmd/history_select_cmds.rs rename to crates/engine-core/src/cmd/history_select_cmds.rs index f6b7de6fb5..500fa88c27 100644 --- a/crates/engine/src/cmd/history_select_cmds.rs +++ b/crates/engine-core/src/cmd/history_select_cmds.rs @@ -110,7 +110,7 @@ mod tests { /// A document with four steps after Open, each targeting different layers. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); @@ -174,7 +174,7 @@ mod tests { #[test] fn a_jump_reports_only_the_pixels_it_changed() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); @@ -238,7 +238,7 @@ mod tests { #[test] fn select_state_refuses_bad_params_and_changes_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute(CMD, json!({"state": 0})).is_err(), "no document"); assert!(!s.is_enabled(CMD)); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); diff --git a/crates/engine/src/cmd/history_source_cmds.rs b/crates/engine-core/src/cmd/history_source_cmds.rs similarity index 99% rename from crates/engine/src/cmd/history_source_cmds.rs rename to crates/engine-core/src/cmd/history_source_cmds.rs index d377d1687e..179bd39129 100644 --- a/crates/engine/src/cmd/history_source_cmds.rs +++ b/crates/engine-core/src/cmd/history_source_cmds.rs @@ -196,7 +196,7 @@ mod tests { /// A white 8×8 document filled red, then green: rows Open, Fill (red), Fill (green). fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": 16, "background": "white"})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s.execute("edit.fill", json!({"color": "#00ff00"})).unwrap(); @@ -391,7 +391,7 @@ mod tests { #[test] fn bad_params_and_no_document_are_errors() { - assert!(matches!(Session::new().execute(CMD, json!({"state": 0})), Err(EngineError::NoDocument | EngineError::Disabled(..)))); + assert!(matches!(crate::session().execute(CMD, json!({"state": 0})), Err(EngineError::NoDocument | EngineError::Disabled(..)))); let mut s = session(); for p in [ json!({}), diff --git a/crates/engine/src/cmd/image_cmds.rs b/crates/engine-core/src/cmd/image_cmds.rs similarity index 100% rename from crates/engine/src/cmd/image_cmds.rs rename to crates/engine-core/src/cmd/image_cmds.rs diff --git a/crates/engine/src/cmd/image_cmds/canvas_size_center_offset_tests.rs b/crates/engine-core/src/cmd/image_cmds/canvas_size_center_offset_tests.rs similarity index 99% rename from crates/engine/src/cmd/image_cmds/canvas_size_center_offset_tests.rs rename to crates/engine-core/src/cmd/image_cmds/canvas_size_center_offset_tests.rs index 8381818864..e37e9caf38 100644 --- a/crates/engine/src/cmd/image_cmds/canvas_size_center_offset_tests.rs +++ b/crates/engine-core/src/cmd/image_cmds/canvas_size_center_offset_tests.rs @@ -8,7 +8,7 @@ use crate::Session; /// The issue's document: 400 x 300 px with a 50 x 50 layer at 175,125. fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 175, "y": 125, "width": 50, "height": 50})).unwrap(); diff --git a/crates/engine/src/cmd/image_cmds/canvas_size_noop_history_tests.rs b/crates/engine-core/src/cmd/image_cmds/canvas_size_noop_history_tests.rs similarity index 98% rename from crates/engine/src/cmd/image_cmds/canvas_size_noop_history_tests.rs rename to crates/engine-core/src/cmd/image_cmds/canvas_size_noop_history_tests.rs index 2fe52589c2..a31478e313 100644 --- a/crates/engine/src/cmd/image_cmds/canvas_size_noop_history_tests.rs +++ b/crates/engine-core/src/cmd/image_cmds/canvas_size_noop_history_tests.rs @@ -10,7 +10,7 @@ use crate::Session; /// The issue's document: 400 x 300 px with a Background and a layer of pixels. fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { diff --git a/crates/engine/src/cmd/image_cmds/canvas_size_selection_tests.rs b/crates/engine-core/src/cmd/image_cmds/canvas_size_selection_tests.rs similarity index 99% rename from crates/engine/src/cmd/image_cmds/canvas_size_selection_tests.rs rename to crates/engine-core/src/cmd/image_cmds/canvas_size_selection_tests.rs index 6e300bd173..682c874620 100644 --- a/crates/engine/src/cmd/image_cmds/canvas_size_selection_tests.rs +++ b/crates/engine-core/src/cmd/image_cmds/canvas_size_selection_tests.rs @@ -10,7 +10,7 @@ use crate::Session; /// 400 x 300 px with a 100 x 100 selection at (50,50). fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("select.rect", json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap(); s diff --git a/crates/engine/src/cmd/image_cmds/duplicate_selection_tests.rs b/crates/engine-core/src/cmd/image_cmds/duplicate_selection_tests.rs similarity index 98% rename from crates/engine/src/cmd/image_cmds/duplicate_selection_tests.rs rename to crates/engine-core/src/cmd/image_cmds/duplicate_selection_tests.rs index 49aff37d7b..28c1f6de14 100644 --- a/crates/engine/src/cmd/image_cmds/duplicate_selection_tests.rs +++ b/crates/engine-core/src/cmd/image_cmds/duplicate_selection_tests.rs @@ -11,7 +11,7 @@ use crate::Session; /// A source at `depth` with the issue's selection (10,10-110,60), one alpha channel saved from /// it, a guide each way and a saved path. fn source(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 100, "height": 50})).unwrap(); diff --git a/crates/engine/src/cmd/image_cmds/tests.rs b/crates/engine-core/src/cmd/image_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/image_cmds/tests.rs rename to crates/engine-core/src/cmd/image_cmds/tests.rs index 88da8f65c1..32da9a3aa4 100644 --- a/crates/engine/src/cmd/image_cmds/tests.rs +++ b/crates/engine-core/src/cmd/image_cmds/tests.rs @@ -54,7 +54,7 @@ fn crop_rejects_origins_that_cannot_move_to_zero() { } fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -159,7 +159,7 @@ fn image_size_scales_everything() { /// #6019: Image Size on an Indexed Color document makes no colours the colour table doesn't have. #[test] fn image_size_resamples_indexed_color_with_nearest_neighbor() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 1})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s.execute("select.rect", json!({"x": 1, "y": 0, "width": 1, "height": 1})).unwrap(); @@ -185,7 +185,7 @@ fn image_size_resamples_indexed_color_with_nearest_neighbor() { /// change of resolution only, and an ordinary resize, still work. #[test] fn image_size_refuses_a_raster_past_the_budget() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); let before = (doc(&s).size, s.active().unwrap().history.past_len()); let err = s.execute("image.imageSize", json!({"width": 300_000, "height": 300_000})).unwrap_err().to_string(); @@ -202,7 +202,7 @@ fn image_size_keeps_canvas_edges_opaque() { for (w, resample) in [(60, "bicubic"), (41, "lanczos"), (15, "bilinear"), (77, "preserveDetails"), (21, "bicubicSharper"), (47, "automatic"), (9, "bicubicAutomatic")] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 30, "height": 20, "depth": depth, "background": "#336699"})).unwrap(); s.execute("select.all", json!({})).unwrap(); // The Crop tool's W x H x Resolution mode still resamples the selection with the @@ -288,7 +288,7 @@ fn image_size_refuses_a_resolution_out_of_range() { #[test] fn image_size_with_a_new_resolution_scales_type_with_the_pixels_only() { for (params, k) in [(json!({"width": 200, "height": 200, "resolution": 144}), 2), (json!({"resolution": 144, "resample": "none"}), 1)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("type.create", json!({"x": 10, "y": 50, "text": "Hi", "size": 12})).unwrap(); let height = |s: &Session| doc(s).layers.last().unwrap().surface().unwrap().content_bounds().height(); @@ -313,7 +313,7 @@ fn image_size_with_a_new_resolution_scales_type_with_the_pixels_only() { fn image_size_keeps_the_pixels_of_type_in_a_missing_font() { for depth in [8, 16, 32] { for (font, kept) in [("No Such Font 8860", true), ("", false)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100, "depth": depth})).unwrap(); let cache = s .edit("type", |doc, active| { @@ -340,7 +340,7 @@ fn image_size_keeps_the_pixels_of_type_in_a_missing_font() { fn image_size_reports_the_size_it_applied() { // #1815: every path reports the document's size afterwards, at every depth. for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); let size = |s: &Session| json!({"width": doc(s).size.width, "height": doc(s).size.height}); for p in [ @@ -361,7 +361,7 @@ fn image_size_reports_the_size_it_applied() { /// #1114: nearest neighbor reduction keeps source values without averaging. #[test] fn nearest_neighbor_reduction_keeps_source_values() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("tools.setColors", json!({"foreground": "#000000", "background": "#ffffff"})).unwrap(); for y in 0..8 { @@ -416,19 +416,19 @@ fn canvas_size_anchor_offsets_and_rejects_unlisted() { ("bottomRight", [36, 32]), ]; for (anchor, off) in expected { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "background": "white"})).unwrap(); let r = s.execute("image.canvasSize", json!({"width": 100, "height": 80, "anchor": anchor})).unwrap(); assert_eq!(r["offset"], json!(off), "anchor {anchor}"); } // An omitted anchor still defaults to center. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "background": "white"})).unwrap(); assert_eq!(s.execute("image.canvasSize", json!({"width": 100, "height": 80})).unwrap()["offset"], json!([18, 16])); // A misspelling or unknown value is a BadParams error naming `anchor`, never an anchor // between two of the nine (the old independent-axis matching produced top-centre etc.). for anchor in ["topleft", "TopLeft", "TOPLEFT", "bottomleft", "bottomright", "middle", "", "NOPE"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "background": "white"})).unwrap(); let err = s.execute("image.canvasSize", json!({"width": 100, "height": 80, "anchor": anchor})).unwrap_err(); assert!(matches!(err, EngineError::BadParams { .. }), "anchor {anchor:?} must be rejected, got {err:?}"); @@ -564,14 +564,14 @@ fn crop_rect_edge_cases_never_fall_back_to_the_selection() { #[test] fn crop_extension_fills_the_background_with_the_background_colour() { - let mut shrink = Session::new(); + let mut shrink = crate::session(); shrink.execute("file.new", json!({"width": 16, "height": 16, "background": "#ff0000"})).unwrap(); shrink.execute("image.crop", json!({"x": 2, "y": 0, "width": 12, "height": 16})).unwrap(); let layer = &doc(&shrink).layers[0]; assert_eq!(layer.name, "Background", "a shrink-only crop keeps the Background"); assert!(layer.locks.transparency && layer.locks.position); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "#ff0000"})).unwrap(); s.tools.background = [0.0, 1.0, 0.0, 1.0]; s.execute("image.crop", json!({"x": -4, "y": 0, "width": 20, "height": 16})).unwrap(); @@ -594,7 +594,7 @@ fn crop_extension_fills_the_background_with_the_background_colour() { assert_eq!(layer.surface().unwrap().content_bounds(), Rect::new(0, 0, 16, 16), "undo removes the filled border"); // A normal layer gets transparent pixels in the added area. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "#ff0000"})).unwrap(); s.execute("layer.new.layerFromBackground", json!({})).unwrap(); s.execute("image.crop", json!({"x": -4, "y": 0, "width": 20, "height": 16})).unwrap(); @@ -674,7 +674,7 @@ fn extending_the_canvas_keeps_the_backgrounds_hidden_pixels() { assert!(doc(s).background().is_some()); s.tools.background = [0.0, 0.0, 0.0, 1.0]; }; - let mut s = Session::new(); + let mut s = crate::session(); hidden(&mut s); s.execute("image.revealAll", json!({})).unwrap(); let surf = doc(&s).background().unwrap().surface().unwrap(); @@ -683,7 +683,7 @@ fn extending_the_canvas_keeps_the_backgrounds_hidden_pixels() { assert_eq!(surf.rgba(80, 50), [1.0, 1.0, 1.0, 1.0], "{depth}-bit"); // Canvas Size wider than the hidden pixels: they show, the rest takes the colour. - let mut s = Session::new(); + let mut s = crate::session(); hidden(&mut s); s.execute("image.canvasSize", json!({"width": 120, "height": 100, "anchor": "right"})).unwrap(); let surf = doc(&s).background().unwrap().surface().unwrap(); @@ -709,7 +709,7 @@ fn an_alpha_less_background_extension_takes_the_colour() { /// A document (`mode`, `depth`) with a white Background and a layer holding a red pixel at /// (12, 8) and a blue one at (30, 3). fn marked(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": mode, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); for (x, y, c) in [(12, 8, "#ff0000"), (30, 3, "#0000ff")] { @@ -804,7 +804,7 @@ fn turned_crop_deleting_pixels_matches_turning_the_whole_canvas() { let scale = w / 140; let pixels = || (0..h).flat_map(|y| (0..w).map(move |x| (x, y))); let mut sessions = [true, false].map(|delete| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -925,7 +925,7 @@ fn crop_refuses_a_canvas_side_past_the_new_document_limit() { #[test] fn crop_to_a_target_size_and_resolution_is_one_step() { for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "resolution": 72, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -972,7 +972,7 @@ fn crop_target_resamples_after_a_turned_crop_and_resolution_alone_keeps_the_pixe /// Nearest Neighbor, so no pixel gets a blend that isn't in the colour table. #[test] fn crop_target_resamples_indexed_color_with_nearest_neighbor() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 1})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s.execute("select.rect", json!({"x": 1, "y": 0, "width": 1, "height": 1})).unwrap(); @@ -1008,7 +1008,7 @@ fn crop_target_accepts_whole_number_floats() { /// allocating, like a target size past the budget. #[test] fn crop_target_budgets_the_hidden_pixels_it_resamples() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2000, "height": 2000})).unwrap(); s.execute("paint.setSymmetry", json!({"mode": "vertical", "center": [500, 700]})).unwrap(); let symmetry = s.active().unwrap().symmetry.clone(); @@ -1040,7 +1040,7 @@ fn crop_target_budgets_the_hidden_pixels_it_resamples() { /// crop to 10 px, 20000 px (400 MP, within the budget) scales the hidden 100 px Background x2000. #[test] fn image_size_budgets_the_hidden_pixels_it_resamples() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("image.crop", json!({"x": 0, "y": 0, "width": 10, "height": 10, "deleteCroppedPixels": false})).unwrap(); let past = s.active().unwrap().history.past_len(); @@ -1058,7 +1058,7 @@ fn image_size_budgets_the_hidden_pixels_it_resamples() { /// crop, so the refusal doesn't send the user to an option that can't clear it. #[test] fn hidden_resample_budget_names_what_delete_cropped_pixels_keeps() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.edit("channel", |doc, _| { let fmt = photocraft_color::PixelFormat::new(ColorMode::Grayscale, doc.pixel_format().sample, false); @@ -1129,7 +1129,7 @@ fn trim_transparent_drops_alpha_that_rounds_to_zero_at_the_depth() { // (the stored image is transparent there), so Trim keeps only the opaque square. A 1/255 // pixel is 0.4 × 257 ≈ 103 steps at 16 bits and any alpha is content at 32 bits: kept. for (depth, faint, keeps) in [(8, 1.0 / 255.0, false), (16, 1.0 / 65535.0, false), (16, 1.0 / 255.0, true), (32, 1.0 / 65535.0, true)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100, "depth": depth, "background": "transparent"})).unwrap(); s.edit("paint", |doc, _| { let surf = doc.layers[0].surface_mut().unwrap(); @@ -1149,7 +1149,7 @@ fn trim_transparent_drops_alpha_that_rounds_to_zero_at_the_depth() { fn thirty_two_bit_holds_linear_light() { // Photoshop 27.11: an 8-bit sRGB grey 128 becomes 0.2159 in 32 bits (and 32 → 0.0144), // and comes back unchanged; alpha keeps its value. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 1, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -1174,7 +1174,7 @@ fn thirty_two_bit_holds_linear_light() { fn grayscale_conversion_matches_photoshop() { // Photoshop 27.11, default Color Settings (working gray Dot Gain 20 %): Image > Mode > // Grayscale turns sRGB 64 / 128 / 192 grey and pure red into 46 / 105 / 177 / 107. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 1, "background": "white"})).unwrap(); s.edit("paint", |doc, _| { let l = doc.layers.first_mut().unwrap(); @@ -1227,7 +1227,7 @@ fn merged_duplicate_is_a_background_only_when_the_source_has_one() { s.execute("image.duplicate", json!({"mergedOnly": true})).unwrap(); let d = doc(&s); assert!(d.is_background(d.layers[0].id), "source has a Background: the merged copy is one"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "transparent"})).unwrap(); s.execute("image.duplicate", json!({"mergedOnly": true})).unwrap(); let d = doc(&s); @@ -1253,7 +1253,7 @@ fn duplicate_document() { #[cfg(target_pointer_width = "64")] #[test] fn hidden_resample_budget_counts_the_image_between_bicubic_passes() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); let mut d = doc(&s).clone(); let bg = d.background_mut().unwrap().surface_mut().unwrap(); @@ -1265,7 +1265,7 @@ fn hidden_resample_budget_counts_the_image_between_bicubic_passes() { #[test] fn trim_and_duplicate_merged_on_too_large_document_fail_gracefully_without_panic() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40000, "height": 30000, "background": "transparent"})).unwrap(); let initial_layers = doc(&s).layers.len(); let initial_bounds = doc(&s).bounds(); diff --git a/crates/engine/src/cmd/image_size_drops_selection_tests.rs b/crates/engine-core/src/cmd/image_size_drops_selection_tests.rs similarity index 98% rename from crates/engine/src/cmd/image_size_drops_selection_tests.rs rename to crates/engine-core/src/cmd/image_size_drops_selection_tests.rs index 825331a1a0..1811e630e6 100644 --- a/crates/engine/src/cmd/image_size_drops_selection_tests.rs +++ b/crates/engine-core/src/cmd/image_size_drops_selection_tests.rs @@ -9,7 +9,7 @@ use crate::Session; /// The issue's document: 400 x 300 px with a 10,10 50 x 50 selection. fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap(); s diff --git a/crates/engine/src/cmd/layer_copy_cmds.rs b/crates/engine-core/src/cmd/layer_copy_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_copy_cmds.rs rename to crates/engine-core/src/cmd/layer_copy_cmds.rs diff --git a/crates/engine/src/cmd/layer_copy_cmds/tests.rs b/crates/engine-core/src/cmd/layer_copy_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/layer_copy_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_copy_cmds/tests.rs index 20d9d7d0e5..5d84f9661d 100644 --- a/crates/engine/src/cmd/layer_copy_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_copy_cmds/tests.rs @@ -9,7 +9,7 @@ use crate::Session; /// Document 0 (`w`×`h`, `depth`) with a red 10×10 square at (4, 6) on layer "paint" above the /// Background, and document 1 (60×50, 8-bit RGB). Document 0 is active. fn two_docs(w: u32, h: u32, depth: u32) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); let paint = LayerId(s.execute("layer.new.layer", json!({"name": "paint"})).unwrap()["layer"].as_u64().unwrap()); s.execute("select.rect", json!({"x": 4, "y": 6, "width": 10, "height": 10})).unwrap(); @@ -205,7 +205,7 @@ fn bad_params_and_states_fail_without_changing_anything() { #[test] fn copying_linked_layers_does_not_join_an_unrelated_destination_group() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let src_a = LayerId(s.execute("layer.new.layer", json!({"name": "Source A"})).unwrap()["layer"].as_u64().unwrap()); let src_b = LayerId(s.execute("layer.new.layer", json!({"name": "Source B"})).unwrap()["layer"].as_u64().unwrap()); @@ -245,7 +245,7 @@ fn copying_linked_layers_does_not_join_an_unrelated_destination_group() { #[test] fn copied_link_groups_are_distinct_from_each_other_and_destination() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let a = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); let b = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); @@ -267,7 +267,7 @@ fn copied_link_groups_are_distinct_from_each_other_and_destination() { /// One painted layer, `depth`-bit RGB, as the only layer above the Background. fn one_doc(depth: u32) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth})).unwrap(); let paint = LayerId(s.execute("layer.new.layer", json!({"name": "paint"})).unwrap()["layer"].as_u64().unwrap()); s.execute("select.rect", json!({"x": 4, "y": 6, "width": 10, "height": 10})).unwrap(); @@ -436,7 +436,7 @@ fn ink(s: &Session, i: usize, id: LayerId) -> (Rect, f64) { /// Document 0 at `from` ppi with a 24 pt "H" (leading 30 pt, baseline shift 2 pt, first-line /// indent 6 pt) and document 1 at `to` ppi; the type layer is selected in document 0. fn type_docs(from: u32, to: u32) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200, "resolution": from})).unwrap(); let t = LayerId( s.execute("type.create", json!({"text": "H", "size": 24, "leading": 30, "baselineShift": 2, "x": 128, "y": 100})).unwrap()["layer"].as_u64().unwrap(), @@ -505,7 +505,7 @@ fn pasted_type_takes_the_destinations_point_size_and_keeps_its_pixels() { /// Paragraph text keeps its box (in pixels) and its wrapping: only the point sizes change. #[test] fn copied_paragraph_type_keeps_its_box() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200, "resolution": 72})).unwrap(); let t = LayerId(s.execute("type.create", json!({"text": "Hello wrapping world", "size": 24, "box": [20, 20, 120, 150]})).unwrap()["layer"].as_u64().unwrap()); @@ -551,7 +551,7 @@ fn retargeting_type_survives_bad_resolutions() { /// Document 0 at 72 ppi with "Hello" in Paragraph Style 1 (24 pt) and "He" also in Character /// Style 1 (24 pt, underlined); document 1 at 300 ppi, its own styles made by `dest`. fn styled_type_docs(dest: impl FnOnce(&mut Session)) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200, "resolution": 72})).unwrap(); let t = s.execute("type.create", json!({"text": "Hello", "size": 12, "x": 100, "y": 100})).unwrap()["layer"].as_u64().unwrap(); s.execute("type.paragraphStyle.new", json!({"attrs": {"size": 24}, "fromSelection": false, "apply": true, "layer": t})).unwrap(); @@ -641,7 +641,7 @@ fn type_duplicated_to_a_new_document_keeps_its_styles() { /// Document 0 (RGB, 72 ppi) with "Hello" whose "He" is in Character Style 1 (red); document 1 /// (CMYK, 72 ppi). The type layer is selected in document 0. fn red_styled_type_docs() -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100, "resolution": 72})).unwrap(); let t = s.execute("type.create", json!({"text": "Hello", "size": 12, "x": 20, "y": 50})).unwrap()["layer"].as_u64().unwrap(); s.execute("type.characterStyle.new", json!({"attrs": {"color": "#ff0000"}, "fromSelection": false, "apply": true, "layer": t, "range": [0, 2]})).unwrap(); @@ -692,7 +692,7 @@ fn copied_type_styles_convert_their_colours_with_the_type() { /// size from it has no override there, and Clear Override leaves it as it was. #[test] fn type_duplicated_to_a_new_document_keeps_the_sources_basic_paragraph() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); let t = LayerId(s.execute("type.create", json!({"text": "Hello", "size": 12, "x": 20, "y": 50})).unwrap()["layer"].as_u64().unwrap()); s.execute("type.paragraphStyle.set", json!({"id": 0, "attrs": {"size": 30}})).unwrap(); diff --git a/crates/engine/src/cmd/layer_css_cmds.rs b/crates/engine-core/src/cmd/layer_css_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_css_cmds.rs rename to crates/engine-core/src/cmd/layer_css_cmds.rs diff --git a/crates/engine/src/cmd/layer_css_cmds/tests.rs b/crates/engine-core/src/cmd/layer_css_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/layer_css_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_css_cmds/tests.rs index 368b965874..ef2904a73d 100644 --- a/crates/engine/src/cmd/layer_css_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_css_cmds/tests.rs @@ -4,7 +4,7 @@ use photocraft_geom::Rect; /// A 400 × 300 document at 72 ppi with a 200 × 140 pixel layer at (100, 80) named `name`. fn session(name: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("layer.new.layer", json!({"name": name})).unwrap(); s.edit("paint", |doc, active| { @@ -80,7 +80,7 @@ fn fill_and_type_layers_describe_their_colour_and_font() { /// stack, so the layer is 3 and the group 4 above the Background. #[test] fn a_group_writes_its_box_then_its_layers() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("layer.new.layer", json!({"name": "2nd-Box"})).unwrap(); s.edit("paint", |doc, active| { @@ -230,7 +230,7 @@ fn bad_params_and_layers_without_css_are_errors() { assert!(s.execute(ID, json!([])).is_err()); s.execute("layer.new.group", json!({})).unwrap(); assert!(s.execute(ID, json!({})).unwrap()["css"].as_str().unwrap().contains(" width: 400px;\n"), "an empty group writes its box"); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute(ID, json!({})).is_err(), "no document"); } diff --git a/crates/engine/src/cmd/layer_from_background_name_tests.rs b/crates/engine-core/src/cmd/layer_from_background_name_tests.rs similarity index 97% rename from crates/engine/src/cmd/layer_from_background_name_tests.rs rename to crates/engine-core/src/cmd/layer_from_background_name_tests.rs index 84e4e35f9f..8cd28e8f25 100644 --- a/crates/engine/src/cmd/layer_from_background_name_tests.rs +++ b/crates/engine-core/src/cmd/layer_from_background_name_tests.rs @@ -23,7 +23,7 @@ fn doc(s: &Session) -> &photocraft_doc::Document { /// A document with the white Background `file.new` makes and top-level layers named `others` above /// it, then Layer from Background: the name the converted Background ends with. fn converted_name(others: &[&str]) -> String { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); let bg = doc(&s).layers[0].id; for n in others { @@ -56,7 +56,7 @@ fn a_document_that_is_only_a_background_takes_layer_0() { #[test] fn undo_restores_the_background_with_its_old_name() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); let bg = doc(&s).layers[0].id; s.execute("layer.new.layer", json!({"name": "Layer 0"})).unwrap(); @@ -73,7 +73,7 @@ fn the_other_callers_of_unlock_background_still_name_it_layer_0() { // through `background_to_layer`, which names it "Layer 0" as today, even when that name is // already taken. for (key, value) in [("opacity", json!(0.5)), ("fill", json!(0.5)), ("blend", json!("Multiply"))] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); let bg = doc(&s).layers[0].id; s.execute("layer.new.layer", json!({"name": "Layer 0"})).unwrap(); diff --git a/crates/engine/src/cmd/layer_label_cmds.rs b/crates/engine-core/src/cmd/layer_label_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_label_cmds.rs rename to crates/engine-core/src/cmd/layer_label_cmds.rs diff --git a/crates/engine/src/cmd/layer_label_cmds/tests.rs b/crates/engine-core/src/cmd/layer_label_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/layer_label_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_label_cmds/tests.rs index ffbb3292db..01e2a5c83d 100644 --- a/crates/engine/src/cmd/layer_label_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_label_cmds/tests.rs @@ -3,7 +3,7 @@ use photocraft_color::SampleType; use photocraft_doc::{Layer, LayerContent, LayerId}; fn fixture(depth: u8) -> (Session, [LayerId; 4]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "depth": depth})).unwrap(); let ids = s .edit("Fixture", |doc, _| { @@ -107,7 +107,7 @@ fn layer_color_invalid_params_never_change_the_document_or_history() { let st = s.active().unwrap(); assert_eq!((st.doc.clone(), st.revision, st.history.past_len()), before); } - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(!empty.is_enabled(ID)); assert!(empty.execute(ID, json!({"color": "red"})).is_err()); empty.execute("file.new", json!({"width": 2, "height": 2})).unwrap(); diff --git a/crates/engine/src/cmd/layer_list_cmds.rs b/crates/engine-core/src/cmd/layer_list_cmds.rs similarity index 98% rename from crates/engine/src/cmd/layer_list_cmds.rs rename to crates/engine-core/src/cmd/layer_list_cmds.rs index 6af810f8b2..4eb4ff3125 100644 --- a/crates/engine/src/cmd/layer_list_cmds.rs +++ b/crates/engine-core/src/cmd/layer_list_cmds.rs @@ -108,7 +108,7 @@ mod tests { use super::*; fn session_with_doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); s } @@ -152,7 +152,7 @@ mod tests { #[test] fn bad_params_are_errors_not_panics() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute(ID, json!({})).is_err(), "no document"); let mut s = session_with_doc(); for p in [json!({"flat": "yes"}), json!({"document": -1}), json!({"document": 99}), json!({"document": u64::MAX}), json!({"document": "a"})] { diff --git a/crates/engine/src/cmd/layer_mask_props_cmds.rs b/crates/engine-core/src/cmd/layer_mask_props_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_mask_props_cmds.rs rename to crates/engine-core/src/cmd/layer_mask_props_cmds.rs diff --git a/crates/engine/src/cmd/layer_mask_props_cmds/tests.rs b/crates/engine-core/src/cmd/layer_mask_props_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/layer_mask_props_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_mask_props_cmds/tests.rs index 572990d60f..6d4a1818a0 100644 --- a/crates/engine/src/cmd/layer_mask_props_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_mask_props_cmds/tests.rs @@ -22,7 +22,7 @@ fn session(depth: SampleType, adjustment: bool) -> (Session, LayerId, LayerId) { let id = layer.id; doc.layers.push(layer); doc.selection = Some(Surface::with_default(PixelFormat::GRAY8, &[0.5])); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); (s, id, background_id) } @@ -82,7 +82,7 @@ fn property_commands_update_rendered_edges_without_rewriting_the_mask() { layer.mask = Some(LayerMask { surface, enabled: true, linked: true, density: 1.0, feather: 0.0 }); let id = layer.id; doc.layers.push(layer); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); let render = |s: &Session| photocraft_compose::flatten(&s.active().unwrap().doc); let original = render(&s); @@ -166,7 +166,7 @@ fn malformed_params_missing_masks_and_stale_documents_do_not_edit() { assert!(Arc::ptr_eq(&before, &st.doc), "{params}"); assert_eq!((st.history.entries().len(), st.revision), (count, revision), "{params}"); } - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(!empty.is_enabled(EDIT)); assert!(empty.execute(EDIT, json!({"density": 50})).is_err()); } diff --git a/crates/engine/src/cmd/layer_menu_cmds.rs b/crates/engine-core/src/cmd/layer_menu_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_menu_cmds.rs rename to crates/engine-core/src/cmd/layer_menu_cmds.rs diff --git a/crates/engine/src/cmd/layer_menu_cmds/tests.rs b/crates/engine-core/src/cmd/layer_menu_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/layer_menu_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_menu_cmds/tests.rs index f9c7a1f5d8..6e5177f25e 100644 --- a/crates/engine/src/cmd/layer_menu_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_menu_cmds/tests.rs @@ -3,7 +3,7 @@ use super::*; const DEPTHS: [u64; 3] = [8, 16, 32]; fn session(depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth, "mode": mode, "background": "transparent"})).unwrap(); s } @@ -719,7 +719,7 @@ fn subject(x: i32, y: i32) -> [f32; 4] { #[test] fn from_transparency_and_mask_all_objects_turn_the_background_into_a_layer() { for cmd in ["layer.layerMask.fromTransparency", "layer.maskAllObjects", "layer.layerMask.hideSelection"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); assert!(doc(&s).is_background(id)); @@ -794,7 +794,7 @@ fn load_files_into_stack_as_smart_object_then_median() { std::fs::write(&p, photocraft_io::export(&d, "f.png", &Default::default()).unwrap().bytes).unwrap(); paths.push(p.to_string_lossy().into_owned()); } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.scripts.loadFilesIntoStack", json!({"paths": paths, "createSmartObject": true})).unwrap(); assert_eq!(doc(&s).layers.len(), 1); assert!(matches!(doc(&s).layers[0].content, LayerContent::Smart(_))); @@ -963,6 +963,7 @@ fn decontamination_alpha_keeps_missing_source_alpha_only_inside_bounds() { #[test] fn layer_export_as_names_every_resample_method_in_the_presets_order() { + crate::install().unwrap(); let spec = crate::install::command_specs().iter().find(|c| c.id == "layer.exportAs").unwrap(); let keys: Vec<&str> = crate::export_preset_cmds::RESAMPLE.iter().map(|(key, _)| *key).collect(); assert!(spec.params.contains(&format!("\"resample\":\"{}\"", keys.join("|"))), "{}", spec.params); diff --git a/crates/engine/src/cmd/layer_multi_cmds.rs b/crates/engine-core/src/cmd/layer_multi_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_multi_cmds.rs rename to crates/engine-core/src/cmd/layer_multi_cmds.rs diff --git a/crates/engine/src/cmd/layer_multi_cmds/align.rs b/crates/engine-core/src/cmd/layer_multi_cmds/align.rs similarity index 100% rename from crates/engine/src/cmd/layer_multi_cmds/align.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/align.rs diff --git a/crates/engine/src/cmd/layer_multi_cmds/damage.rs b/crates/engine-core/src/cmd/layer_multi_cmds/damage.rs similarity index 100% rename from crates/engine/src/cmd/layer_multi_cmds/damage.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/damage.rs diff --git a/crates/engine/src/cmd/layer_multi_cmds/layers_panel_parity_tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/layers_panel_parity_tests.rs similarity index 99% rename from crates/engine/src/cmd/layer_multi_cmds/layers_panel_parity_tests.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/layers_panel_parity_tests.rs index f58ea7d6ae..695b85cfb7 100644 --- a/crates/engine/src/cmd/layer_multi_cmds/layers_panel_parity_tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/layers_panel_parity_tests.rs @@ -2,7 +2,7 @@ use super::*; /// A 24×16 document with three layers, "Test 0" to "Test 2", above the Background; the last one is active. fn new_session() -> (Session, Vec) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 16})).unwrap(); let ids = (0..3).map(|n| LayerId(s.execute("layer.new.layer", json!({"name": format!("Test {n}")})).unwrap()["layer"].as_u64().unwrap())).collect(); (s, ids) @@ -85,7 +85,7 @@ fn preview_rejects_invalid_drop_unchanged() { /// layer is a translucent, differently placed rectangle, so the stack order and the clip /// groups both show in the composite. fn clip_stack(spec: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); for (n, name) in spec.split_whitespace().enumerate() { let id = LayerId(s.execute("layer.new.layer", json!({"name": name.trim_end_matches('*')})).unwrap()["layer"].as_u64().unwrap()); diff --git a/crates/engine/src/cmd/layer_multi_cmds/moves.rs b/crates/engine-core/src/cmd/layer_multi_cmds/moves.rs similarity index 100% rename from crates/engine/src/cmd/layer_multi_cmds/moves.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/moves.rs diff --git a/crates/engine/src/cmd/layer_multi_cmds/selection.rs b/crates/engine-core/src/cmd/layer_multi_cmds/selection.rs similarity index 100% rename from crates/engine/src/cmd/layer_multi_cmds/selection.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/selection.rs diff --git a/crates/engine/src/cmd/layer_multi_cmds/structure.rs b/crates/engine-core/src/cmd/layer_multi_cmds/structure.rs similarity index 100% rename from crates/engine/src/cmd/layer_multi_cmds/structure.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/structure.rs diff --git a/crates/engine/src/cmd/layer_multi_cmds/tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/layer_multi_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/tests.rs index b4855c9c06..69918e5b9a 100644 --- a/crates/engine/src/cmd/layer_multi_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tests.rs @@ -5,7 +5,7 @@ use super::*; #[test] fn merge_with_background_preserves_background() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); let bg_id = s.active().unwrap().doc.layers[0].id; assert!(s.active().unwrap().doc.is_background(bg_id)); @@ -22,7 +22,7 @@ fn merge_with_background_preserves_background() { #[test] fn duplicates_are_numbered_not_stacked() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); s.execute("layer.new.layer", json!({"name": "Layer 1"})).unwrap(); let name = |s: &Session| { @@ -44,7 +44,7 @@ fn duplicates_are_numbered_not_stacked() { } fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "depth": depth})).unwrap(); s } @@ -81,7 +81,7 @@ fn damage(s: &Session) -> Option { #[test] fn translate_in_points_follows_the_resolution() { for (res, moved) in [(200, 1), (300, 2), (72, 0)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "resolution": res})).unwrap(); let a = rect_layer(&mut s, Rect::new(10, 10, 20, 20)); s.execute("layer.translate", json!({"dx": 0.36, "dy": -0.36, "units": "pt"})).unwrap(); @@ -1160,7 +1160,7 @@ fn select_linked_layers_preserves_a_linked_active_layer() { #[test] fn select_linked_layers_requires_a_linked_selection() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("layer.selectLinkedLayers")); assert!(s.execute("layer.selectLinkedLayers", json!({})).is_err()); let mut s = session(8); @@ -1321,7 +1321,7 @@ fn bounded_step(s: &mut Session, id: &str, p: serde_json::Value) -> Rect { #[test] fn hiding_a_masked_adjustment_damages_only_its_mask() { for depth in [32, 8] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "depth": depth})).unwrap(); let c = rect_layer(&mut s, Rect::new(50, 50, 700, 500)); s.execute("layer.setProps", json!({"layer": c.0, "opacity": 0.37})).unwrap(); @@ -1343,7 +1343,7 @@ fn hiding_a_masked_adjustment_damages_only_its_mask() { /// everywhere was an adjustment, is bounded by where the layers draw. #[test] fn show_only_with_an_adjustment_is_bounded() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "depth": 8, "background": "transparent"})).unwrap(); let a = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); let b = rect_layer(&mut s, Rect::new(40, 20, 60, 50)); @@ -1369,7 +1369,7 @@ fn bring_forward_damages_only_the_moved_layer() { /// adjustment moving past a layer reaches as far as the layers beneath it at either end. #[test] fn send_backward_undo_and_redo_are_bounded() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "depth": 8, "background": "transparent"})).unwrap(); let _a = rect_layer(&mut s, Rect::new(10, 10, 30, 30)); let b = rect_layer(&mut s, Rect::new(20, 20, 50, 50)); @@ -1865,7 +1865,7 @@ fn duplicate_hide_lock_and_reverse_selected() { /// through both `layer.setProps` and `layer.lockLayers`. #[test] fn locking_pixels_clears_and_holds_off_the_transparency_lock() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let id = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); let locks = |s: &Session| doc(s).layer(id).unwrap().locks; @@ -1988,7 +1988,7 @@ fn layer_via_copy_of_one_linked_layer_keeps_the_copy_in_its_link_group() { /// tool does with several layers selected; without it the selection stays. #[test] fn translate_can_carry_the_selection_in_the_same_step() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100, "background": "transparent"})).unwrap(); let a = s.active().unwrap().active_layer.unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); @@ -2021,7 +2021,7 @@ fn translate_can_carry_the_selection_in_the_same_step() { /// opposite edge, and a move of exactly one canvas is not a history step. #[test] fn translate_wrap_folds_pixels_back_into_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(0, 1, 1, 2)); s.edit("paint", |doc, _| { @@ -2054,7 +2054,7 @@ fn translate_wrap_folds_pixels_back_into_the_canvas() { /// step of -1, and a move of exactly one canvas is history unless every target is raster. #[test] fn translate_wrap_moves_a_shape_by_the_raw_delta() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = LayerId(s.execute("shape.create", json!({"kind": "rect", "rect": [2, 1, 3, 2]})).unwrap()["layer"].as_u64().unwrap()); let xy = |s: &Session| { @@ -2069,7 +2069,7 @@ fn translate_wrap_moves_a_shape_by_the_raw_delta() { assert_eq!(s.active().unwrap().history.past_len(), steps + 1, "a full canvas still moves a shape"); assert_eq!(xy(&s), [9.0, 1.0]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(0, 0, 1, 1)); let steps = s.active().unwrap().history.past_len(); @@ -2081,7 +2081,7 @@ fn translate_wrap_moves_a_shape_by_the_raw_delta() { s.execute("layer.translate", json!({"dx": 8, "dy": 0, "wrap": true})).unwrap(); assert_eq!(s.active().unwrap().history.past_len(), steps, "a group of only rasters folds away too"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(1, 1, 2, 2)); s.execute("layer.layerMask.hideAll", json!({})).unwrap(); @@ -2100,7 +2100,7 @@ fn translate_wrap_moves_a_shape_by_the_raw_delta() { /// A contained wrap still leaves samples that started outside the canvas where they are. #[test] fn translate_wrap_leaves_off_canvas_samples_in_place() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(2, 1, 3, 2)); s.edit("paint", |doc, _| { @@ -2118,7 +2118,7 @@ fn translate_wrap_leaves_off_canvas_samples_in_place() { /// Opposite-edge samples wrap by tile copies of each piece, not one buffer of their bounding rect. #[test] fn translate_wrap_folds_sparse_tiles_on_opposite_edges() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 512, "height": 256, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(0, 0, 1, 1)); s.edit("paint", |doc, _| { @@ -2136,7 +2136,7 @@ fn translate_wrap_folds_sparse_tiles_on_opposite_edges() { /// A 256-pixel wrap on a 300-pixel canvas clones a whole tile; only the destination piece is kept. #[test] fn translate_wrap_clips_a_tile_aligned_piece_to_its_destination() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 64, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(0, 0, 1, 1)); s.edit("paint", |doc, _| { @@ -2155,7 +2155,7 @@ fn translate_wrap_clips_a_tile_aligned_piece_to_its_destination() { /// A linked vector mask on raster wraps with the pixels so it still covers them on the far edge. #[test] fn translate_wrap_folds_a_linked_vector_mask_with_raster() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(7, 1, 8, 2)); s.edit("mask", |doc, _| { @@ -2176,7 +2176,7 @@ fn translate_wrap_folds_a_linked_vector_mask_with_raster() { /// A linked raster mask on a shape follows the raw delta, like the shape itself. #[test] fn translate_wrap_moves_a_shape_mask_by_the_raw_delta() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = LayerId(s.execute("shape.create", json!({"kind": "rect", "rect": [2, 1, 3, 2]})).unwrap()["layer"].as_u64().unwrap()); s.execute("layer.layerMask.hideAll", json!({})).unwrap(); @@ -2199,7 +2199,7 @@ fn translate_wrap_moves_a_shape_mask_by_the_raw_delta() { /// reveal pixels the mask was hiding. #[test] fn translate_wrap_leaves_an_off_canvas_vector_mask_in_place() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = rect_layer(&mut s, Rect::new(1, 1, 2, 2)); s.edit("mask", |doc, _| { @@ -2231,7 +2231,7 @@ fn wrap_path_caps_repeated_edge_crossings() { /// later selection-limited edits on the opposite edge. #[test] fn translate_wrap_does_not_fold_a_selection_of_shapes() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let a = LayerId(s.execute("shape.create", json!({"kind": "rect", "rect": [1, 1, 2, 2]})).unwrap()["layer"].as_u64().unwrap()); let b = LayerId(s.execute("shape.create", json!({"kind": "rect", "rect": [3, 1, 4, 2]})).unwrap()["layer"].as_u64().unwrap()); @@ -2253,7 +2253,7 @@ fn translate_wrap_does_not_fold_a_selection_of_shapes() { /// covers the shape after a wrap move. #[test] fn translate_wrap_does_not_fold_a_mixed_group_mask() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let raster = rect_layer(&mut s, Rect::new(7, 1, 8, 2)); s.execute("shape.create", json!({"kind": "rect", "rect": [2, 1, 3, 2]})).unwrap(); @@ -2275,7 +2275,7 @@ fn translate_wrap_does_not_fold_a_mixed_group_mask() { /// Frame geometry is not a tile of samples. A whole-canvas wrap still moves the frame. #[test] fn translate_wrap_still_moves_a_frame() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "transparent"})).unwrap(); let id = LayerId(s.execute("layer.new.frame", json!({"x": 0, "y": 0, "width": 4, "height": 4})).unwrap()["layer"].as_u64().unwrap()); let tx = |s: &Session| s.active().unwrap().doc.layer(id).unwrap().frame.as_ref().unwrap().transform.m[4]; diff --git a/crates/engine/src/cmd/layer_multi_cmds/tile_damage_tests.rs b/crates/engine-core/src/cmd/layer_multi_cmds/tile_damage_tests.rs similarity index 99% rename from crates/engine/src/cmd/layer_multi_cmds/tile_damage_tests.rs rename to crates/engine-core/src/cmd/layer_multi_cmds/tile_damage_tests.rs index 937dd4af41..f996083ec4 100644 --- a/crates/engine/src/cmd/layer_multi_cmds/tile_damage_tests.rs +++ b/crates/engine-core/src/cmd/layer_multi_cmds/tile_damage_tests.rs @@ -5,7 +5,7 @@ use super::*; use photocraft_geom::TILE_SIZE; fn session(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); s } diff --git a/crates/engine/src/cmd/layer_nav_cmds.rs b/crates/engine-core/src/cmd/layer_nav_cmds.rs similarity index 99% rename from crates/engine/src/cmd/layer_nav_cmds.rs rename to crates/engine-core/src/cmd/layer_nav_cmds.rs index fd04d6e8f3..e8a4aaed81 100644 --- a/crates/engine/src/cmd/layer_nav_cmds.rs +++ b/crates/engine-core/src/cmd/layer_nav_cmds.rs @@ -107,7 +107,7 @@ mod tests { /// Bottom to top: Background, A, Group { B, C }, D. Panel rows: D, Group, C, B, A, Background. fn session() -> (Session, [LayerId; 6]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; let id = |s: &mut Session, cmd: &str, p: Value| LayerId(s.execute(cmd, p).unwrap()["layer"].as_u64().unwrap()); @@ -196,7 +196,7 @@ mod tests { st.saved_revision = st.revision; s.execute("layer.selectTop", json!({"junk": [1, 2]})).unwrap(); assert!(!s.active().unwrap().is_dirty(), "selecting a layer is not an edit"); - let mut empty = Session::new(); + let mut empty = crate::session(); for c in specs() { assert!(!empty.is_enabled(c.id)); assert!(empty.execute(c.id, json!({})).is_err()); diff --git a/crates/engine/src/cmd/layer_params.rs b/crates/engine-core/src/cmd/layer_params.rs similarity index 100% rename from crates/engine/src/cmd/layer_params.rs rename to crates/engine-core/src/cmd/layer_params.rs diff --git a/crates/engine/src/cmd/layer_references.rs b/crates/engine-core/src/cmd/layer_references.rs similarity index 100% rename from crates/engine/src/cmd/layer_references.rs rename to crates/engine-core/src/cmd/layer_references.rs diff --git a/crates/engine/src/cmd/layer_xmp_cmds.rs b/crates/engine-core/src/cmd/layer_xmp_cmds.rs similarity index 100% rename from crates/engine/src/cmd/layer_xmp_cmds.rs rename to crates/engine-core/src/cmd/layer_xmp_cmds.rs diff --git a/crates/engine/src/cmd/layer_xmp_cmds/tests.rs b/crates/engine-core/src/cmd/layer_xmp_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/layer_xmp_cmds/tests.rs rename to crates/engine-core/src/cmd/layer_xmp_cmds/tests.rs index cacad97308..d811ec22b6 100644 --- a/crates/engine/src/cmd/layer_xmp_cmds/tests.rs +++ b/crates/engine-core/src/cmd/layer_xmp_cmds/tests.rs @@ -4,7 +4,7 @@ use photocraft_doc::Layer; const PACKET: &str = r#"120"#; fn fixture(depth: u8) -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "depth": depth})).unwrap(); let (a, b) = s .edit("Fixture", |doc, _| { @@ -121,7 +121,7 @@ fn refuses_what_is_not_an_xmp_packet() { #[test] fn needs_a_document_and_a_layer() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(matches!(s.execute(ID, json!({})), Err(EngineError::Disabled(..)))); assert!(enabled(&s).is_err()); } diff --git a/crates/engine/src/cmd/lens_batch_close_tests.rs b/crates/engine-core/src/cmd/lens_batch_close_tests.rs similarity index 95% rename from crates/engine/src/cmd/lens_batch_close_tests.rs rename to crates/engine-core/src/cmd/lens_batch_close_tests.rs index 6cc4465389..c91c6e567a 100644 --- a/crates/engine/src/cmd/lens_batch_close_tests.rs +++ b/crates/engine-core/src/cmd/lens_batch_close_tests.rs @@ -9,7 +9,7 @@ fn fixture(name: &str) -> Res<(std::path::PathBuf, [String; 3], String)> { let dir = std::env::temp_dir().join(format!("pc-lens-close-{}-{name}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir)?; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "background": "#808080"}))?; let files = ["a.png", "b.png", "c.png"].map(|f| dir.join(f).to_string_lossy().into_owned()); let doc = &s.active().ok_or("no document")?.doc; @@ -45,7 +45,7 @@ fn paths(s: &Session) -> Vec> { #[test] fn an_open_unmodified_source_is_closed_and_the_other_documents_stay() { let (dir, [a, b, _], out) = fixture("open").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &a).unwrap(); let kept = untitled(&mut s).unwrap(); assert!(!s.documents()[0].is_dirty(), "the opened source is saved and unmodified"); @@ -66,7 +66,7 @@ fn an_open_unmodified_source_is_closed_and_the_other_documents_stay() { #[test] fn an_open_source_that_is_the_active_document_is_closed() { let (dir, [a, b, _], out) = fixture("active").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); untitled(&mut s).unwrap(); open(&mut s, &b).unwrap(); @@ -80,7 +80,7 @@ fn an_open_source_that_is_the_active_document_is_closed() { #[test] fn two_open_sources_are_both_closed_and_the_active_untitled_document_stays_active() { let (dir, [a, b, _], out) = fixture("both").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &a).unwrap(); let kept = untitled(&mut s).unwrap(); open(&mut s, &b).unwrap(); @@ -97,7 +97,7 @@ fn two_open_sources_are_both_closed_and_the_active_untitled_document_stays_activ #[test] fn a_source_listed_under_another_spelling_of_its_path_is_closed() { let (dir, [a, b, _], out) = fixture("alias").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &a).unwrap(); // `..` (unlike `.`) is not dropped when paths are compared, so only the file on disk matches. std::fs::create_dir(dir.join("sub")).unwrap(); @@ -113,7 +113,7 @@ fn a_source_listed_under_another_spelling_of_its_path_is_closed() { #[test] fn an_open_saved_document_that_is_not_a_source_stays_open() { let (dir, [a, b, c], out) = fixture("other").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &c).unwrap(); run(&mut s, json!([a, b]), &out).unwrap(); @@ -125,7 +125,7 @@ fn an_open_saved_document_that_is_not_a_source_stays_open() { #[test] fn an_open_source_with_unsaved_changes_stays_open() { let (dir, [a, b, _], out) = fixture("dirty").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &a).unwrap(); s.execute("layer.new.layer", json!({"name": "unsaved"})).unwrap(); let revision = s.active().unwrap().revision; @@ -144,7 +144,7 @@ fn an_open_source_with_unsaved_changes_stays_open() { #[test] fn an_open_source_whose_correction_fails_stays_open() { let (dir, [a, b, _], out) = fixture("failed").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &a).unwrap(); std::fs::remove_file(&a).unwrap(); @@ -160,7 +160,7 @@ fn an_open_source_whose_correction_fails_stays_open() { #[test] fn sources_that_are_not_open_leave_nothing_open() { let (dir, [a, b, _], out) = fixture("closed").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let r = run(&mut s, json!([a, b]), &out).unwrap(); @@ -174,7 +174,7 @@ fn sources_that_are_not_open_leave_nothing_open() { #[test] fn folder_mode_keeps_an_open_source_open() { let (dir, [a, _, _], out) = fixture("folder").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); open(&mut s, &a).unwrap(); run(&mut s, json!(dir.to_string_lossy()), &out).unwrap(); diff --git a/crates/engine/src/cmd/lens_batch_gray_tests.rs b/crates/engine-core/src/cmd/lens_batch_gray_tests.rs similarity index 97% rename from crates/engine/src/cmd/lens_batch_gray_tests.rs rename to crates/engine-core/src/cmd/lens_batch_gray_tests.rs index 218caf2e88..2650665809 100644 --- a/crates/engine/src/cmd/lens_batch_gray_tests.rs +++ b/crates/engine-core/src/cmd/lens_batch_gray_tests.rs @@ -8,7 +8,6 @@ use photocraft_color::{ColorMode, SampleType}; use serde_json::json; use super::LENS_BATCH; -use crate::Session; fn temp_dir(name: &str) -> PathBuf { let dir = std::env::temp_dir().join(format!("pc-lens-gray-{name}-{}", std::process::id())); @@ -19,7 +18,7 @@ fn temp_dir(name: &str) -> PathBuf { /// Writes a 40 x 30 source in `mode` and `depth` to `/in/`. fn source(dir: &Path, file: &str, mode: &str, depth: u32) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "mode": mode, "depth": depth})).unwrap(); let path = dir.join("in").join(file); crate::file_cmds::save_doc(&s.active().unwrap().doc, path.to_str().unwrap(), None).unwrap(); @@ -27,7 +26,7 @@ fn source(dir: &Path, file: &str, mode: &str, depth: u32) { /// Runs the batch on `/in` with `format` and returns the mode and depth of `/out/`. fn run(dir: &Path, format: &str, file: &str) -> (ColorMode, SampleType) { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute(LENS_BATCH, json!({"input": dir.join("in").to_str().unwrap(), "output": dir.join("out").to_str().unwrap(), "format": format})).unwrap(); assert!(r["errors"].as_array().unwrap().is_empty(), "{r}"); let path = dir.join("out").join(file); diff --git a/crates/engine/src/cmd/lens_cmds.rs b/crates/engine-core/src/cmd/lens_cmds.rs similarity index 99% rename from crates/engine/src/cmd/lens_cmds.rs rename to crates/engine-core/src/cmd/lens_cmds.rs index affbde1e94..ae7c187b02 100644 --- a/crates/engine/src/cmd/lens_cmds.rs +++ b/crates/engine-core/src/cmd/lens_cmds.rs @@ -530,7 +530,7 @@ mod tests { use super::*; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 80, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({"name": "grid"})).unwrap(); s.edit("grid", |doc, active| { @@ -735,7 +735,7 @@ mod tests { fn camera_raw_rejects_an_area_too_large_to_develop() { // #962: `area.width() * area.height()` overflowed u32 on a legal 65536×65536 canvas, // so `run` panicked and dispatch reported an internal error. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "transparent"})).unwrap(); s.execute("image.canvasSize", json!({"width": 65536, "height": 65536, "extensionColor": "transparent"})).unwrap(); let err = s.execute(RAW, json!({"exposure": 1})).unwrap_err(); diff --git a/crates/engine/src/cmd/magnetic_cmds.rs b/crates/engine-core/src/cmd/magnetic_cmds.rs similarity index 100% rename from crates/engine/src/cmd/magnetic_cmds.rs rename to crates/engine-core/src/cmd/magnetic_cmds.rs diff --git a/crates/engine/src/cmd/magnetic_cmds/tests.rs b/crates/engine-core/src/cmd/magnetic_cmds/tests.rs similarity index 97% rename from crates/engine/src/cmd/magnetic_cmds/tests.rs rename to crates/engine-core/src/cmd/magnetic_cmds/tests.rs index dd1c163346..88b47b9d2a 100644 --- a/crates/engine/src/cmd/magnetic_cmds/tests.rs +++ b/crates/engine-core/src/cmd/magnetic_cmds/tests.rs @@ -5,7 +5,7 @@ use super::*; /// A black 40×40 square at (40, 30) on a white 120×100 background. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 100})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -91,7 +91,7 @@ fn edges_come_from_the_visible_composite() { #[test] fn reads_only_around_the_border_of_a_large_image() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000, "background": "transparent"})).unwrap(); s.edit("paint", |doc, _| { doc.layers[0].surface_mut().unwrap().fill_rect(Rect::new(2000, 1500, 2200, 1700), &[1.0, 0.0, 0.0, 1.0]); @@ -132,10 +132,10 @@ fn bad_params_are_refused() { assert!(s.active().unwrap().doc.selection.is_none()); // Far outside the canvas is kept on it; a border far too long is refused. s.execute("select.magneticLasso", json!({"points": [[-1e9, -1e9], [1e9, -1e9], [1e9, 1e9]]})).unwrap(); - let mut big = Session::new(); + let mut big = crate::session(); big.execute("file.new", json!({"width": 30000, "height": 30000, "background": "transparent"})).unwrap(); let zigzag: Vec<[f64; 2]> = (0..20).map(|i| [f64::from(i % 2) * 30000.0, f64::from(i) * 1500.0]).collect(); assert!(big.execute("select.magneticLasso", json!({"points": zigzag})).is_err()); - let mut none = Session::new(); + let mut none = crate::session(); assert!(none.execute("select.magneticLasso", json!({"points": ROUGH})).is_err()); } diff --git a/crates/engine/src/cmd/mask_view_cmds.rs b/crates/engine-core/src/cmd/mask_view_cmds.rs similarity index 100% rename from crates/engine/src/cmd/mask_view_cmds.rs rename to crates/engine-core/src/cmd/mask_view_cmds.rs diff --git a/crates/engine/src/cmd/mask_view_cmds/tests.rs b/crates/engine-core/src/cmd/mask_view_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/mask_view_cmds/tests.rs rename to crates/engine-core/src/cmd/mask_view_cmds/tests.rs index 82179a5456..80a8acb2a4 100644 --- a/crates/engine/src/cmd/mask_view_cmds/tests.rs +++ b/crates/engine-core/src/cmd/mask_view_cmds/tests.rs @@ -3,7 +3,7 @@ use photocraft_geom::Rect; /// 40×20 document: Background, then "Masked" (red, mask hiding the left half) on top. fn session() -> (Session, u64, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id.0; let masked = s.execute("layer.new.layer", json!({"name": "Masked"})).unwrap()["layer"].as_u64().unwrap(); @@ -110,7 +110,7 @@ fn bad_params_and_no_mask_fail_gracefully() { assert_eq!(s.execute(ID, json!({"layer": bg, "mode": "off"})).unwrap()["mode"], "off"); assert_eq!(view(&s)["mode"], "gray"); // No document. - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute(ID, json!({"mode": "gray"})).is_err()); } @@ -161,7 +161,7 @@ fn backslash_command_toggles_the_overlay() { assert!(s.execute(OVERLAY_ID, json!({"layer": "x"})).is_err()); assert!(s.execute(OVERLAY_ID, json!([1])).is_err()); assert_eq!(view(&s), Value::Null); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(!empty.is_enabled(OVERLAY_ID)); assert!(empty.execute(OVERLAY_ID, json!({})).is_err()); } diff --git a/crates/engine/src/cmd/migrate_cmds.rs b/crates/engine-core/src/cmd/migrate_cmds.rs similarity index 97% rename from crates/engine/src/cmd/migrate_cmds.rs rename to crates/engine-core/src/cmd/migrate_cmds.rs index 8c705a71d2..ada62282c3 100644 --- a/crates/engine/src/cmd/migrate_cmds.rs +++ b/crates/engine-core/src/cmd/migrate_cmds.rs @@ -93,7 +93,7 @@ mod tests { #[test] fn merges_new_groups_only() { - let mut s = Session::new(); + let mut s = crate::session(); let before = s.presets.gradients.len(); let existing = s.presets.gradients[0].name.clone(); // A presets file with one new gradient group and one that already exists. @@ -138,7 +138,7 @@ mod tests { ("tool_presets", json!([{"name": "Imported tool", "tool": "brush", "options": {"size": 17.0}}])), ] { for wrapped in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); let mut data = json!({}); data[key] = incoming.clone(); if wrapped { @@ -152,7 +152,7 @@ mod tests { assert_eq!(s.prefs.rev(), prefs_rev + 1, "{key}, wrapped={wrapped}: preferences must be saved"); assert_ne!(s.presets.revision(), presets_rev); let saved = s.prefs_to_json(); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&saved).unwrap(); let imported = &incoming[0]; assert!(restored.prefs_value()["presets"][key].as_array().unwrap().contains(imported), "{key}, wrapped={wrapped}"); @@ -170,7 +170,7 @@ mod tests { s.execute("edit.presets.migratePresets", json!({"path": file.to_string_lossy()})).unwrap() }; // A damaged entry no longer discards the good ones; blank and overlong names are skipped. - let mut s = Session::new(); + let mut s = crate::session(); let before = s.presets.tool_presets.len(); let r = migrate( &mut s, @@ -188,11 +188,11 @@ mod tests { let padded = s.presets.tool_presets.iter().find(|t| t.name == "Padded").expect("trimmed name"); assert_eq!(padded.options, json!({})); // What was imported survives the next launch. - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(restored.presets.tool_presets, s.presets.tool_presets); // The library stays within MAX_PRESETS. - let mut s = Session::new(); + let mut s = crate::session(); let many: Vec = (0..MAX_PRESETS + 500).map(|i| json!({"name": format!("p{i}"), "tool": "brush"})).collect(); let before = s.presets.tool_presets.len(); let r = migrate(&mut s, json!({"tool_presets": many})); @@ -203,7 +203,7 @@ mod tests { #[test] fn bad_path_is_an_error() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("edit.presets.migratePresets", json!({"path": "/no/such/file.json"})).is_err()); assert!(s.execute("edit.presets.migratePresets", json!({})).is_err()); } diff --git a/crates/engine/src/cmd/mode_cmds.rs b/crates/engine-core/src/cmd/mode_cmds.rs similarity index 100% rename from crates/engine/src/cmd/mode_cmds.rs rename to crates/engine-core/src/cmd/mode_cmds.rs diff --git a/crates/engine/src/cmd/mode_cmds/color_table_index_tests.rs b/crates/engine-core/src/cmd/mode_cmds/color_table_index_tests.rs similarity index 98% rename from crates/engine/src/cmd/mode_cmds/color_table_index_tests.rs rename to crates/engine-core/src/cmd/mode_cmds/color_table_index_tests.rs index 02770d88ce..e0d62da9ad 100644 --- a/crates/engine/src/cmd/mode_cmds/color_table_index_tests.rs +++ b/crates/engine-core/src/cmd/mode_cmds/color_table_index_tests.rs @@ -11,7 +11,7 @@ const YELLOW: [f32; 4] = [1.0, 1.0, 0.0, 1.0]; /// The epic's test document, scaled down: four solid bars red, green, blue and yellow, converted /// to Indexed Color with an Exact palette, no dither and no transparency. fn bars() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "background": "white"})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); @@ -81,7 +81,7 @@ fn red_white_white() -> Session { let indices: Vec = row.iter().chain(&row).copied().collect(); let png = photocraft_codecs::encode_png_indexed(6, 2, &indices, &[[255, 0, 0], [255, 255, 255], [255, 255, 255]], None, None, None).unwrap(); let opened = photocraft_io::import("red-white-white.png", &png).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(opened.document, None); s } @@ -134,7 +134,7 @@ fn a_saved_document_keeps_its_indices() { let saved = photocraft_io::export(&s.active().unwrap().doc, "pcraft", &Default::default()).unwrap(); let reopened = photocraft_io::import("red-white-white.pcraft", &saved.bytes).unwrap(); assert!(reopened.document.color_indices.is_some()); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(reopened.document, None); s.execute("image.mode.colorTable", json!({"entries": {"2": "#00ff00"}})).unwrap(); assert_eq!(pairs(&s), [RED, WHITE, GREEN]); @@ -179,7 +179,7 @@ fn moved_pixels_fall_back_to_the_nearest_entry() { // must not be trusted after a move. The pixels of index 1 must not turn green. let indices: Vec = (0..256).flat_map(|_| (0..768).map(|x| [0u8, 2, 1][x / 256])).collect(); let png = photocraft_codecs::encode_png_indexed(768, 256, &indices, &[[255, 0, 0], [255, 255, 255], [255, 255, 255]], None, None, None).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(photocraft_io::import("solid.png", &png).unwrap().document, None); s.execute("image.canvasSize", json!({"width": 668, "height": 256, "anchor": "right"})).unwrap(); s.execute("image.mode.colorTable", json!({"entries": {"2": "#00ff00"}})).unwrap(); @@ -236,7 +236,7 @@ fn palette_pngs_of_every_bit_depth_keep_their_indices() { #[test] fn a_transparent_entry_keeps_its_index() { let png = photocraft_codecs::encode_png_indexed(3, 1, &[0, 1, 2], &[[0, 0, 0], [255, 255, 255], [255, 255, 255]], Some(0), None, None).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(photocraft_io::import("t.png", &png).unwrap().document, None); assert!(s.active().unwrap().doc.color_indices.is_some()); s.execute("image.mode.colorTable", json!({"entries": {"2": "#00ff00"}})).unwrap(); @@ -261,7 +261,7 @@ fn a_palette_png_without_shared_colours_is_not_read_again() { // Every entry its own colour: the colours already name the entries, so the open skips the // second pass over the file, and Color Table still recolours by entry. let png = photocraft_codecs::encode_png_indexed(3, 1, &[0, 1, 2], &[[0, 0, 0], [255, 255, 255], [0, 0, 255]], Some(0), None, None).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(photocraft_io::import("unique.png", &png).unwrap().document, None); assert!(s.active().unwrap().doc.color_indices.is_none()); s.execute("image.mode.colorTable", json!({"entries": {"1": "#00ff00"}})).unwrap(); @@ -291,13 +291,13 @@ fn a_flip_saved_and_reopened_leaves_the_indices_unknown() { let row = [0u8, 0, 1, 1, 2, 2]; let indices: Vec = row.iter().chain(&row).copied().collect(); let png = photocraft_codecs::encode_png_indexed(6, 2, &indices, &[[255, 255, 255], [255, 0, 0], [255, 255, 255]], None, None, None).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(photocraft_io::import("wrw.png", &png).unwrap().document, None); s.execute("image.imageRotation.flipCanvasHorizontal", json!({})).unwrap(); let saved = photocraft_io::export(&s.active().unwrap().doc, "pcraft", &Default::default()).unwrap(); let reopened = photocraft_io::import("wrw.pcraft", &saved.bytes).unwrap(); assert!(reopened.document.color_indices.is_none()); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(reopened.document, None); s.execute("image.mode.colorTable", json!({"entries": {"2": "#00ff00"}})).unwrap(); assert_eq!(pairs(&s), [WHITE, RED, WHITE], "the right columns came from index 0"); diff --git a/crates/engine/src/cmd/mode_cmds/tests.rs b/crates/engine-core/src/cmd/mode_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/mode_cmds/tests.rs rename to crates/engine-core/src/cmd/mode_cmds/tests.rs index 2ef957fdac..5e5d41bd34 100644 --- a/crates/engine/src/cmd/mode_cmds/tests.rs +++ b/crates/engine-core/src/cmd/mode_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_geom::Rect; fn session(w: u32, h: u32, depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "mode": mode})).unwrap(); paint(&mut s, |x, y| [x as f32 / w as f32, y as f32 / h as f32, 0.5, 1.0]); s @@ -95,7 +95,7 @@ fn rotate_arbitrary_keeps_the_full_precision_angle() { // Rounded to f32 this angle crosses a whole pixel: 1003 px instead of 1002, so a rotated crop // that sized its canvas with `rotated_size` at f64 would land 1 px off. let angle = 0.114_706_514_493_370_71; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1000, "height": 1000})).unwrap(); let r = s.execute("image.rotation.arbitrary", json!({"angle": angle})).unwrap(); assert_eq!(rotated_size(Size::new(1000, 1000), angle), Size::new(1002, 1002)); @@ -104,7 +104,7 @@ fn rotate_arbitrary_keeps_the_full_precision_angle() { #[test] fn rotate_arbitrary_rotates_grouped_locked_children_and_preserves_lock() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap(); s.execute("edit.fill", json!({"color": "#0000ff"})).unwrap(); @@ -152,7 +152,7 @@ fn rotate_arbitrary_rotates_grouped_locked_children_and_preserves_lock() { fn rotate_arbitrary_keeps_the_pixels_of_type_in_a_missing_font() { for depth in [8, 16, 32] { for (font, kept) in [("No Such Font 8860", true), ("", false)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 60, "depth": depth})).unwrap(); let cache = s .edit("type", |doc, _| { @@ -187,7 +187,7 @@ fn rotate_arbitrary_keeps_the_pixels_of_type_in_a_missing_font() { fn rotate_arbitrary_turns_unlinked_layer_masks() { for depth in [8, 16] { for grouped in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); @@ -289,7 +289,7 @@ fn indexed_color_palettes_and_dithers() { fn indexed_exact_preserves_profile_and_samples_through_default_rgb() { for depth in [8, 16, 32] { for profile in ["adobe-rgb-compat", "display-p3", "prophoto-compat", "none"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1, "height": 1, "depth": depth, "background": "transparent"})).unwrap(); s.execute("edit.assignProfile", json!({"profile": profile})).unwrap(); paint(&mut s, |_, _| [100.0 / 255.0, 150.0 / 255.0, 200.0 / 255.0, 1.0]); @@ -329,7 +329,7 @@ fn indexed_matte_blends_edges_without_replacing_clear_pixels() { ("foreground", [0.0, 0.0, 1.0]), ("background", [0.0, 1.0, 0.0]), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 1, "depth": depth, "background": "transparent"})).unwrap(); s.execute("tools.setColors", json!({"foreground": "#0000ff", "background": "#00ff00"})).unwrap(); paint(&mut s, |x, _| match x { @@ -366,7 +366,7 @@ fn indexed_matte_converts_working_rgb_to_document_profile_at_every_depth() { for depth in [8, 16, 32] { for (matte, color) in [("foreground", [0.0, 1.0, 0.0]), ("background", [1.0, 0.0, 0.0])] { for (intent, bpc) in [("relative", false), ("absolute", true)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"workingRgb": "display-p3", "intent": intent, "bpc": bpc})).unwrap(); s.execute("file.new", json!({"width": 2, "height": 1, "depth": depth, "background": "transparent"})).unwrap(); s.execute("edit.assignProfile", json!({"profile": "adobe-rgb-compat"})).unwrap(); @@ -394,7 +394,7 @@ fn indexed_matte_converts_working_rgb_to_document_profile_at_every_depth() { #[test] fn indexed_matte_hex_stays_in_document_rgb_coordinates() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1, "height": 1, "depth": depth, "background": "transparent"})).unwrap(); s.execute("edit.assignProfile", json!({"profile": "adobe-rgb-compat"})).unwrap(); paint(&mut s, |_, _| [1.0, 0.0, 0.0, 0.5]); @@ -411,7 +411,7 @@ fn indexed_matte_hex_stays_in_document_rgb_coordinates() { #[test] fn indexed_matte_named_gray_choices_use_their_document_samples() { for (matte, channel) in [("gray", 128.0 / 255.0), ("netscapeGray", 192.0 / 255.0)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1, "height": 1, "depth": 32, "background": "transparent"})).unwrap(); paint(&mut s, |_, _| [1.0, 0.0, 0.0, 0.5]); s.execute("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "dither": "none", "matte": matte})).unwrap(); @@ -426,7 +426,7 @@ fn indexed_matte_named_gray_choices_use_their_document_samples() { #[test] fn indexed_matte_without_transparency_fills_clear_pixels_and_rejects_bad_input_atomically() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 1, "background": "transparent"})).unwrap(); let before = s.active().unwrap().revision; for matte in [json!(false), json!(12), json!("#gg0000"), json!("#000000ff"), json!("unknown")] { @@ -441,7 +441,7 @@ fn indexed_matte_without_transparency_fills_clear_pixels_and_rejects_bad_input_a #[test] fn indexed_exact_rejects_full_opaque_palette_with_clear_pixels_atomically() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 257, "height": 1, "background": "transparent"})).unwrap(); paint(&mut s, |x, _| if x < 256 { [x as f32 / 255.0, x as f32 / 255.0, x as f32 / 255.0, 1.0] } else { [0.0; 4] }); let before = doc(&s).layers[0].surface().unwrap().to_interleaved(doc(&s).bounds()); @@ -460,7 +460,7 @@ fn indexed_exact_rejects_full_opaque_palette_with_clear_pixels_atomically() { #[test] fn indexed_exact_reserves_transparency_only_when_needed_and_available() { for (opaque, clear) in [(255u32, true), (256, false)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": opaque + u32::from(clear), "height": 1, "background": "transparent"})).unwrap(); paint(&mut s, |x, _| if x < opaque as i32 { [x as f32 / 255.0, x as f32 / 255.0, x as f32 / 255.0, 1.0] } else { [0.0; 4] }); let result = s.execute("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "dither": "none", "transparency": true})).unwrap(); @@ -482,7 +482,7 @@ fn indexed_exact_reserves_transparency_only_when_needed_and_available() { #[test] fn indexed_exact_failure_restores_a_floating_copy_and_redo() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 258, "height": 1, "background": "transparent"})).unwrap(); paint(&mut s, |x, _| if x < 256 { [x as f32 / 255.0, x as f32 / 255.0, x as f32 / 255.0, 1.0] } else { [0.0; 4] }); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 1, "height": 1})).unwrap(); @@ -517,7 +517,7 @@ fn indexed_exact_failure_restores_a_floating_copy_and_redo() { #[test] fn indexed_exact_success_drops_the_floating_copy_before_counting_colours() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 257, "height": 1, "background": "transparent"})).unwrap(); paint(&mut s, |x, _| if x < 256 { [x as f32 / 255.0, x as f32 / 255.0, x as f32 / 255.0, 1.0] } else { [0.0; 4] }); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 1, "height": 1})).unwrap(); @@ -541,7 +541,7 @@ fn indexed_exact_success_drops_the_floating_copy_before_counting_colours() { #[test] fn indexed_exact_transparency_and_sources() { // Two colours + transparency: exact palette with a transparent entry. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "transparent"})).unwrap(); paint(&mut s, |x, _| { if x < 3 { @@ -602,7 +602,7 @@ fn color_table_presets_and_entries() { #[test] fn clearing_color_table_transparency_restores_indexed_pixels() { let pixel = |s: &mut Session| -> [f32; 4] { serde_json::from_value(s.execute("document.pixel", json!({"x": 5, "y": 8})).unwrap()).unwrap() }; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "#ff0000"})).unwrap(); s.execute("image.mode.indexedColor", json!({"palette": "exact", "colors": 2, "forced": "none", "dither": "none"})).unwrap(); assert_eq!(doc(&s).color_table.as_ref().unwrap().colors, vec![[255, 0, 0]]); @@ -616,7 +616,7 @@ fn clearing_color_table_transparency_restores_indexed_pixels() { s.execute("image.mode.rgb", json!({})).unwrap(); assert_eq!(pixel(&mut s), [1.0, 0.0, 0.0, 1.0]); - let mut control = Session::new(); + let mut control = crate::session(); control.execute("file.new", json!({"width": 16, "height": 16, "background": "#ff0000"})).unwrap(); control.execute("image.mode.indexedColor", json!({"palette": "exact", "colors": 2, "forced": "none", "dither": "none"})).unwrap(); control.execute("image.mode.colorTable", json!({"entries": {"0": "#0000ff"}})).unwrap(); @@ -922,7 +922,7 @@ fn bitmap_budgets_a_conversion_at_the_document_resolution_too() { // #8477: without a resample nothing was budgeted, and a huge document's full-size f32 // working buffers aborted the app. 60000 x 60000 px (3.6 gigapixels, a plain white // background shares one tile) needs more than the 8 GiB budget at any depth: refused. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60_000, "height": 60_000, "mode": "grayscale"})).unwrap(); let before = s.active().unwrap().history.past_len(); let e = s.execute("image.mode.bitmap", json!({"method": "threshold"})).unwrap_err().to_string(); @@ -1015,7 +1015,7 @@ fn bitmap_in_bands_matches_one_full_canvas_conversion() { fn bitmap_lays_a_transparent_composite_over_white() { // Transparent pixels flatten over white before the conversion: an empty canvas is white, // 25%-opaque black is light (75% gray) and thresholds to white, 75%-opaque black to black. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 3, "height": 1, "mode": "grayscale", "background": "transparent"})).unwrap(); paint(&mut s, |x, _| [0.0, 0.0, 0.0, [0.0, 0.25, 0.75][x as usize]]); s.execute("image.mode.bitmap", json!({"method": "threshold"})).unwrap(); @@ -1157,7 +1157,7 @@ fn duotone_to_rgb_inks_fill_layer_colours() { /// Three-entry Indexed doc (red, blue, transparent at index 2) from an RGB doc with clear pixels. fn indexed_with_transparency() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "transparent"})).unwrap(); paint(&mut s, |x, _| { if x < 3 { @@ -1220,7 +1220,7 @@ fn color_table_rejects_an_invalid_transparent_index_without_editing() { /// A white 16×16 document in Indexed Color with the two-entry black/white table (#8669's repro). fn black_white_indexed(transparency: bool) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); let background = if transparency { "transparent" } else { "white" }; s.execute("file.new", json!({"width": 16, "height": 16, "background": background})).unwrap(); paint(&mut s, |x, _| { diff --git a/crates/engine/src/cmd/multichannel_cmds.rs b/crates/engine-core/src/cmd/multichannel_cmds.rs similarity index 100% rename from crates/engine/src/cmd/multichannel_cmds.rs rename to crates/engine-core/src/cmd/multichannel_cmds.rs diff --git a/crates/engine/src/cmd/multichannel_cmds/tests.rs b/crates/engine-core/src/cmd/multichannel_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/multichannel_cmds/tests.rs rename to crates/engine-core/src/cmd/multichannel_cmds/tests.rs index 79eac5cd63..774bd22394 100644 --- a/crates/engine/src/cmd/multichannel_cmds/tests.rs +++ b/crates/engine-core/src/cmd/multichannel_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_color::SampleType; fn session(mode: &str, depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 12, "height": 8, "depth": depth, "mode": mode})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); diff --git a/crates/engine/src/cmd/new_document_history_name_tests.rs b/crates/engine-core/src/cmd/new_document_history_name_tests.rs similarity index 95% rename from crates/engine/src/cmd/new_document_history_name_tests.rs rename to crates/engine-core/src/cmd/new_document_history_name_tests.rs index 166e69b011..7cd855830c 100644 --- a/crates/engine/src/cmd/new_document_history_name_tests.rs +++ b/crates/engine-core/src/cmd/new_document_history_name_tests.rs @@ -22,7 +22,7 @@ fn open_png(s: &mut Session, name: &str) { #[test] fn the_new_document_dialogs_document_has_the_state_new_under_its_snapshot() { // The measured case: White, 13 x 400 px at 1 ppi, created as Untitled-1. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 13, "height": 400, "resolution": 1, "background": "white", "name": "Untitled-1"})).unwrap(); assert_eq!(history(&s), (json!(["New"]), json!([{"id": 0, "name": "Untitled-1"}]))); } @@ -30,7 +30,7 @@ fn the_new_document_dialogs_document_has_the_state_new_under_its_snapshot() { #[test] fn an_artboard_document_has_the_state_new_too() { // The measured case: Artboards on, 11 x 8 in at 300 ppi, White. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 3300, "height": 2400, "resolution": 300, "artboard": true, "name": "Untitled-1"})).unwrap(); assert_eq!(history(&s), (json!(["New"]), json!([{"id": 0, "name": "Untitled-1"}]))); } @@ -43,7 +43,7 @@ fn every_background_and_mode_of_file_new_gives_new() { json!({"width": 8, "height": 8, "background": "black", "mode": "cmyk", "depth": 16}), json!({"width": 8, "height": 8, "background": "#336699", "mode": "lab", "depth": 32}), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", p.clone()).unwrap(); assert_eq!(history(&s).0, json!(["New"]), "{p}"); } @@ -51,7 +51,7 @@ fn every_background_and_mode_of_file_new_gives_new() { #[test] fn the_first_state_stays_new_through_undo_and_redo_and_is_the_default_brush_source() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let source = |s: &Session| crate::inspect::document(s.active().unwrap())["historySource"].clone(); assert_eq!(source(&s), json!({"state": 0, "label": "New"})); @@ -66,7 +66,7 @@ fn the_first_state_stays_new_through_undo_and_redo_and_is_the_default_brush_sour #[test] fn an_opened_file_keeps_open_next_to_a_new_document() { - let mut s = Session::new(); + let mut s = crate::session(); open_png(&mut s, "before.png"); s.execute("file.new", json!({"width": 8, "height": 8, "name": "Untitled-1"})).unwrap(); open_png(&mut s, "after.png"); diff --git a/crates/engine/src/cmd/notes_cmds.rs b/crates/engine-core/src/cmd/notes_cmds.rs similarity index 99% rename from crates/engine/src/cmd/notes_cmds.rs rename to crates/engine-core/src/cmd/notes_cmds.rs index 590df80131..da18436c1d 100644 --- a/crates/engine/src/cmd/notes_cmds.rs +++ b/crates/engine-core/src/cmd/notes_cmds.rs @@ -322,7 +322,7 @@ mod tests { use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80})).unwrap(); s } diff --git a/crates/engine/src/cmd/notes_import_message_tests.rs b/crates/engine-core/src/cmd/notes_import_message_tests.rs similarity index 99% rename from crates/engine/src/cmd/notes_import_message_tests.rs rename to crates/engine-core/src/cmd/notes_import_message_tests.rs index bf686b7516..3b03d55337 100644 --- a/crates/engine/src/cmd/notes_import_message_tests.rs +++ b/crates/engine-core/src/cmd/notes_import_message_tests.rs @@ -10,7 +10,7 @@ use super::{NO_NOTES_IMPORTED, import_notes_from, source_error}; use crate::{EngineError, Session}; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80})).unwrap(); s } diff --git a/crates/engine/src/cmd/notes_import_placement_tests.rs b/crates/engine-core/src/cmd/notes_import_placement_tests.rs similarity index 99% rename from crates/engine/src/cmd/notes_import_placement_tests.rs rename to crates/engine-core/src/cmd/notes_import_placement_tests.rs index d28eb96eff..b0b1534261 100644 --- a/crates/engine/src/cmd/notes_import_placement_tests.rs +++ b/crates/engine-core/src/cmd/notes_import_placement_tests.rs @@ -74,7 +74,7 @@ fn an_import_reports_outside_and_keeps_the_history_step() { let mut src = Document::new("src", photocraft_doc::Size::new(600, 400), photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U8); src.notes = source(); let bytes = photocraft_format::save_to_bytes(&src, &Default::default()).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1200, "height": 1600})).unwrap(); let before = s.active().unwrap().history.past_len(); let r = import_notes_from(&mut s, "notes.pcraft", &bytes).unwrap(); diff --git a/crates/engine/src/cmd/notes_stored_values_tests.rs b/crates/engine-core/src/cmd/notes_stored_values_tests.rs similarity index 99% rename from crates/engine/src/cmd/notes_stored_values_tests.rs rename to crates/engine-core/src/cmd/notes_stored_values_tests.rs index 2c79fdeb12..12551748de 100644 --- a/crates/engine/src/cmd/notes_stored_values_tests.rs +++ b/crates/engine-core/src/cmd/notes_stored_values_tests.rs @@ -9,7 +9,7 @@ use super::notes_cmds::{DEFAULT_NOTE_COLOR, pdf_date_at}; use crate::Session; fn session(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/ops.rs b/crates/engine-core/src/cmd/ops.rs similarity index 99% rename from crates/engine/src/cmd/ops.rs rename to crates/engine-core/src/cmd/ops.rs index 7073b45184..c300028e72 100644 --- a/crates/engine/src/cmd/ops.rs +++ b/crates/engine-core/src/cmd/ops.rs @@ -270,7 +270,7 @@ mod tests { /// layer that has a mask already keeps it unless asked to replace it; one undo puts it back. #[test] fn a_layer_mask_moves_or_copies_onto_another_layer_or_group() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let a = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); s.execute("select.rect", json!({"x": 4, "y": 4, "width": 10, "height": 10})).unwrap(); @@ -308,7 +308,7 @@ mod tests { /// enabled state and density, nothing else in the document changes, and no history step is added. #[test] fn dropping_a_layer_mask_on_its_own_layer_changes_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let a = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); s.execute("select.rect", json!({"x": 4, "y": 4, "width": 10, "height": 10})).unwrap(); @@ -333,7 +333,7 @@ mod tests { /// mask, puts both layers' masks back exactly (pixels, enabled, density, feather). #[test] fn undo_restores_both_masks_after_a_copy_or_a_replace() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let a = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); s.execute("select.rect", json!({"x": 4, "y": 4, "width": 10, "height": 10})).unwrap(); diff --git a/crates/engine/src/cmd/paint_cmds.rs b/crates/engine-core/src/cmd/paint_cmds.rs similarity index 100% rename from crates/engine/src/cmd/paint_cmds.rs rename to crates/engine-core/src/cmd/paint_cmds.rs diff --git a/crates/engine/src/cmd/paint_cmds/bucket_bitmap_tests.rs b/crates/engine-core/src/cmd/paint_cmds/bucket_bitmap_tests.rs similarity index 96% rename from crates/engine/src/cmd/paint_cmds/bucket_bitmap_tests.rs rename to crates/engine-core/src/cmd/paint_cmds/bucket_bitmap_tests.rs index 5149067238..42f7fbea06 100644 --- a/crates/engine/src/cmd/paint_cmds/bucket_bitmap_tests.rs +++ b/crates/engine-core/src/cmd/paint_cmds/bucket_bitmap_tests.rs @@ -6,7 +6,7 @@ use super::*; fn bitmap() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "background": "white"})).unwrap(); s.execute("image.mode.grayscale", json!({})).unwrap(); s.execute("image.mode.bitmap", json!({})).unwrap(); @@ -64,7 +64,7 @@ fn other_modes_still_fill() { ("lab", 16), ("indexed", 8), ] { - let mut s = Session::new(); + let mut s = crate::session(); let new_mode = if mode == "indexed" { "rgb" } else { mode }; s.execute("file.new", json!({"width": 64, "height": 64, "mode": new_mode, "depth": depth, "background": "white"})).unwrap(); if mode == "indexed" { @@ -81,10 +81,10 @@ fn other_modes_still_fill() { #[test] fn unmeasured_modes_are_not_refused() { - let mut multi = Session::new(); + let mut multi = crate::session(); multi.execute("file.new", json!({"width": 64, "height": 64, "background": "white"})).unwrap(); multi.execute("image.mode.multichannel", json!({})).unwrap(); - let mut duotone = Session::new(); + let mut duotone = crate::session(); duotone.execute("file.new", json!({"width": 64, "height": 64, "mode": "grayscale", "background": "white"})).unwrap(); duotone.execute("image.mode.duotone", json!({"type": "monotone"})).unwrap(); for (mut s, mode) in [(multi, photocraft_color::ColorMode::Multichannel), (duotone, photocraft_color::ColorMode::Duotone)] { diff --git a/crates/engine/src/cmd/paint_cmds/bucket_no_op_history_tests.rs b/crates/engine-core/src/cmd/paint_cmds/bucket_no_op_history_tests.rs similarity index 98% rename from crates/engine/src/cmd/paint_cmds/bucket_no_op_history_tests.rs rename to crates/engine-core/src/cmd/paint_cmds/bucket_no_op_history_tests.rs index 7c0170c083..5b88e1de82 100644 --- a/crates/engine/src/cmd/paint_cmds/bucket_no_op_history_tests.rs +++ b/crates/engine-core/src/cmd/paint_cmds/bucket_no_op_history_tests.rs @@ -7,7 +7,7 @@ use photocraft_geom::Rect; /// A white 80x60 document whose Background has a black wall at x = 30, so the regions left and /// right of it are separate; with a 20x20 selection in the top-left corner. fn walled() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "background": "white"})).unwrap(); s.edit("wall", |doc, active| { doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(30, 0, 31, 60), &[0.0, 0.0, 0.0, 1.0]); @@ -82,7 +82,7 @@ fn a_click_outside_the_selection_adds_no_state_even_when_its_region_reaches_it() fills_nothing(&mut s, json!({"x": 25, "y": 5, "color": "#ff0000", "sampleAllLayers": all}), &format!("sampleAllLayers {all}")); } // The issue's measured case: a plain 800x600 document, a click outside the selection. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 200, "height": 200})).unwrap(); fills_nothing(&mut s, json!({"x": 400, "y": 50, "color": "#ff0000"}), "800x600, click at (400, 50)"); diff --git a/crates/engine/src/cmd/paint_cmds/tests.rs b/crates/engine-core/src/cmd/paint_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/paint_cmds/tests.rs rename to crates/engine-core/src/cmd/paint_cmds/tests.rs index 7043373580..de6bc5da95 100644 --- a/crates/engine/src/cmd/paint_cmds/tests.rs +++ b/crates/engine-core/src/cmd/paint_cmds/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_geom::Rect; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10})).unwrap(); s } @@ -14,7 +14,7 @@ fn px(s: &Session, x: i32, y: i32) -> Vec { /// A visible wall on the Background with an empty, active layer above it. fn bucket_layers(depth: u32) -> (Session, photocraft_doc::LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "depth": depth, "background": "white"})).unwrap(); let bottom = s.active().unwrap().active_layer.unwrap(); s.edit("wall", |doc, _| { @@ -31,7 +31,7 @@ fn bucket_layers(depth: u32) -> (Session, photocraft_doc::LayerId) { #[test] fn bucket_mode_multiplies_clears_and_rejects_bad_names() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let base = json!({"x": 1, "y": 1, "antiAlias": false, "tolerance": 0}); @@ -284,7 +284,7 @@ fn grey_fill(cmd: &str, opacity: Value) -> Value { } fn white(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "depth": depth, "background": "white"})).unwrap(); s } @@ -334,7 +334,7 @@ fn bucket_and_gradient_reject_non_numeric_opacity_without_editing() { /// transparency, Deselect, then the Paint Bucket clicked in the hole with white at 100 %. Returns /// the session after the fill and the layer's pixels right after the clear. fn clear_then_bucket(depth: u32, selection: Value, bucket_aa: bool) -> (Session, Vec<[f32; 4]>) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 100, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layerFromBackground", json!({})).unwrap(); s.execute("select.rect", selection).unwrap(); diff --git a/crates/engine/src/cmd/params.rs b/crates/engine-core/src/cmd/params.rs similarity index 100% rename from crates/engine/src/cmd/params.rs rename to crates/engine-core/src/cmd/params.rs diff --git a/crates/engine/src/cmd/path_delete_last_anchor_tests.rs b/crates/engine-core/src/cmd/path_delete_last_anchor_tests.rs similarity index 99% rename from crates/engine/src/cmd/path_delete_last_anchor_tests.rs rename to crates/engine-core/src/cmd/path_delete_last_anchor_tests.rs index d0b4cf7252..7d054c46ed 100644 --- a/crates/engine/src/cmd/path_delete_last_anchor_tests.rs +++ b/crates/engine-core/src/cmd/path_delete_last_anchor_tests.rs @@ -8,7 +8,7 @@ use serde_json::{Value, json}; use crate::Session; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 400, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/path_edit_cmds.rs b/crates/engine-core/src/cmd/path_edit_cmds.rs similarity index 99% rename from crates/engine/src/cmd/path_edit_cmds.rs rename to crates/engine-core/src/cmd/path_edit_cmds.rs index 98cbe43ccd..4be7987d8c 100644 --- a/crates/engine/src/cmd/path_edit_cmds.rs +++ b/crates/engine-core/src/cmd/path_edit_cmds.rs @@ -384,7 +384,7 @@ mod tests { use crate::Session; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 100, "background": "white"})).unwrap(); s } @@ -477,7 +477,7 @@ mod tests { #[test] fn shape_paths_and_vector_masks_are_edited_and_rerendered() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 100, "depth": depth})).unwrap(); let id = s.execute("shape.create", json!({"kind": "rect", "rect": [10, 10, 40, 40], "fill": "#ff0000"})).unwrap()["layer"].as_u64().unwrap(); let r = s.execute("path.moveAnchors", json!({"name": "layer", "layer": id, "anchors": [[0, 1], [0, 2]], "move": [30, 0]})).unwrap(); @@ -585,7 +585,7 @@ mod tests { let r = s.execute("path.deleteAnchor", json!({"name": "Outline", "subpath": 0, "knot": 0})).unwrap(); assert_eq!((r["path"]["subpaths"][0]["knots"].as_array().unwrap().len(), r["path"]["subpaths"][0]["closed"].clone()), (3, json!(true))); for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 100, "depth": depth})).unwrap(); let id = s.execute("shape.create", json!({"kind": "rect", "rect": [10, 10, 40, 40], "fill": "#ff0000"})).unwrap()["layer"].as_u64().unwrap(); // Top edge, then pull the new midpoint up: the layer re-renders from the edited path. diff --git a/crates/engine/src/cmd/pattern_cmds.rs b/crates/engine-core/src/cmd/pattern_cmds.rs similarity index 98% rename from crates/engine/src/cmd/pattern_cmds.rs rename to crates/engine-core/src/cmd/pattern_cmds.rs index 1271ea0591..4b3b441863 100644 --- a/crates/engine/src/cmd/pattern_cmds.rs +++ b/crates/engine-core/src/cmd/pattern_cmds.rs @@ -640,7 +640,7 @@ mod tests { use photocraft_doc::LayerId; fn session(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth})).unwrap(); s } @@ -652,12 +652,12 @@ mod tests { #[test] fn library_has_builtins_and_lists() { - let mut s = Session::new(); + let mut s = crate::session(); let v = s.execute("pattern.list", json!({})).unwrap(); assert!(v.as_array().unwrap().len() >= 6); assert!(v[0]["id"].as_str().unwrap().len() == 36); // Built-in ids are stable across sessions. - assert_eq!(builtin()[0].id, Session::new().patterns.items[0].id); + assert_eq!(builtin()[0].id, crate::session().patterns.items[0].id); } #[test] @@ -706,7 +706,7 @@ mod tests { fn banded_compositing_matches_a_single_pass() { for depth in [8u64, 16, 32] { for transparent in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); let background = if transparent { "transparent" } else { "white" }; s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth, "background": background})).unwrap(); s.execute("select.rect", json!({"x": 3, "y": 4, "width": 20, "height": 13})).unwrap(); @@ -730,7 +730,7 @@ mod tests { #[test] fn alpha_that_stores_as_opaque_counts_as_opaque() { for (depth, opaque) in [(8u64, true), (32, false)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": depth, "background": "transparent"})).unwrap(); s.execute("edit.fill", json!({"color": "#336699"})).unwrap(); s.execute("layer.setProps", json!({"opacity": 0.999})).unwrap(); @@ -746,7 +746,7 @@ mod tests { #[test] fn defined_patterns_over_4096_squared_paint_or_are_refused() { for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4100, "height": 4100, "depth": depth})).unwrap(); s.execute("edit.fill", json!({"color": "#336699"})).unwrap(); s.execute("edit.definePattern", json!({"name": "Big"})).unwrap(); @@ -756,12 +756,12 @@ mod tests { let [r, g, b, a] = pixel(&s, 5, 5); assert!(a == 1.0 && (r - 0.2).abs() < 0.01 && (g - 0.4).abs() < 0.01 && (b - 0.6).abs() < 0.01, "depth {depth}: {:?}", [r, g, b, a]); } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4100, "height": 4100, "depth": 32})).unwrap(); let e = s.execute("edit.definePattern", json!({})).unwrap_err().to_string(); assert!(e.contains("32-bit") && e.contains("16777216"), "{e}"); assert!(s.patterns.items.iter().all(|p| p.name != "Pattern"), "nothing was defined"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 5600, "depth": 16})).unwrap(); let e = s.execute("edit.definePattern", json!({})).unwrap_err().to_string(); assert!(e.contains("16-bit") && e.contains("33554432"), "{e}"); @@ -770,7 +770,7 @@ mod tests { /// A pattern at the area limit is paintable and renders; production permits 8000×8000 at 8 bits. #[test] fn a_pattern_at_the_area_limit_is_defined_and_paints() { - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(MAX_DEFINE_EDGE, 8000); assert!(photocraft_doc::pattern::max_paint_pixels(SampleType::U8) >= 8000 * 8000); assert_eq!(photocraft_doc::pattern::working_bytes_for(8000 * 8000, SampleType::U8), 8000 * 8000 * 4); @@ -793,7 +793,7 @@ mod tests { /// and by pattern.list, instead of rendering as transparency with no message. #[test] fn a_pattern_that_would_paint_nothing_is_reported() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": 8})).unwrap(); // A 32-bit 5000 x 5000 pattern (declared only: 400 MB as a working copy, past the cap). let surface = photocraft_raster::Surface::new(photocraft_doc::PixelFormat::RGBA32F); @@ -819,7 +819,7 @@ mod tests { #[test] fn define_pattern_accepts_edges_over_4000_up_to_8000() { for (w, ok) in [(4100, true), (8000, true), (8001, false)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": 2, "depth": 8})).unwrap(); s.execute("edit.fill", json!({"color": "#336699"})).unwrap(); let r = s.execute("edit.definePattern", json!({})); diff --git a/crates/engine/src/cmd/pattern_fill_cmds.rs b/crates/engine-core/src/cmd/pattern_fill_cmds.rs similarity index 98% rename from crates/engine/src/cmd/pattern_fill_cmds.rs rename to crates/engine-core/src/cmd/pattern_fill_cmds.rs index 96caaa50a3..1f2df5b69c 100644 --- a/crates/engine/src/cmd/pattern_fill_cmds.rs +++ b/crates/engine-core/src/cmd/pattern_fill_cmds.rs @@ -153,7 +153,7 @@ mod tests { use std::sync::Arc; fn session(depth: u64) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 2, "y": 2, "width": 20, "height": 10})).unwrap(); let id = s.execute(CREATE, json!({"pattern": "Checkerboard"})).unwrap()["layer"].as_u64().unwrap(); @@ -207,7 +207,7 @@ mod tests { #[test] fn an_empty_pixel_layer_becomes_the_fill_other_layers_get_one_above() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); let empty = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); let before = s.active().unwrap().doc.clone(); @@ -241,7 +241,7 @@ mod tests { /// it) and a blank video layer. Both get a fill above and keep what they had. #[test] fn a_default_pixel_or_video_layer_is_not_taken_for_an_empty_one() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); let opaque = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); let doc = Arc::make_mut(s.active_mut().unwrap().doc_mut()); @@ -264,7 +264,7 @@ mod tests { #[test] fn an_empty_layer_is_still_the_fill_after_a_mode_change() { for mode in ["image.mode.cmyk", "image.mode.lab"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); let empty = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); s.execute(mode, json!({})).unwrap(); @@ -302,7 +302,7 @@ mod tests { fn create_preview_and_commit_honor_default_masks_option() { for depth in [8, 16, 32] { for default_mask in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth})).unwrap(); s.edit_prefs(|prefs| { prefs.dialogs.insert("ui.layersPanelOptions".into(), json!({"useDefaultMasksOnFillLayers": default_mask})); @@ -364,7 +364,7 @@ mod tests { s.execute("layer.newFillLayer.solidColor", json!({})).unwrap(); assert!(s.execute(SET, json!({"scale": 50})).is_err(), "a Solid Color Fill is not a Pattern Fill"); assert_eq!(s.active().unwrap().doc.layer(id), before.layer(id)); - assert!(Session::new().execute(SET, json!({})).is_err(), "no document"); + assert!(crate::session().execute(SET, json!({})).is_err(), "no document"); } #[test] diff --git a/crates/engine/src/cmd/perspective_crop_cmds.rs b/crates/engine-core/src/cmd/perspective_crop_cmds.rs similarity index 99% rename from crates/engine/src/cmd/perspective_crop_cmds.rs rename to crates/engine-core/src/cmd/perspective_crop_cmds.rs index bed7292739..a4f0dab270 100644 --- a/crates/engine/src/cmd/perspective_crop_cmds.rs +++ b/crates/engine-core/src/cmd/perspective_crop_cmds.rs @@ -329,7 +329,7 @@ mod tests { } } doc.layers[0].surface_mut().unwrap().write_region(Rect::from_xywh(0, 0, 160, 120), &px); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); s } @@ -402,7 +402,7 @@ mod tests { fn a_quad_below_a_horizon_across_the_canvas_keeps_its_content() { let mut doc = Document::with_background("red", Size::new(100, 100), ColorMode::Rgb, SampleType::U8, Color::WHITE); doc.layers[0].surface_mut().unwrap().fill_rect(Rect::from_xywh(0, 0, 100, 100), &[1.0, 0.0, 0.0, 1.0]); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); s.execute(CMD, json!({"corners": [[40, 70], [60, 70], [90, 95], [10, 95]], "width": 50, "height": 39})).unwrap(); let px = s.active().unwrap().doc.layers[0].surface().unwrap().rgba(25, 20); diff --git a/crates/engine/src/cmd/perspective_crop_refuse_tests.rs b/crates/engine-core/src/cmd/perspective_crop_refuse_tests.rs similarity index 98% rename from crates/engine/src/cmd/perspective_crop_refuse_tests.rs rename to crates/engine-core/src/cmd/perspective_crop_refuse_tests.rs index 03d556b7e5..065dfcdf90 100644 --- a/crates/engine/src/cmd/perspective_crop_refuse_tests.rs +++ b/crates/engine-core/src/cmd/perspective_crop_refuse_tests.rs @@ -41,7 +41,7 @@ fn session(extra: Vec) -> Session { for l in extra { doc.insert_above(None, l); } - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); s } @@ -167,7 +167,7 @@ fn a_type_layer_and_a_smart_object_refuse_once() { #[test] fn a_bitmap_document_refuses_the_perspective_crop() { let doc = Document::with_background("bitmap", Size::new(160, 120), ColorMode::Bitmap, SampleType::U8, Color::WHITE); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); assert_refused(&mut s, NOT_BITMAP, "Bitmap document"); } @@ -177,7 +177,7 @@ fn a_bitmap_document_refuses_the_perspective_crop() { /// live is #11800, so this pins the crop, not their kind. #[test] fn pixel_adjustment_fill_shape_and_group_layers_still_crop() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 500})).unwrap(); s.execute("layer.newAdjustmentLayer.levels", json!({})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({"color": "#3366cc"})).unwrap(); @@ -197,7 +197,7 @@ fn pixel_adjustment_fill_shape_and_group_layers_still_crop() { fn rgb_grayscale_and_cmyk_documents_are_not_refused() { for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Cmyk] { let doc = Document::with_background("m", Size::new(160, 120), mode, SampleType::U8, Color::WHITE); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); s.execute(CMD, crop_params()).unwrap(); assert_eq!(s.active().unwrap().doc.size, Size::new(100, 80), "{mode:?} cropped"); diff --git a/crates/engine/src/cmd/perspective_crop_size_tests.rs b/crates/engine-core/src/cmd/perspective_crop_size_tests.rs similarity index 99% rename from crates/engine/src/cmd/perspective_crop_size_tests.rs rename to crates/engine-core/src/cmd/perspective_crop_size_tests.rs index 4fb25b8903..3fa93e0848 100644 --- a/crates/engine/src/cmd/perspective_crop_size_tests.rs +++ b/crates/engine-core/src/cmd/perspective_crop_size_tests.rs @@ -4,8 +4,6 @@ use photocraft_algo::transform::{convex_quad, quad_free_size}; use serde_json::{Value, json}; -use crate::Session; - const SKEWED: [[f64; 2]; 4] = [[100.0, 50.0], [700.0, 80.0], [760.0, 450.0], [40.0, 420.0]]; const PAST_CANVAS: [[f64; 2]; 4] = [[100.0, 50.0], [872.0, 50.0], [872.0, 550.0], [100.0, 450.0]]; const RECTANGLE: [[f64; 2]; 4] = [[100.0, 50.0], [700.0, 50.0], [700.0, 450.0], [100.0, 450.0]]; @@ -13,7 +11,7 @@ const CENTER: [f64; 2] = [400.0, 250.0]; /// The size an 800 x 500 document commits to. fn commit(corners: [[f64; 2]; 4], options: Value) -> (u32, u32) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 500, "background": "white"})).unwrap(); let mut p = json!({"corners": corners}); p.as_object_mut().unwrap().extend(options.as_object().unwrap().clone()); diff --git a/crates/engine/src/cmd/photo_cmds.rs b/crates/engine-core/src/cmd/photo_cmds.rs similarity index 100% rename from crates/engine/src/cmd/photo_cmds.rs rename to crates/engine-core/src/cmd/photo_cmds.rs diff --git a/crates/engine/src/cmd/photo_cmds/photomerge_layer_order_tests.rs b/crates/engine-core/src/cmd/photo_cmds/photomerge_layer_order_tests.rs similarity index 99% rename from crates/engine/src/cmd/photo_cmds/photomerge_layer_order_tests.rs rename to crates/engine-core/src/cmd/photo_cmds/photomerge_layer_order_tests.rs index 5a44a04294..a5cfdf6a4e 100644 --- a/crates/engine/src/cmd/photo_cmds/photomerge_layer_order_tests.rs +++ b/crates/engine-core/src/cmd/photo_cmds/photomerge_layer_order_tests.rs @@ -28,7 +28,7 @@ fn scene(w: usize, h: usize) -> Vec<[f32; 4]> { fn three_tiles() -> Session { let (sw, sh, t) = (700usize, 300usize, 300usize); let sc = scene(sw, sh); - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 200, 400].into_iter().enumerate() { let mut d = Document::new(format!("t{}.tif", k + 1), Size::new(t as u32, t as u32), ColorMode::Rgb, SampleType::U8); let fmt = d.pixel_format(); diff --git a/crates/engine/src/cmd/photo_cmds/photomerge_name_tests.rs b/crates/engine-core/src/cmd/photo_cmds/photomerge_name_tests.rs similarity index 97% rename from crates/engine/src/cmd/photo_cmds/photomerge_name_tests.rs rename to crates/engine-core/src/cmd/photo_cmds/photomerge_name_tests.rs index b3bf560b43..7ede132e4b 100644 --- a/crates/engine/src/cmd/photo_cmds/photomerge_name_tests.rs +++ b/crates/engine-core/src/cmd/photo_cmds/photomerge_name_tests.rs @@ -73,7 +73,7 @@ fn blank(name: &str) -> Document { fn panorama_is_untitled_panorama_1_whatever_else_is_open() { let (_dir, paths) = source_files(); for open in [0, 1, 3] { - let mut s = Session::new(); + let mut s = crate::session(); for k in 0..open { s.add_document(blank(&format!("doc{k}")), None); } @@ -84,12 +84,12 @@ fn panorama_is_untitled_panorama_1_whatever_else_is_open() { #[test] fn a_second_panorama_gets_another_number() { let (_dir, paths) = source_files(); - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(merge(&mut s, &paths), "Untitled_Panorama-1"); // The first panorama is still open, so the next one takes the next free number. assert_eq!(merge(&mut s, &paths), "Untitled_Panorama-2"); // A free number below the taken ones is reused. - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(blank("Untitled_Panorama-2"), None); assert_eq!(merge(&mut s, &paths), "Untitled_Panorama-1"); } diff --git a/crates/engine/src/cmd/photo_cmds/tests.rs b/crates/engine-core/src/cmd/photo_cmds/tests.rs similarity index 97% rename from crates/engine/src/cmd/photo_cmds/tests.rs rename to crates/engine-core/src/cmd/photo_cmds/tests.rs index 0576a82516..23baa9f901 100644 --- a/crates/engine/src/cmd/photo_cmds/tests.rs +++ b/crates/engine-core/src/cmd/photo_cmds/tests.rs @@ -64,7 +64,7 @@ fn photomerge_open_documents_reposition_and_perspective() { for depth in [SampleType::U8, SampleType::U16, SampleType::F32] { let (sw, sh) = (520, 220); let sc = scene(sw, sh, 5); - let mut s = Session::new(); + let mut s = crate::session(); // Three overlapping crops, the middle one 15 % brighter (gain compensation). for (k, (x0, g)) in [(0usize, 1.0f32), (130, 1.15), (260, 1.0)].into_iter().enumerate() { s.add_document(doc_from(&format!("img{k}"), &crop(&sc, sw, x0, 10, 220, 200, g), 220, 200, depth), None); @@ -93,7 +93,7 @@ fn photomerge_open_documents_reposition_and_perspective() { // Perspective + no blending: plain layers, no masks. let (sw, sh) = (520, 220); let sc = scene(sw, sh, 8); - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 180].into_iter().enumerate() { s.add_document(doc_from(&format!("p{k}"), &crop(&sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None); } @@ -103,7 +103,7 @@ fn photomerge_open_documents_reposition_and_perspective() { assert!(d.layers.iter().all(|l| l.mask.is_none())); assert!((r["width"].as_i64().unwrap() - 440).abs() <= 8, "{r}"); assert!(s.execute("file.automate.photomerge", json!({"useOpenDocuments": true, "layout": "zigzag"})).is_err()); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute("file.automate.photomerge", json!({})).is_err()); } @@ -112,7 +112,7 @@ fn photomerge_cylindrical_with_fill() { let (sw, sh) = (900, 260); let sc = scene(sw, sh, 21); let f = 260.0f64; - let mut s = Session::new(); + let mut s = crate::session(); let (tw, th) = (260usize, 200usize); for (k, pan) in [-0.45f64, 0.0, 0.45].into_iter().enumerate() { let px: Vec<[f32; 4]> = (0..tw * th) @@ -154,7 +154,7 @@ fn hdr_merge_from_synthetic_exposures() { }) .collect() }; - let mut s = Session::new(); + let mut s = crate::session(); for (k, dt) in [0.25f32, 1.0, 4.0].into_iter().enumerate() { let mut d = doc_from(&format!("e{k}"), &shoot(dt), w, h, SampleType::U8); d.metadata.exif = Some(std::sync::Arc::new(exif::build(&exif::CameraInfo { @@ -217,7 +217,7 @@ fn scan_with_one_photo() -> Document { #[test] fn crop_and_straighten_keeps_duotone_inks() { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(scan_with_one_photo(), None); s.execute("image.mode.grayscale", json!({})).unwrap(); s.execute("image.mode.duotone", json!({"type": "duotone", "inks": [{"name": "Black", "color": [0, 0, 0]}, {"name": "Orange", "color": [255, 128, 0]}]})) @@ -234,7 +234,7 @@ fn crop_and_straighten_keeps_duotone_inks() { #[test] fn crop_and_straighten_disabled_for_indexed() { // Photoshop greys the command out for Indexed Color documents. - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(scan_with_one_photo(), None); s.execute("image.mode.indexedColor", json!({})).unwrap(); assert_eq!(s.documents()[0].doc.mode, ColorMode::Indexed); @@ -254,7 +254,7 @@ fn crop_and_straighten_only_processes_the_selection() { px[y * w + x0..y * w + x0 + pw].fill(c); } } - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc_from("scan", &px, w, h, SampleType::U8), None); s.execute("select.rect", json!({"x": 270, "y": 160, "width": 190, "height": 160})).unwrap(); let r = s.execute("file.automate.cropAndStraightenPhotos", json!({})).unwrap(); @@ -289,7 +289,7 @@ fn crop_and_straighten_skips_photos_between_selected_regions() { px[y * w + x0..y * w + x0 + pw].fill(c); } } - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc_from("scan", &px, w, h, SampleType::U8), None); s.execute("select.rect", json!({"x": 20, "y": 40, "width": 200, "height": 150})).unwrap(); s.execute("select.rect", json!({"x": 270, "y": 160, "width": 190, "height": 160, "mode": "add"})).unwrap(); @@ -314,7 +314,7 @@ fn crop_and_straighten_refuses_a_selection_under_half_coverage() { for y in 180..300 { px[y * w + 290..y * w + 440].fill([0.1, 0.2, 0.6, 1.0]); } - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc_from("scan", &px, w, h, SampleType::U8), None); let mut m = Surface::new(photocraft_color::PixelFormat::GRAY8); m.fill_rect(Rect::new(270, 160, 460, 320), &[0.3]); @@ -341,7 +341,7 @@ fn crop_and_straighten_makes_documents() { } } } - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc_from("scan", &px, w, h, SampleType::U16), None); assert!(s.is_enabled("file.automate.cropAndStraightenPhotos")); let r = s.execute("file.automate.cropAndStraightenPhotos", json!({})).unwrap(); @@ -364,7 +364,7 @@ fn crop_and_straighten_makes_documents() { fn photomerge_rejects_insufficient_memory_budget() { let (sw, sh) = (520, 220); let sc = scene(sw, sh, 5); - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 180].into_iter().enumerate() { s.add_document(doc_from(&format!("img{k}"), &crop(&sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None); } @@ -438,7 +438,7 @@ fn seam_blend_rejects_a_band_larger_than_its_budget() { fn photomerge_succeeds_with_a_large_enough_memory_budget() { let (sw, sh) = (520, 220); let sc = scene(sw, sh, 5); - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 180].into_iter().enumerate() { s.add_document(doc_from(&format!("img{k}"), &crop(&sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None); } @@ -468,7 +468,7 @@ fn photomerge_memory_budget_precedence_and_defaults() { #[test] fn photomerge_rejects_oversized_sparse_source_before_flattening() { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::new("sparse", Size::new(100_000, 100_000), ColorMode::Rgb, SampleType::U8), None); let err = load_sources(&s, &json!({"useOpenDocuments": true}), "file.automate.photomerge", None).err().expect("oversized canvas must be refused"); assert!(err.to_string().contains("too large to flatten"), "{err}"); @@ -517,7 +517,7 @@ fn photomerge_source_load_charges_the_document_and_both_flatten_surfaces() { fn photomerge_rejects_over_budget_sources_before_flattening() { let (sw, sh) = (520, 220); let sc = scene(sw, sh, 9); - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 180].into_iter().enumerate() { s.add_document(doc_from(&format!("img{k}"), &crop(&sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None); } @@ -538,7 +538,7 @@ fn photomerge_rejects_over_budget_sources_before_flattening() { fn photomerge_rejects_a_panorama_over_budget_after_loading() { let (sw, sh) = (520, 220); let sc = scene(sw, sh, 5); - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 180].into_iter().enumerate() { s.add_document(doc_from(&format!("img{k}"), &crop(&sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None); } @@ -562,7 +562,7 @@ fn photomerge_refuses_an_oversized_file_before_reading_or_decoding_it() { let path = dir.join("big.png"); // Not a valid image: reaching the decoder would report a format error instead. std::fs::write(&path, vec![0xAB; 4096]).unwrap(); - let err = load_sources(&Session::new(), &json!({"paths": [path.to_string_lossy()]}), cmd, Some(1024)) + let err = load_sources(&crate::session(), &json!({"paths": [path.to_string_lossy()]}), cmd, Some(1024)) .err() .expect("a file larger than the budget must be refused"); assert!(err.to_string().contains("was not read"), "{err}"); @@ -577,7 +577,7 @@ fn photomerge_refuses_an_oversized_file_before_reading_or_decoding_it() { fn photomerge_reports_a_missing_file_as_a_file_error_under_a_budget() { let cmd = "file.automate.photomerge"; let missing = temp_dir("missing-file").join("does-not-exist.png"); - let err = load_sources(&Session::new(), &json!({"paths": [missing.to_string_lossy()]}), cmd, Some(1 << 30)).err().expect("a missing file must fail"); + let err = load_sources(&crate::session(), &json!({"paths": [missing.to_string_lossy()]}), cmd, Some(1 << 30)).err().expect("a missing file must fail"); let message = err.to_string(); assert!(!message.contains("not enough memory"), "{message}"); assert!(message.contains("does-not-exist.png"), "{message}"); @@ -599,11 +599,11 @@ fn photomerge_file_source_is_charged_beside_the_sources_already_loaded() { // two bytes: alone it loads, but not beside an open source that keeps its surface. let budget = cost + png.len() + 2; - let alone = Session::new(); + let alone = crate::session(); let (loaded, _, _) = load_sources(&alone, &json!({"paths": [path.to_string_lossy()]}), cmd, Some(budget)).expect("the file alone fits"); assert_eq!(loaded.len(), 1); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(open, None); let err = load_sources(&s, &json!({"useOpenDocuments": true, "paths": [path.to_string_lossy()]}), cmd, Some(budget)) .err() @@ -617,7 +617,7 @@ fn photomerge_file_source_is_charged_beside_the_sources_already_loaded() { fn merge_to_hdr_pro_accepts_sources_without_the_photomerge_budget() { let (sw, sh) = (120, 90); let sc = scene(sw, sh, 11); - let mut s = Session::new(); + let mut s = crate::session(); for k in 0..2 { s.add_document(doc_from(&format!("exp{k}"), &crop(&sc, sw, 0, 0, sw, sh, 1.0 + k as f32), sw, sh, SampleType::U8), None); } @@ -636,7 +636,7 @@ fn photomerge_open_documents_ignores_the_folder() { let (sw, sh) = (520, 220); let sc = scene(sw, sh, 5); let open_two = |sc: &[[f32; 4]]| { - let mut s = Session::new(); + let mut s = crate::session(); for (k, x0) in [0usize, 180].into_iter().enumerate() { s.add_document(doc_from(&format!("o{k}"), &crop(sc, sw, x0, 10, 260, 200, 1.0), 260, 200, SampleType::U8), None); } diff --git a/crates/engine/src/cmd/pick_cmds.rs b/crates/engine-core/src/cmd/pick_cmds.rs similarity index 99% rename from crates/engine/src/cmd/pick_cmds.rs rename to crates/engine-core/src/cmd/pick_cmds.rs index 9d71d8abe1..4ed5bb7b05 100644 --- a/crates/engine/src/cmd/pick_cmds.rs +++ b/crates/engine-core/src/cmd/pick_cmds.rs @@ -235,7 +235,7 @@ mod tests { #[test] fn picks_topmost_layer_with_pixels() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; s.execute("layer.new.layer", json!({"name": "A"})).unwrap(); @@ -257,7 +257,7 @@ mod tests { /// Two filled squares: A at (0..10), B at (20..30), both in their own layers. fn two_squares() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); let mut ids = Vec::new(); for (name, x) in [("A", 0), ("B", 20)] { @@ -312,7 +312,7 @@ mod tests { fn a_click_on_an_artboard_picks_the_board_or_the_layers_on_it() { // #1531: an empty spot on a board picked the Background under it, so a Move-tool drag // there never moved the board. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; s.execute("layer.new.layer", json!({"name": "A"})).unwrap(); @@ -391,7 +391,7 @@ mod tests { #[test] fn auto_select_hits_a_type_layer_between_its_letters() { // #2370: a click in the gap between two glyphs picked the layer under the type. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; let mut text = None; @@ -421,7 +421,7 @@ mod tests { #[test] fn auto_select_hits_typed_text_in_a_gap_between_letters() { // The same through the type engine: "I I" leaves a transparent gap inside its bounds. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; let t = s.execute("type.create", json!({"text": "I I", "size": 48, "x": 20, "y": 70})).unwrap()["layer"].as_u64().unwrap(); @@ -492,7 +492,7 @@ mod tests { for (x, y) in [(-1e12, 5.0), (1e12, 1e12), (-0.5, -0.5), (40.0, 40.0)] { assert_eq!(s.execute("layer.pickAt", json!({"x": x, "y": y})).unwrap()["layer"], Value::Null, "({x}, {y})"); } - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute("layer.pickAt", json!({"x": 1, "y": 1})).is_err()); } @@ -500,7 +500,7 @@ mod tests { /// are neither picked there nor caught by a marquee that touches only the pasteboard. #[test] fn nothing_is_hit_off_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40, "background": "transparent"})).unwrap(); let fill = s.execute("layer.newFillLayer.solidColor", json!({"color": "#00ff00"})).unwrap()["layer"].as_u64().unwrap(); s.execute("layer.new.layer", json!({"name": "Off"})).unwrap(); @@ -524,7 +524,7 @@ mod tests { /// `LayerMask::value`), so the layer stays pickable; at full density it is clicked through. #[test] fn mask_density_is_honoured_when_picking() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; s.execute("layer.new.layer", json!({"name": "Red"})).unwrap(); diff --git a/crates/engine/src/cmd/plugin_cmds.rs b/crates/engine-core/src/cmd/plugin_cmds.rs similarity index 100% rename from crates/engine/src/cmd/plugin_cmds.rs rename to crates/engine-core/src/cmd/plugin_cmds.rs diff --git a/crates/engine/src/cmd/plugin_cmds/tests.rs b/crates/engine-core/src/cmd/plugin_cmds/tests.rs similarity index 90% rename from crates/engine/src/cmd/plugin_cmds/tests.rs rename to crates/engine-core/src/cmd/plugin_cmds/tests.rs index c949326f3f..eca01841f4 100644 --- a/crates/engine/src/cmd/plugin_cmds/tests.rs +++ b/crates/engine-core/src/cmd/plugin_cmds/tests.rs @@ -50,7 +50,7 @@ const GREY: &str = r#"(local $i i32) (i32.const 0)"#; fn doc(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 28, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("pattern", |doc, active| { @@ -87,10 +87,10 @@ fn select_partial(s: &mut Session) { #[test] fn example_invert_matches_builtin_invert_and_round_trips_the_registry() { // One test owns the example plug-in's id (the registry is process-wide). - let r = Session::new().execute("plugin.install", json!({"data": b64(INVERT)})).unwrap(); + let r = crate::session().execute("plugin.install", json!({"data": b64(INVERT)})).unwrap(); assert_eq!(r["id"], INVERT_ID); assert_eq!(r["name"], "Invert (WebAssembly)"); - let list = Session::new().execute("plugin.list", json!({})).unwrap(); + let list = crate::session().execute("plugin.list", json!({})).unwrap(); assert!(list["plugins"].as_array().unwrap().iter().any(|p| p["id"] == INVERT_ID)); for depth in [8, 16, 32] { @@ -128,10 +128,10 @@ fn example_invert_matches_builtin_invert_and_round_trips_the_registry() { std::fs::create_dir_all(&dir).unwrap(); let path = dir.join("invert.wasm"); std::fs::write(&path, INVERT).unwrap(); - let r = Session::new().execute("plugin.install", json!({"path": path.to_str().unwrap()})).unwrap(); + let r = crate::session().execute("plugin.install", json!({"path": path.to_str().unwrap()})).unwrap(); assert_eq!(r["source"], path.to_str().unwrap()); - assert!(Session::new().execute("plugin.install", json!({"path": path.to_str().unwrap(), "replace": false})).is_err()); - Session::new().execute("plugin.remove", json!({"id": INVERT_ID})).unwrap(); + assert!(crate::session().execute("plugin.install", json!({"path": path.to_str().unwrap(), "replace": false})).is_err()); + crate::session().execute("plugin.remove", json!({"id": INVERT_ID})).unwrap(); assert!(doc(8).execute("plugin.run", json!({"id": INVERT_ID})).is_err(), "removed"); std::fs::remove_dir_all(&dir).ok(); } @@ -145,7 +145,7 @@ fn installing_a_file_that_is_not_wasm_names_what_it_is() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("Old Plug-in.8bt"); std::fs::write(&path, b"MZ\x90\x00\x03\0").unwrap(); - let e = Session::new().execute("plugin.install", json!({"path": path.to_str().unwrap()})).unwrap_err(); + let e = crate::session().execute("plugin.install", json!({"path": path.to_str().unwrap()})).unwrap_err(); let msg = e.to_string(); assert!(msg.contains("Windows") && msg.contains("8bf"), "{msg}"); assert!(msg.contains("WebAssembly"), "{msg}"); @@ -156,8 +156,8 @@ fn installing_a_file_that_is_not_wasm_names_what_it_is() { #[test] fn params_are_validated_and_passed() { let bytes = wat_plugin("test.cmds.grey", r#"{"amount":{"type":"number","min":0,"max":1,"default":1}}"#, GREY); - Session::new().execute("plugin.install", json!({"data": b64(&bytes)})).unwrap(); - let list = Session::new().execute("plugin.list", json!({})).unwrap(); + crate::session().execute("plugin.install", json!({"data": b64(&bytes)})).unwrap(); + let list = crate::session().execute("plugin.list", json!({})).unwrap(); let me = list["plugins"].as_array().unwrap().iter().find(|p| p["id"] == "test.cmds.grey").unwrap().clone(); assert_eq!(me["params"], r#"{"amount":0..1=1}"#); let mut s = doc(16); @@ -172,7 +172,7 @@ fn params_are_validated_and_passed() { s.execute("plugin.run", json!({"id": "test.cmds.grey", "amount": 0.5})).unwrap(); s.execute("plugin.run", json!({"id": "test.cmds.grey", "params": {"amount": 0.25}})).unwrap(); assert!((pixels(&s)[0] - 0.5).abs() < 1e-4); - Session::new().execute("plugin.remove", json!({"id": "test.cmds.grey"})).unwrap(); + crate::session().execute("plugin.remove", json!({"id": "test.cmds.grey"})).unwrap(); } /// #7524: a reduced live preview divides the plug-in's `"unit": "px"` params by the reduction, in @@ -186,8 +186,8 @@ fn preview_scales_the_plugin_pixel_params() { r#""radius":{"type":"int","min":2,"max":50,"default":10,"unit":"px"},"#, r#""size":{"type":"number","min":0,"max":100,"default":50}}"# ); - Session::new().execute("plugin.install", json!({"data": b64(&wat_plugin(id, params, GREY))})).unwrap(); - let list = Session::new().execute("plugin.list", json!({})).unwrap(); + crate::session().execute("plugin.install", json!({"data": b64(&wat_plugin(id, params, GREY))})).unwrap(); + let list = crate::session().execute("plugin.list", json!({})).unwrap(); let me = list["plugins"].as_array().unwrap().iter().find(|p| p["id"] == id).unwrap().clone(); assert_eq!(me["paramsSchema"]["amount"]["unit"], "px"); @@ -228,14 +228,14 @@ fn preview_scales_the_plugin_pixel_params() { assert_eq!(preview_factor(&json!({"id": id, "params": {"radius": 3}}), 4), 1); assert_eq!(preview_factor(&json!({"id": id}), 8), 5, "the default radius"); assert_eq!(preview_factor(&json!({"id": "test.cmds.none", "radius": 3}), 4), 4); - Session::new().execute("plugin.remove", json!({"id": id})).unwrap(); + crate::session().execute("plugin.remove", json!({"id": id})).unwrap(); } #[test] fn locked_layers_refuse_plugin_filters() { // Like built-in filters: locked pixels (or Lock All) refuse the run with no undo step. let id = "test.cmds.locks"; - Session::new().execute("plugin.install", json!({"data": b64(&wat_plugin(id, "{}", GREY))})).unwrap(); + crate::session().execute("plugin.install", json!({"data": b64(&wat_plugin(id, "{}", GREY))})).unwrap(); for lock_all in [false, true] { let mut s = doc(16); let layer = s.active().unwrap().active_layer.unwrap(); @@ -278,7 +278,7 @@ fn locked_layers_refuse_plugin_filters() { assert!((a[0] - 0.5).abs() < 1e-3, "colour changed: {a:?}"); } } - Session::new().execute("plugin.remove", json!({"id": id})).unwrap(); + crate::session().execute("plugin.remove", json!({"id": id})).unwrap(); } #[test] @@ -288,7 +288,7 @@ fn hostile_plugins_fail_without_touching_the_document() { ("test.cmds.spin", "(loop $l (br $l)) (i32.const 0)"), ("test.cmds.oob", "(i32.store (i32.const -4) (i32.const 1)) (i32.const 0)"), ] { - Session::new().execute("plugin.install", json!({"data": b64(&wat_plugin(id, "{}", body))})).unwrap(); + crate::session().execute("plugin.install", json!({"data": b64(&wat_plugin(id, "{}", body))})).unwrap(); let mut s = doc(8); let before = pixels(&s); let undo_before = s.active().unwrap().history.can_undo(); @@ -297,7 +297,7 @@ fn hostile_plugins_fail_without_touching_the_document() { assert!(t.elapsed() < std::time::Duration::from_secs(10), "{id} took {:?}", t.elapsed()); assert_eq!(pixels(&s), before, "{id}"); assert_eq!(s.active().unwrap().history.can_undo(), undo_before, "{id}: no undo step"); - Session::new().execute("plugin.remove", json!({"id": id})).unwrap(); + crate::session().execute("plugin.remove", json!({"id": id})).unwrap(); } } @@ -326,7 +326,7 @@ fn bad_params_are_errors_not_panics() { assert!(s.execute(cmd, p.clone()).is_err(), "{cmd} {p}"); } // No document: running is disabled. - assert!(Session::new().execute("plugin.run", json!({"id": "x"})).is_err()); + assert!(crate::session().execute("plugin.run", json!({"id": "x"})).is_err()); } #[test] @@ -335,7 +335,7 @@ fn preference_folder_is_loaded() { std::fs::create_dir_all(&dir).unwrap(); std::fs::write(dir.join("grey.wasm"), wat_plugin("test.cmds.folder", "{}", GREY)).unwrap(); std::fs::write(dir.join("broken.wasm"), b"nope").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); // Off by default: setting the folder alone loads nothing. s.execute("prefs.set", json!({"path": "plugIns.additionalPluginsFolder", "value": dir.to_str().unwrap()})).unwrap(); assert!(registry::get("test.cmds.folder").is_none()); @@ -355,8 +355,8 @@ fn bitmap_documents_refuse_plugin_filters_but_keep_plugin_management() { // #10484: Photoshop 2025 refuses its filter plug-in modules (Solarize, Clouds, Average) on a // Bitmap document and runs them on a Grayscale one. Installing, listing and removing stay. let id = "test.cmds.bitmap"; - Session::new().execute("plugin.install", json!({"data": b64(&wat_plugin(id, "{}", GREY))})).unwrap(); - let mut s = Session::new(); + crate::session().execute("plugin.install", json!({"data": b64(&wat_plugin(id, "{}", GREY))})).unwrap(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 28, "mode": "grayscale", "background": "white"})).unwrap(); s.execute("image.mode.bitmap", json!({"method": "threshold"})).unwrap(); let before = pixels(&s); diff --git a/crates/engine/src/cmd/preset_import_cmds.rs b/crates/engine-core/src/cmd/preset_import_cmds.rs similarity index 98% rename from crates/engine/src/cmd/preset_import_cmds.rs rename to crates/engine-core/src/cmd/preset_import_cmds.rs index 02e115630b..a312f1efb3 100644 --- a/crates/engine/src/cmd/preset_import_cmds.rs +++ b/crates/engine-core/src/cmd/preset_import_cmds.rs @@ -492,7 +492,7 @@ mod tests { }; for (opacity, expected) in [(0, 0.01), (37, 0.37)] { let abr = craft_psd::abr::write_v6_folders(2, &[], &[], &[preset(opacity)], &[vec![]], true).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("brush.presets.importAbr", json!({"data": photocraft_paint::tile::b64_encode(&abr), "select": true})).unwrap(); assert!((s.tools.brush.opacity - expected).abs() < 1e-6, "{opacity}: {}", s.tools.brush.opacity); } @@ -500,7 +500,7 @@ mod tests { #[test] fn import_adds_a_group_and_paints() { - let mut s = Session::new(); + let mut s = crate::session(); let before = s.tools.presets.len(); let data = photocraft_paint::tile::b64_encode(&abr_v2()); let r = s.execute("brush.presets.importAbr", json!({"data": data, "group": "Legacy", "select": true})).unwrap(); @@ -534,7 +534,7 @@ mod tests { /// in ones included: the new brushes become "Kit (2)", "Kit (3)"… Only `replace` drops them (#10640). #[test] fn reimport_keeps_the_groups_brushes_unless_replace() { - let mut s = Session::new(); + let mut s = crate::session(); let data = photocraft_paint::tile::b64_encode(&abr_v2()); let builtin = s.tools.presets.iter().filter(|p| p.builtin).count(); s.execute("brush.presets.importAbr", json!({"data": data, "group": "Kit"})).unwrap(); @@ -566,7 +566,7 @@ mod tests { #[test] fn bad_params_fail_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); let n = s.tools.presets.len(); for p in [ json!({}), @@ -601,7 +601,7 @@ mod tests { }) .collect(); let data = photocraft_paint::tile::b64_encode(&write(&gradients)); - let mut s = Session::new(); + let mut s = crate::session(); // Re-importing over the group replaces it (`replace`, #10640), so it keeps the same names. for _ in 0..2 { let result = s.execute("gradient.presets.importGrd", json!({"data": data, "group": "Duplicates", "replace": true})).unwrap(); @@ -637,7 +637,7 @@ mod tests { ..Default::default() }]; let data = photocraft_paint::tile::b64_encode(&write(&gradients)); - let mut s = Session::new(); + let mut s = crate::session(); let first = s.execute("gradient.presets.importGrd", json!({"data": data, "group": "Sky"})).unwrap(); assert_eq!(first["imported"], json!(["Sunset"])); let second = s.execute("gradient.presets.importGrd", json!({"data": data, "group": "Sky"})).unwrap(); @@ -664,7 +664,7 @@ mod tests { ..Default::default() }) .collect(); - let mut s = Session::new(); + let mut s = crate::session(); let result = s .execute( "gradient.presets.importGrd", @@ -700,7 +700,7 @@ mod tests { }, GrdGradient { name: "Static".into(), noise: true, ..Default::default() }, ]; - let mut s = Session::new(); + let mut s = crate::session(); let data = photocraft_paint::tile::b64_encode(&write(&grads)); let r = s.execute("gradient.presets.importGrd", json!({"data": data, "group": "Fire"})).unwrap(); assert_eq!(r["imported"], json!(["Ember"])); @@ -753,7 +753,7 @@ mod tests { #[test] fn imports_an_image_as_a_brush_tip() { use photocraft_paint::TipShape; - let mut s = Session::new(); + let mut s = crate::session(); let data = photocraft_paint::tile::b64_encode(&stamp_png16()); let r = s.execute("brush.presets.importImage", json!({"data": data, "fileName": "Stamp.png"})).unwrap(); assert_eq!(r, json!({"name": "Stamp", "width": 10, "height": 6}), "cropped to the dark block"); @@ -784,7 +784,7 @@ mod tests { #[test] fn image_brush_import_fails_cleanly() { - let mut s = Session::new(); + let mut s = crate::session(); let white = photocraft_codecs::Image::from_u8(4, 4, photocraft_codecs::ChannelLayout::Gray, vec![255; 16]).unwrap(); let white = photocraft_paint::tile::b64_encode(&photocraft_codecs::encode(&white, photocraft_codecs::Format::Png, &Default::default()).unwrap()); let n = s.tools.presets.len(); @@ -810,7 +810,7 @@ mod tests { fn repeated_brush_names_are_numbered_in_linear_time() { let (tx, rx) = std::sync::mpsc::channel(); std::thread::spawn(move || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("brush.presets.save", json!({"name": "9 PX ROUND 3"})).unwrap(); let round = LegacyBrush { name: String::new(), @@ -836,7 +836,7 @@ mod tests { #[test] fn repeated_brush_names_take_the_first_free_number() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("brush.presets.save", json!({"name": "speckle 3"})).unwrap(); let tip = AbrSample { id: String::new(), width: 6, height: 4, depth: 8, data: vec![255; 24] }; let brush = |name: &str| LegacyBrush { name: name.into(), spacing: 25, anti_alias: true, tip: LegacyTip::Sampled(tip.clone()) }; @@ -862,7 +862,7 @@ mod tests { // A sparse file between the two caps: refused as a .grd, which is checked before reading. let big = dir.join("big.grd"); std::fs::File::create(&big).unwrap().set_len(MAX_FILE_BYTES + 1).unwrap(); - let err = Session::new().execute("gradient.presets.importGrd", json!({"path": big.to_string_lossy()})).unwrap_err(); + let err = crate::session().execute("gradient.presets.importGrd", json!({"path": big.to_string_lossy()})).unwrap_err(); assert!(err.to_string().contains("too large"), "{err}"); let data = json!({"data": "A".repeat(16)}); assert!(file_bytes_limited(&data, "t", "f", 12).is_ok()); diff --git a/crates/engine/src/cmd/print_cmds.rs b/crates/engine-core/src/cmd/print_cmds.rs similarity index 100% rename from crates/engine/src/cmd/print_cmds.rs rename to crates/engine-core/src/cmd/print_cmds.rs diff --git a/crates/engine/src/cmd/print_cmds/package_clash_name_tests.rs b/crates/engine-core/src/cmd/print_cmds/package_clash_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/print_cmds/package_clash_name_tests.rs rename to crates/engine-core/src/cmd/print_cmds/package_clash_name_tests.rs index 52aa47952b..76c5440d2a 100644 --- a/crates/engine/src/cmd/print_cmds/package_clash_name_tests.rs +++ b/crates/engine-core/src/cmd/print_cmds/package_clash_name_tests.rs @@ -14,7 +14,7 @@ fn tmp(name: &str) -> String { fn write_link(dir: &str, sub: &str, name: &str, colour: &str) -> String { std::fs::create_dir_all(format!("{dir}/{sub}")).unwrap(); let path = format!("{dir}/{sub}/{name}"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 4, "height": 4, "background": colour})).unwrap(); let doc = src.active().unwrap().doc.clone(); // A name without an extension has no format of its own: write the PNG bytes by hand. @@ -25,7 +25,7 @@ fn write_link(dir: &str, sub: &str, name: &str, colour: &str) -> String { } fn open_session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 90, "name": "Clash.psd", "background": "#3366cc"})).unwrap(); s } diff --git a/crates/engine/src/cmd/print_cmds/package_layer_rename_tests.rs b/crates/engine-core/src/cmd/print_cmds/package_layer_rename_tests.rs similarity index 98% rename from crates/engine/src/cmd/print_cmds/package_layer_rename_tests.rs rename to crates/engine-core/src/cmd/print_cmds/package_layer_rename_tests.rs index b4a1cad7f0..ef1b036643 100644 --- a/crates/engine/src/cmd/print_cmds/package_layer_rename_tests.rs +++ b/crates/engine-core/src/cmd/print_cmds/package_layer_rename_tests.rs @@ -30,12 +30,12 @@ fn package_the_document(tag: &str) -> (String, Session, serde_json::Value) { std::fs::create_dir_all(&d).unwrap(); d.to_string_lossy().replace('\\', "/") }; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 90, "name": "Print Me.psd", "background": "#3366cc"})).unwrap(); let path_of = |sub: &str, colour: &str| { std::fs::create_dir_all(format!("{dir}/{sub}")).unwrap(); let link = format!("{dir}/{sub}/logo.png"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 4, "height": 4, "background": colour})).unwrap(); crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); link diff --git a/crates/engine/src/cmd/print_cmds/paths_export_document_bounds_tests.rs b/crates/engine-core/src/cmd/print_cmds/paths_export_document_bounds_tests.rs similarity index 97% rename from crates/engine/src/cmd/print_cmds/paths_export_document_bounds_tests.rs rename to crates/engine-core/src/cmd/print_cmds/paths_export_document_bounds_tests.rs index 14ebb04403..db621a0fce 100644 --- a/crates/engine/src/cmd/print_cmds/paths_export_document_bounds_tests.rs +++ b/crates/engine-core/src/cmd/print_cmds/paths_export_document_bounds_tests.rs @@ -10,7 +10,7 @@ const BEGIN: &str = "%Adobe_Photoshop_Path_Begin"; /// A 300 x 200 document at `dpi` without any path. fn plain(dpi: f32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 200, "background": "#ffffff", "name": "Bounds.psd"})).unwrap(); s.edit("resolution", |d, _| { d.resolution_dpi = dpi; @@ -83,13 +83,13 @@ fn document_bounds_writes_the_file_and_reports_no_paths() { #[test] fn the_entry_is_enabled_with_or_without_paths() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled(CMD), "greyed without a document"); s.execute("file.new", json!({"width": 300, "height": 200})).unwrap(); assert!(s.is_enabled(CMD), "a document without paths"); add_path(&mut s, "Rect A"); assert!(s.is_enabled(CMD), "a document with a path"); - let mut bitmap = Session::new(); + let mut bitmap = crate::session(); bitmap.execute("file.new", json!({"width": 300, "height": 200, "mode": "gray", "background": "#ffffff"})).unwrap(); bitmap.execute("image.mode.bitmap", json!({})).unwrap(); assert!(bitmap.is_enabled(CMD), "a Bitmap-mode document"); diff --git a/crates/engine/src/cmd/print_cmds/paths_export_path_blocks_tests.rs b/crates/engine-core/src/cmd/print_cmds/paths_export_path_blocks_tests.rs similarity index 99% rename from crates/engine/src/cmd/print_cmds/paths_export_path_blocks_tests.rs rename to crates/engine-core/src/cmd/print_cmds/paths_export_path_blocks_tests.rs index f1f9b77a95..924218d3d3 100644 --- a/crates/engine/src/cmd/print_cmds/paths_export_path_blocks_tests.rs +++ b/crates/engine-core/src/cmd/print_cmds/paths_export_path_blocks_tests.rs @@ -34,7 +34,7 @@ fn circle(cx: f64, cy: f64, r: f64) -> Subpath { /// A 300 x 200 px document at 72 ppi holding each `(name, subpaths)` pair as a saved path. pub(super) fn doc_with(paths: Vec<(&str, Vec)>) -> Document { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 200, "background": "#ffffff", "name": "Blocks.psd"})).unwrap(); s.edit("paths", |d, _| { d.resolution_dpi = 72.0; diff --git a/crates/engine/src/cmd/print_cmds/paths_export_smooth_operators_tests.rs b/crates/engine-core/src/cmd/print_cmds/paths_export_smooth_operators_tests.rs similarity index 100% rename from crates/engine/src/cmd/print_cmds/paths_export_smooth_operators_tests.rs rename to crates/engine-core/src/cmd/print_cmds/paths_export_smooth_operators_tests.rs diff --git a/crates/engine/src/cmd/print_cmds/tests.rs b/crates/engine-core/src/cmd/print_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/print_cmds/tests.rs rename to crates/engine-core/src/cmd/print_cmds/tests.rs index 1d35fc3cc4..626ab60a63 100644 --- a/crates/engine/src/cmd/print_cmds/tests.rs +++ b/crates/engine-core/src/cmd/print_cmds/tests.rs @@ -73,7 +73,7 @@ fn tmp(name: &str) -> String { } fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 150, "mode": mode, "depth": depth, "name": "Print Me.psd", "background": "#3366cc"})).unwrap(); s } @@ -344,7 +344,7 @@ fn test_printers() -> PrinterSource { #[test] fn printer_commands_answer_without_a_document_and_reject_bad_settings() { - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(test_printers()); let r = s.execute("file.print.printers", json!({})).unwrap(); assert_eq!(r["supported"], cfg!(windows)); @@ -423,7 +423,7 @@ fn only_the_same_paper_the_other_way_round_is_turned() { /// the error is the same with or without one. #[test] fn printer_page_refuses_an_unknown_orientation() { - let mut s = Session::new(); + let mut s = crate::session(); for bad in [json!("sideways"), json!(2), json!(true)] { let e = s.execute("file.print.page", json!({"printer": "Anything", "orientation": bad})).unwrap_err().to_string(); assert!(e.contains("orientation"), "{bad}: {e}"); @@ -531,7 +531,7 @@ fn print_one_copy_repeats_the_last_settings() { fn package_copies_links_and_relinks() { let dir = tmp("package"); let link = format!("{dir}/art.png"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 20, "height": 20, "background": "#ff0000"})).unwrap(); crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); let mut s = session("rgb", 8); @@ -580,7 +580,7 @@ fn package_never_overwrites_one_link_copy_with_another() { for (sub, name, colour) in [("a", "x.png", "#ff0000"), ("b", "2-x.png", "#00ff00"), ("c", "x.png", "#0000ff")] { std::fs::create_dir_all(format!("{dir}/{sub}")).unwrap(); let link = format!("{dir}/{sub}/{name}"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 4, "height": 4, "background": colour})).unwrap(); crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); s.execute("file.placeLinked", json!({"path": link})).unwrap(); @@ -602,7 +602,7 @@ fn package_never_overwrites_one_link_copy_with_another() { fn package_keeps_files_already_in_links() { let dir = tmp("package-again"); let link = format!("{dir}/art.png"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 4, "height": 4, "background": "#ff0000"})).unwrap(); crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); let mut s = session("rgb", 8); @@ -624,7 +624,7 @@ fn package_keeps_files_already_in_links() { fn package_lists_a_missing_link_once() { let dir = tmp("package-missing-once"); let link = format!("{dir}/gone.png"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); let mut s = session("rgb", 8); @@ -776,7 +776,7 @@ fn spool_transport_streams_pdf_and_propagates_refusal() { #[test] fn disabled_printing_never_spools() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); super::disable_printing(); assert!(super::printing_disabled()); @@ -804,7 +804,7 @@ fn disabled_printing_never_spools() { #[test] fn printers_lists_the_spooler_destinations_without_a_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(test_printers()); let r = s.execute("file.printers", json!({})).unwrap(); assert_eq!(r["printers"], json!([{"name": "Studio", "default": false}, {"name": "Office", "default": true}])); @@ -828,7 +828,7 @@ fn printer_listings_enter_the_spooler_one_thread_at_a_time() { .map(|i| { let (inside, most, start) = (Arc::clone(&inside), Arc::clone(&most), Arc::clone(&start)); std::thread::spawn(move || { - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(Arc::new(move || { let now = inside.fetch_add(1, Ordering::SeqCst) + 1; most.fetch_max(now, Ordering::SeqCst); @@ -857,7 +857,7 @@ fn a_panic_inside_the_spooler_does_not_block_later_callers() { let panicked = std::thread::spawn(|| with_spooler::<()>(|| panic!("a driver call panicked"))).join(); assert!(panicked.is_err()); assert_eq!(with_spooler(|| 7), 7); - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(test_printers()); assert_eq!(s.execute("file.printers", json!({})).unwrap()["default"], "Office"); } @@ -868,7 +868,7 @@ fn a_panic_inside_the_spooler_does_not_block_later_callers() { fn a_thread_holding_the_spooler_does_not_wait_for_itself() { let (done, finished) = std::sync::mpsc::channel(); std::thread::spawn(move || { - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(test_printers()); // Inside one outer hold, so no other test takes the lock between the calls. let answers = with_spooler(|| { @@ -892,7 +892,7 @@ fn listings_without_waiting_return_the_last_lists_while_the_spooler_is_busy() { use std::sync::{Arc, mpsc}; let asked = Arc::new(AtomicUsize::new(0)); let counted = Arc::clone(&asked); - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(Arc::new(move || { counted.fetch_add(1, Ordering::SeqCst); vec![craft_print::Printer { name: "Office".into(), default: true, two_sided: None, description: String::new() }] @@ -902,7 +902,7 @@ fn listings_without_waiting_return_the_last_lists_while_the_spooler_is_busy() { let released = Arc::new(AtomicBool::new(false)); let holder = { let released = Arc::clone(&released); - let mut lister = Session::new(); + let mut lister = crate::session(); lister.printer_source = s.printer_source.clone(); std::thread::spawn(move || { with_spooler(|| { @@ -942,7 +942,7 @@ fn uncached_listings_do_not_wait(cache_other: bool) { use std::sync::{Arc, mpsc}; let asked = Arc::new(AtomicUsize::new(0)); let counted = Arc::clone(&asked); - let mut s = Session::new(); + let mut s = crate::session(); s.printer_source = Some(Arc::new(move || { counted.fetch_add(1, Ordering::SeqCst); vec![craft_print::Printer { name: "Proofing".into(), default: true, two_sided: None, description: String::new() }] @@ -954,7 +954,7 @@ fn uncached_listings_do_not_wait(cache_other: bool) { let holder = std::thread::spawn(move || { with_spooler(|| { if cache_other { - let mut other = Session::new(); + let mut other = crate::session(); other.printer_source = Some(test_printers()); list_system_printers(&other); let _ = list_rgb_printers(&other); @@ -1365,7 +1365,7 @@ fn the_windows_pdf_check_is_a_no_op_elsewhere() { /// A 500 × 1000 pt document (72 ppi) on A3 (841.89 × 1190.55 pt): its height sets the fit. fn a3_layout(extra: Value) -> Result { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 500, "height": 1000, "resolution": 72})).unwrap(); let mut p = json!({"paper": "a3", "scaleToFit": true}); if let (Some(p), Some(extra)) = (p.as_object_mut(), extra.as_object()) { @@ -1431,7 +1431,7 @@ fn emulsion_down_fits_the_mirrored_printable_area() { // 10 pt on the left, 40 pt on the right of the sheet as the driver sees it. The page is // mirrored as it prints, so the image box (before mirroring) must fit the mirror image. // A wide image, so the printable width sets the fit. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1000, "height": 500, "resolution": 72})).unwrap(); let p = json!({"paper": "a3", "scaleToFit": true, "printable": [10.0, 0.0, pw - 50.0, ph], "emulsionDown": true}); let l = layout(&s.active().unwrap().doc, &p, "file.print").unwrap(); @@ -1451,7 +1451,7 @@ fn a_native_print_drops_a_printable_area_the_driver_did_not_give() { #[test] fn a_print_uses_the_printable_area_but_does_not_remember_it() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 500, "height": 1000, "resolution": 72})).unwrap(); let r = s.execute("file.print", json!({"paper": "a3", "scaleToFit": true, "printable": [0.0, 0.0, 842.29, 1191.14], "dryRun": true})).unwrap(); assert!((r["scale"].as_f64().unwrap() - 119.055).abs() < 1e-6, "{r}"); @@ -1462,7 +1462,7 @@ fn a_print_uses_the_printable_area_but_does_not_remember_it() { #[test] fn a_rejected_printable_area_fails_the_print_and_changes_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 500, "height": 1000, "resolution": 72})).unwrap(); s.execute("file.print", json!({"paper": "a3", "scale": 50, "dryRun": true})).unwrap(); let before = (last_print(&s), s.prefs.get().dialogs.get(REMEMBERED).cloned(), s.active().unwrap().doc.clone()); @@ -1485,7 +1485,7 @@ fn a_rejected_printable_area_fails_the_print_and_changes_nothing() { fn package_of_a_document_named_after_a_windows_device_is_written() { // On Windows a folder named `nul` is the NUL device: the save failed with "path not found". let dir = tmp("package-device-name"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "name": "nul.psd"})).unwrap(); let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap(); assert_eq!(r["folder"].as_str().unwrap(), format!("{dir}/pkg/nul_")); diff --git a/crates/engine/src/cmd/print_cmds/windows_marks.rs b/crates/engine-core/src/cmd/print_cmds/windows_marks.rs similarity index 100% rename from crates/engine/src/cmd/print_cmds/windows_marks.rs rename to crates/engine-core/src/cmd/print_cmds/windows_marks.rs diff --git a/crates/engine/src/cmd/rasterize_style_cmds.rs b/crates/engine-core/src/cmd/rasterize_style_cmds.rs similarity index 100% rename from crates/engine/src/cmd/rasterize_style_cmds.rs rename to crates/engine-core/src/cmd/rasterize_style_cmds.rs diff --git a/crates/engine/src/cmd/rasterize_style_cmds/tests.rs b/crates/engine-core/src/cmd/rasterize_style_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/rasterize_style_cmds/tests.rs rename to crates/engine-core/src/cmd/rasterize_style_cmds/tests.rs index 6174573ff7..f13186f347 100644 --- a/crates/engine/src/cmd/rasterize_style_cmds/tests.rs +++ b/crates/engine-core/src/cmd/rasterize_style_cmds/tests.rs @@ -30,7 +30,7 @@ fn tolerance(depth: u32) -> f32 { /// A white Background and a red rectangle (partly off the right edge of the canvas) with a /// Normal-mode drop shadow, outer glow, inner shadow, outside stroke and a half colour overlay. fn scene(depth: u32) -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); let id = s.execute("layer.new.layer", json!({"name": "a"})).unwrap()["layer"].as_u64().unwrap(); s.execute("select.rect", json!({"x": 14, "y": 10, "width": 56, "height": 20})).unwrap(); @@ -97,7 +97,7 @@ fn keeps_the_pixels_past_the_canvas() { #[test] fn rasterizes_fill_content_first() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({"color": "#3366cc"})).unwrap(); let id = s.active().unwrap().active_layer.unwrap().0; @@ -147,7 +147,7 @@ fn several_selected_layers_bake_in_one_step() { #[test] fn disabled_and_bad_params_fail_gracefully() { - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute(ID, json!({})).is_err(), "no document"); let (mut s, id) = scene(8); let bg = doc(&s).layers[0].id.0; diff --git a/crates/engine/src/cmd/redeye_cmds.rs b/crates/engine-core/src/cmd/redeye_cmds.rs similarity index 99% rename from crates/engine/src/cmd/redeye_cmds.rs rename to crates/engine-core/src/cmd/redeye_cmds.rs index 305b094846..4024abdf96 100644 --- a/crates/engine/src/cmd/redeye_cmds.rs +++ b/crates/engine-core/src/cmd/redeye_cmds.rs @@ -302,7 +302,7 @@ mod tests { const DEPTHS: [u64; 3] = [8, 16, 32]; fn session(w: u32, h: u32, depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "mode": mode})).unwrap(); s } @@ -394,7 +394,7 @@ mod tests { #[test] fn disabled_without_a_paintable_target() { - let s = Session::new(); + let s = crate::session(); assert!(!s.is_enabled("paint.redEye")); let mut s = session(32, 32, 8, "rgb"); assert!(s.is_enabled("paint.redEye")); diff --git a/crates/engine/src/cmd/redeye_color_mode_tests.rs b/crates/engine-core/src/cmd/redeye_color_mode_tests.rs similarity index 99% rename from crates/engine/src/cmd/redeye_color_mode_tests.rs rename to crates/engine-core/src/cmd/redeye_color_mode_tests.rs index c1189211ff..4e050690a8 100644 --- a/crates/engine/src/cmd/redeye_color_mode_tests.rs +++ b/crates/engine-core/src/cmd/redeye_color_mode_tests.rs @@ -8,7 +8,7 @@ use serde_json::{Value, json}; use super::*; fn new_doc(mode: &str, depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "mode": mode, "depth": depth})).unwrap(); s } diff --git a/crates/engine/src/cmd/redeye_history_state_tests.rs b/crates/engine-core/src/cmd/redeye_history_state_tests.rs similarity index 99% rename from crates/engine/src/cmd/redeye_history_state_tests.rs rename to crates/engine-core/src/cmd/redeye_history_state_tests.rs index 20fb8c7a6b..150a21802a 100644 --- a/crates/engine/src/cmd/redeye_history_state_tests.rs +++ b/crates/engine-core/src/cmd/redeye_history_state_tests.rs @@ -12,7 +12,7 @@ fn session(mode: &str) -> Session { } fn session_at(mode: &str, depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "mode": mode, "depth": depth})).unwrap(); s } diff --git a/crates/engine/src/cmd/redeye_outside_selection_tests.rs b/crates/engine-core/src/cmd/redeye_outside_selection_tests.rs similarity index 99% rename from crates/engine/src/cmd/redeye_outside_selection_tests.rs rename to crates/engine-core/src/cmd/redeye_outside_selection_tests.rs index 8bc173e223..1d9ca30efa 100644 --- a/crates/engine/src/cmd/redeye_outside_selection_tests.rs +++ b/crates/engine-core/src/cmd/redeye_outside_selection_tests.rs @@ -8,7 +8,7 @@ use super::*; /// 800 × 600 RGB/8 with eye A at (200, 200) and eye B at (500, 200): a white disc of radius 40 /// with a red pupil (210, 40, 40) of radius 30, on a skin tone. fn eyes() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "mode": "rgb", "depth": 8})).unwrap(); s.execute("edit.fill", json!({"color": "#c08a68"})).unwrap(); for cx in [200, 500] { diff --git a/crates/engine/src/cmd/render_cmds.rs b/crates/engine-core/src/cmd/render_cmds.rs similarity index 99% rename from crates/engine/src/cmd/render_cmds.rs rename to crates/engine-core/src/cmd/render_cmds.rs index a6ee1585ea..1fbea15fb9 100644 --- a/crates/engine/src/cmd/render_cmds.rs +++ b/crates/engine-core/src/cmd/render_cmds.rs @@ -240,7 +240,7 @@ mod tests { use super::*; fn session(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 160, "height": 120, "depth": depth})).unwrap(); assert_eq!(Some(s.active().unwrap().doc.depth), crate::document_preset_cmds::sample_type(depth)); s.execute("layer.new.layer", json!({})).unwrap(); @@ -321,7 +321,7 @@ mod tests { #[test] fn works_in_cmyk_and_gray() { for mode in ["cmyk", "grayscale", "lab"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 96, "mode": mode})).unwrap(); let r = s.execute("filter.render.pictureFrame", json!({"frame": 13, "newLayer": true})).unwrap_or_else(|e| panic!("{mode}: {e}")); assert!(r["bounds"].is_array(), "{mode}"); @@ -377,7 +377,7 @@ mod tests { #[test] #[ignore] fn bench_24mp() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); for (id, p) in [ diff --git a/crates/engine/src/cmd/retouch_cmds.rs b/crates/engine-core/src/cmd/retouch_cmds.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds.rs rename to crates/engine-core/src/cmd/retouch_cmds.rs diff --git a/crates/engine/src/cmd/retouch_cmds/art_history.rs b/crates/engine-core/src/cmd/retouch_cmds/art_history.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/art_history.rs rename to crates/engine-core/src/cmd/retouch_cmds/art_history.rs index 0622bf0ed0..c20a26e165 100644 --- a/crates/engine/src/cmd/retouch_cmds/art_history.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/art_history.rs @@ -337,7 +337,7 @@ mod tests { use serde_json::json; fn session(w: u32, h: u32, depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "mode": mode})).unwrap(); s } @@ -573,7 +573,7 @@ mod tests { let many: Vec<[f32; 2]> = (0..10_000).map(|i| [i as f32, 0.0]).collect(); assert!(s.execute("paint.artHistoryBrush", json!({"points": many})).unwrap_err().to_string().contains("too many points")); assert!(s.execute("paint.artHistoryBrush", json!({"points": [[5, 5]], "size": 8000})).unwrap_err().to_string().contains("stroke too large")); - assert!(!Session::new().is_enabled("paint.artHistoryBrush")); + assert!(!crate::session().is_enabled("paint.artHistoryBrush")); assert!(crate::commands::find("paint.artHistoryBrush").is_some()); } @@ -601,11 +601,12 @@ mod tests { #[test] fn command_is_registered() { + crate::install().unwrap(); let spec = crate::commands::find("paint.artHistoryBrush").expect("registered"); assert_eq!(spec.label, "Art History Brush"); assert!(spec.params.contains("style")); assert!(spec.journal); - assert!(!Session::new().is_enabled("paint.artHistoryBrush")); + assert!(!crate::session().is_enabled("paint.artHistoryBrush")); let s = session(16, 16, 8, "rgb"); assert!(s.is_enabled("paint.artHistoryBrush")); } diff --git a/crates/engine/src/cmd/retouch_cmds/art_history_depth_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/art_history_depth_tests.rs similarity index 98% rename from crates/engine/src/cmd/retouch_cmds/art_history_depth_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/art_history_depth_tests.rs index d6c8b13525..7c6dd6aad5 100644 --- a/crates/engine/src/cmd/retouch_cmds/art_history_depth_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/art_history_depth_tests.rs @@ -14,7 +14,7 @@ const MODE: &str = "Could not use the art history brush because the current colo /// Rows Open (white), Fill (red): row 1 is the red state. fn filled(depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": depth, "mode": mode, "background": "white"})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s @@ -46,7 +46,7 @@ fn paints(s: &mut Session, state: Value, case: &str) { #[test] fn a_single_layer_16_bit_document_is_refused() { for mode in ["rgb", "gray"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": 16, "mode": mode})).unwrap(); // The source is the open state, the History panel's default. assert_eq!(refused(&mut s, json!({"state": null, "tolerance": 0}), mode), BITS16, "{mode}"); diff --git a/crates/engine/src/cmd/retouch_cmds/art_history_mode_mismatch_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/art_history_mode_mismatch_tests.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/art_history_mode_mismatch_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/art_history_mode_mismatch_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds/art_history_noop_state_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/art_history_noop_state_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/art_history_noop_state_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/art_history_noop_state_tests.rs index 3a67d39df9..55d2255b86 100644 --- a/crates/engine/src/cmd/retouch_cmds/art_history_noop_state_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/art_history_noop_state_tests.rs @@ -4,7 +4,7 @@ use super::*; fn session(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": depth, "mode": "rgb"})).unwrap(); s } diff --git a/crates/engine/src/cmd/retouch_cmds/art_history_refusal_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/art_history_refusal_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/art_history_refusal_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/art_history_refusal_tests.rs index 6d18e01a89..5f82c1bf97 100644 --- a/crates/engine/src/cmd/retouch_cmds/art_history_refusal_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/art_history_refusal_tests.rs @@ -12,7 +12,7 @@ use crate::hidden_target::{ART_HISTORY_HIDDEN, HIDDEN}; /// An RGB document with a red "Layer 1" above the white Background, the layer active. History /// rows: 0 Open, 1 New Layer, 2 Fill. fn session() -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "background": "white"})).unwrap(); let id = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); diff --git a/crates/engine/src/cmd/retouch_cmds/blur_refuses_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/blur_refuses_indexed_tests.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/blur_refuses_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/blur_refuses_indexed_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds/burn_refuses_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/burn_refuses_indexed_tests.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/burn_refuses_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/burn_refuses_indexed_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds/clone.rs b/crates/engine-core/src/cmd/retouch_cmds/clone.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/clone.rs rename to crates/engine-core/src/cmd/retouch_cmds/clone.rs diff --git a/crates/engine/src/cmd/retouch_cmds/clone_sampling.rs b/crates/engine-core/src/cmd/retouch_cmds/clone_sampling.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/clone_sampling.rs rename to crates/engine-core/src/cmd/retouch_cmds/clone_sampling.rs diff --git a/crates/engine/src/cmd/retouch_cmds/clone_source_layer_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/clone_source_layer_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/clone_source_layer_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/clone_source_layer_tests.rs index 1d9f72e13c..ae89424dd2 100644 --- a/crates/engine/src/cmd/retouch_cmds/clone_source_layer_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/clone_source_layer_tests.rs @@ -3,7 +3,7 @@ use crate::presets::clone_source::Mapping; /// Create a native colour-gradient source and an empty destination without re-picking. fn setup(depth: u64, mode: &str) -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "depth": depth, "mode": mode})).unwrap(); let source = s.active().unwrap().active_layer.unwrap(); s.edit("source", |doc, _| { @@ -781,7 +781,7 @@ fn clone_and_heal_transformed_far_sources_are_finite_and_preserve_the_destinatio /// Build equivalent opaque sources with/without stored alpha, using quantized fixture colours. fn no_alpha_scene(depth: u64, mode: &str, source_alpha: bool, target_alpha: bool, external: bool, at: [i32; 2], color: [f32; 4]) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "depth": depth, "mode": mode})).unwrap(); let source = s.active().unwrap().active_layer.unwrap(); s.edit("opaque source", |doc, _| { diff --git a/crates/engine/src/cmd/retouch_cmds/content_aware_move.rs b/crates/engine-core/src/cmd/retouch_cmds/content_aware_move.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/content_aware_move.rs rename to crates/engine-core/src/cmd/retouch_cmds/content_aware_move.rs index fa7b82ad72..b269e69ec8 100644 --- a/crates/engine/src/cmd/retouch_cmds/content_aware_move.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/content_aware_move.rs @@ -826,7 +826,7 @@ mod tests { use crate::jobs::JobCtx; fn textured(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); diff --git a/crates/engine/src/cmd/retouch_cmds/content_aware_move_color_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/content_aware_move_color_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/content_aware_move_color_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/content_aware_move_color_tests.rs index 57e99d3898..cc21b78f2b 100644 --- a/crates/engine/src/cmd/retouch_cmds/content_aware_move_color_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/content_aware_move_color_tests.rs @@ -5,7 +5,7 @@ use super::*; fn session(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": 8, "mode": "rgb"})).unwrap(); s } diff --git a/crates/engine/src/cmd/retouch_cmds/dab.rs b/crates/engine-core/src/cmd/retouch_cmds/dab.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/dab.rs rename to crates/engine-core/src/cmd/retouch_cmds/dab.rs diff --git a/crates/engine/src/cmd/retouch_cmds/dodge_refuses_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/dodge_refuses_indexed_tests.rs similarity index 98% rename from crates/engine/src/cmd/retouch_cmds/dodge_refuses_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/dodge_refuses_indexed_tests.rs index c2e54642e4..1c84fa9f7d 100644 --- a/crates/engine/src/cmd/retouch_cmds/dodge_refuses_indexed_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/dodge_refuses_indexed_tests.rs @@ -13,7 +13,7 @@ const BITMAP: &str = "Could not use the dodge tool because it does not work with /// A session with one 64 × 64 document of `mode` and `depth`, filled mid grey. pub(super) fn session(mode: ColorMode, depth: SampleType) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::with_background("t", Size::new(64, 64), mode, depth, Color::rgb(0.5, 0.5, 0.5)), None); s } diff --git a/crates/engine/src/cmd/retouch_cmds/heal.rs b/crates/engine-core/src/cmd/retouch_cmds/heal.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/heal.rs rename to crates/engine-core/src/cmd/retouch_cmds/heal.rs diff --git a/crates/engine/src/cmd/retouch_cmds/heal_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/heal_indexed_tests.rs similarity index 98% rename from crates/engine/src/cmd/retouch_cmds/heal_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/heal_indexed_tests.rs index 48a3afb5e2..19cbaf929b 100644 --- a/crates/engine/src/cmd/retouch_cmds/heal_indexed_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/heal_indexed_tests.rs @@ -12,7 +12,7 @@ const MESSAGE: &str = "Could not set the clone source because it does not work w /// A 64 × 64 `mode` document of `depth`, mid grey with its left half black: the edge is the /// texture the stroke heals onto the flat grey. fn edged(mode: ColorMode, depth: SampleType) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::with_background("t", Size::new(64, 64), mode, depth, Color::rgb(0.5, 0.5, 0.5)), None); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 32, "height": 64})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#000000"})).unwrap(); diff --git a/crates/engine/src/cmd/retouch_cmds/patch.rs b/crates/engine-core/src/cmd/retouch_cmds/patch.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/patch.rs rename to crates/engine-core/src/cmd/retouch_cmds/patch.rs diff --git a/crates/engine/src/cmd/retouch_cmds/patch_destination_selection_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/patch_destination_selection_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/patch_destination_selection_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/patch_destination_selection_tests.rs index 7ed9e54efa..76f46f27f7 100644 --- a/crates/engine/src/cmd/retouch_cmds/patch_destination_selection_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/patch_destination_selection_tests.rs @@ -3,7 +3,7 @@ use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "depth": 8, "mode": "rgb"})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); diff --git a/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/patch_history_names_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/patch_history_names_tests.rs index 2fcee6e1d7..88736ffc9a 100644 --- a/crates/engine/src/cmd/retouch_cmds/patch_history_names_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/patch_history_names_tests.rs @@ -4,7 +4,7 @@ use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 128, "height": 64, "depth": 8, "mode": "rgb"})).unwrap(); s } diff --git a/crates/engine/src/cmd/retouch_cmds/pattern_stamp.rs b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/pattern_stamp.rs rename to crates/engine-core/src/cmd/retouch_cmds/pattern_stamp.rs diff --git a/crates/engine/src/cmd/retouch_cmds/pattern_stamp_behind_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_behind_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/pattern_stamp_behind_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_behind_tests.rs index fc0df896ff..287f03e86e 100644 --- a/crates/engine/src/cmd/retouch_cmds/pattern_stamp_behind_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_behind_tests.rs @@ -15,7 +15,7 @@ const RED: [f32; 4] = [0.8, 0.1, 0.1, 1.0]; /// A 64 × 48 document at `depth` with a new layer above the Background whose pixels are `f`. fn session(depth: u64, f: impl Fn(i32, i32) -> [f32; 4]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth, "mode": "rgb"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("setup", |doc, active| { @@ -159,7 +159,7 @@ fn behind_paints_nothing_without_transparency_to_paint_into() { let live = super::super::LiveRetouch::begin(&s, "paint.patternStamp", &stroke(json!({"mode": "behind"}))).unwrap().doc.clone(); assert_eq!(pixels(&live, &s), before, "the live stroke too"); // The Background has no transparency. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H})).unwrap(); let before = layer(&s); stamp(&mut s, json!({"mode": "behind"})); diff --git a/crates/engine/src/cmd/retouch_cmds/pattern_stamp_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_indexed_tests.rs similarity index 97% rename from crates/engine/src/cmd/retouch_cmds/pattern_stamp_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_indexed_tests.rs index 6fb7adc4c0..624cdcfee6 100644 --- a/crates/engine/src/cmd/retouch_cmds/pattern_stamp_indexed_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_indexed_tests.rs @@ -41,7 +41,7 @@ fn state(s: &Session) -> (Vec<[f32; 4]>, usize) { #[test] fn an_rgb_pattern_is_refused_in_an_indexed_document_with_the_reference_words() { - let mut s = Session::new(); + let mut s = crate::session(); let pat = quadrants(&mut s, "rgb"); new_doc(&mut s, "rgb", 8); to_indexed(&mut s); @@ -61,7 +61,7 @@ fn an_rgb_pattern_is_refused_in_an_indexed_document_with_the_reference_words() { #[test] fn other_documents_keep_painting_with_the_rgb_pattern() { - let mut s = Session::new(); + let mut s = crate::session(); let pat = quadrants(&mut s, "rgb"); for mode in ["rgb", "grayscale", "cmyk", "lab"] { for depth in [8, 16, 32] { @@ -78,7 +78,7 @@ fn other_documents_keep_painting_with_the_rgb_pattern() { #[test] fn grayscale_cmyk_lab_and_indexed_patterns_are_refused_in_an_indexed_document_too() { - let mut s = Session::new(); + let mut s = crate::session(); let mut patterns = ["grayscale", "cmyk", "lab"].map(|mode| quadrants(&mut s, mode)).to_vec(); // A pattern defined from an Indexed Color image. s.execute("file.new", json!({"width": 20, "height": 20, "depth": 8, "mode": "rgb"})).unwrap(); diff --git a/crates/engine/src/cmd/retouch_cmds/pattern_stamp_origin_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_origin_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/pattern_stamp_origin_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_origin_tests.rs index dcd29975c7..299525fe00 100644 --- a/crates/engine/src/cmd/retouch_cmds/pattern_stamp_origin_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/pattern_stamp_origin_tests.rs @@ -1,7 +1,7 @@ use super::*; fn fixture(width: i32, height: i32, depth: u64) -> (Session, String) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 700, "height": 600, "depth": depth})).unwrap(); let fmt = s.active().unwrap().doc.pixel_format(); let mut surface = Surface::new(fmt); diff --git a/crates/engine/src/cmd/retouch_cmds/periodic.rs b/crates/engine-core/src/cmd/retouch_cmds/periodic.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/periodic.rs rename to crates/engine-core/src/cmd/retouch_cmds/periodic.rs diff --git a/crates/engine/src/cmd/retouch_cmds/remove.rs b/crates/engine-core/src/cmd/retouch_cmds/remove.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/remove.rs rename to crates/engine-core/src/cmd/retouch_cmds/remove.rs diff --git a/crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/remove_history_name_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/remove_history_name_tests.rs index bec64fbb0f..7ad63bf28b 100644 --- a/crates/engine/src/cmd/retouch_cmds/remove_history_name_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/remove_history_name_tests.rs @@ -6,7 +6,7 @@ use crate::jobs::Started; /// A flat grey layer with a dark square at 40..52 × 24..36. fn square_session(depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 64, "depth": depth, "mode": mode})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); diff --git a/crates/engine/src/cmd/retouch_cmds/remove_new_layer_name_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/remove_new_layer_name_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/remove_new_layer_name_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/remove_new_layer_name_tests.rs index 008d87f594..b22a582f81 100644 --- a/crates/engine/src/cmd/retouch_cmds/remove_new_layer_name_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/remove_new_layer_name_tests.rs @@ -6,7 +6,7 @@ use super::*; /// A flat grey layer with a dark square at 40..52 × 24..36. fn square_session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 96, "height": 64, "depth": 8, "mode": "rgb"})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); diff --git a/crates/engine/src/cmd/retouch_cmds/sampling.rs b/crates/engine-core/src/cmd/retouch_cmds/sampling.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/sampling.rs rename to crates/engine-core/src/cmd/retouch_cmds/sampling.rs diff --git a/crates/engine/src/cmd/retouch_cmds/sharpen_refuses_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/sharpen_refuses_indexed_tests.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/sharpen_refuses_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/sharpen_refuses_indexed_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds/smudge_mode_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/smudge_mode_tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/smudge_mode_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/smudge_mode_tests.rs index acfa963b8d..dbbb703cc5 100644 --- a/crates/engine/src/cmd/retouch_cmds/smudge_mode_tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/smudge_mode_tests.rs @@ -17,7 +17,7 @@ const XS: [i32; 6] = [100, 110, 120, 130, 140, 155]; /// A 200 × 60 document of `depth` and `mode` whose left half is `left` and right half `right`. fn two_tone(depth: u64, mode: &str, left: [i32; 3], right: [i32; 3]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "depth": depth, "mode": mode})).unwrap(); s.edit("setup", |doc, active| { let b = doc.bounds(); @@ -203,7 +203,7 @@ fn a_transparent_pixel_takes_the_smudged_colour() { d.doc.layer(d.active_layer.unwrap()).unwrap().surface().unwrap().rgba(x, 30)[3] }; let run = |mode: &str| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "background": "transparent"})).unwrap(); s.execute("paint.pencil", json!({"points": [[0, 30], [99, 30]], "size": 40, "color": "#c82828"})).unwrap(); s.execute("paint.smudge", stroke(Some(mode))).unwrap(); diff --git a/crates/engine/src/cmd/retouch_cmds/smudge_refuses_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/smudge_refuses_indexed_tests.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/smudge_refuses_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/smudge_refuses_indexed_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds/sponge_refuses_indexed_tests.rs b/crates/engine-core/src/cmd/retouch_cmds/sponge_refuses_indexed_tests.rs similarity index 100% rename from crates/engine/src/cmd/retouch_cmds/sponge_refuses_indexed_tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/sponge_refuses_indexed_tests.rs diff --git a/crates/engine/src/cmd/retouch_cmds/tests.rs b/crates/engine-core/src/cmd/retouch_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/retouch_cmds/tests.rs rename to crates/engine-core/src/cmd/retouch_cmds/tests.rs index 82d0bb0302..d1291be463 100644 --- a/crates/engine/src/cmd/retouch_cmds/tests.rs +++ b/crates/engine-core/src/cmd/retouch_cmds/tests.rs @@ -138,7 +138,7 @@ fn periodic_clone_live_matches_commit_through_a_corner() { points.push(json!([x, y])); } params["points"] = json!(points); - let mut committed = Session::new(); + let mut committed = crate::session(); committed.add_document((*before).clone(), None); committed.execute("paint.cloneStamp", params.clone()).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); @@ -241,7 +241,7 @@ fn clone_preview_matches_source_without_mutating_session() { } fn session(w: u32, h: u32, depth: u64, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth, "mode": mode})).unwrap(); s } @@ -898,7 +898,7 @@ fn the_budget_is_applied_to_the_rendered_extent_not_the_input_points() { #[test] fn history_brush_reads_a_source_when_its_pixels_were_locked() { // Given a white layer locked in history state 1, then unlocked and filled red. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": 8, "mode": "rgb", "background": "white"})).unwrap(); s.execute("layer.lockLayers", json!({"pixels": true})).unwrap(); s.execute("layer.lockLayers", json!({"pixels": false})).unwrap(); @@ -915,7 +915,7 @@ fn history_brush_reads_a_source_when_its_pixels_were_locked() { #[test] fn history_brush_refuses_a_locked_destination_when_source_is_unlocked() { // Given an unlocked white source and a red, currently locked destination. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": 8, "mode": "rgb", "background": "white"})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s.execute("layer.lockLayers", json!({"pixels": true})).unwrap(); @@ -958,7 +958,7 @@ fn erase_to_history_paints_the_source_states_visible_image_at_every_depth() { #[test] fn erase_to_history_paints_a_new_layer_from_a_single_layer_state_background_or_not() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "background": "transparent"})).unwrap(); s.execute("paint.stroke", json!({"points": [[0, 10], [40, 10]], "size": 12, "hardness": 1.0, "color": "#ff0000"})).unwrap(); let red = rgba(&s, 20, 10); @@ -970,7 +970,7 @@ fn erase_to_history_paints_a_new_layer_from_a_single_layer_state_background_or_n #[test] fn erase_to_history_paints_a_new_layer_with_the_single_layers_own_pixels_not_its_opacity() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "background": "transparent"})).unwrap(); s.execute("paint.stroke", json!({"points": [[0, 10], [40, 10]], "size": 12, "hardness": 1.0, "color": "#ff0000"})).unwrap(); let red = rgba(&s, 20, 10); @@ -982,7 +982,7 @@ fn erase_to_history_paints_a_new_layer_with_the_single_layers_own_pixels_not_its #[test] fn erase_to_history_refuses_a_new_layer_from_a_state_holding_only_a_group() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "background": "transparent"})).unwrap(); s.execute("paint.stroke", json!({"points": [[0, 10], [40, 10]], "size": 12, "hardness": 1.0, "color": "#ff0000"})).unwrap(); s.execute("layer.groupLayers", json!({})).unwrap(); // State 2: one group at the root. @@ -995,7 +995,7 @@ fn erase_to_history_refuses_a_new_layer_from_a_state_holding_only_a_group() { /// no pixels to paint back: refused like the one-layer group (FredApps' review of #10692). #[test] fn erase_to_history_refuses_a_new_layer_from_a_state_holding_one_group_of_several_layers() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "background": "transparent"})).unwrap(); s.execute("paint.stroke", json!({"points": [[0, 5], [40, 5]], "size": 6, "hardness": 1.0, "color": "#ff0000"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); @@ -1019,7 +1019,7 @@ fn erase_to_history_refuses_a_new_layer_from_a_state_holding_one_group_of_severa #[test] fn erase_to_history_on_a_new_layer_without_pixels_names_the_target_not_the_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "background": "transparent"})).unwrap(); s.execute("paint.stroke", json!({"points": [[0, 10], [40, 10]], "size": 12, "hardness": 1.0, "color": "#ff0000"})).unwrap(); // An adjustment layer has a mask, so the command is available, but this targets its pixels. @@ -1035,7 +1035,7 @@ fn erase_to_history_on_a_new_layer_without_pixels_names_the_target_not_the_docum #[test] fn erase_to_history_paints_a_single_solid_shapes_colour_past_its_path() { for depth in [8u64, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "depth": depth, "background": "transparent"})).unwrap(); let first = s.active().unwrap().active_layer.unwrap(); s.execute("shape.create", json!({"kind": "rect", "rect": [1, 1, 5, 5], "fill": "#0000ff"})).unwrap(); @@ -1056,7 +1056,7 @@ fn erase_to_history_paints_white_past_the_path_of_a_single_shape_without_a_solid let outline = json!({"kind": "rect", "rect": [1, 1, 5, 5], "fill": null, "stroke": {"width": 2, "color": "#ff0000"}}); for shape in [gradient, outline] { for depth in [8u64, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "depth": depth, "background": "transparent"})).unwrap(); let first = s.active().unwrap().active_layer.unwrap(); s.execute("shape.create", shape.clone()).unwrap(); @@ -1074,7 +1074,7 @@ fn erase_to_history_paints_white_past_the_path_of_a_single_shape_without_a_solid #[test] fn erase_to_history_paints_white_past_a_shapes_path_in_every_colour_mode() { for mode in ["cmyk", "gray", "lab"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20, "mode": mode, "background": "transparent"})).unwrap(); let first = s.active().unwrap().active_layer.unwrap(); let fill = json!({"gradient": {"stops": [[0, "#ff0000"], [1, "#0000ff"]], "angle": 0}}); @@ -1176,6 +1176,7 @@ fn history_brush_errors_when_layer_is_new() { #[test] fn retouch_commands_are_registered_and_need_a_pixel_layer() { + crate::install().unwrap(); let ids = [ "paint.cloneStamp", "paint.patternStamp", @@ -1194,7 +1195,7 @@ fn retouch_commands_are_registered_and_need_a_pixel_layer() { for id in ids { let spec = crate::commands::find(id).unwrap_or_else(|| panic!("{id} missing")); assert!(spec.params.contains("\"points\"") && spec.params.contains("spacing"), "{id}"); - assert!(!Session::new().is_enabled(id)); + assert!(!crate::session().is_enabled(id)); } let mut s = session(10, 10, 8, "rgb"); assert!(s.execute("paint.dodge", json!({"points": []})).is_err()); @@ -2628,7 +2629,7 @@ fn remove_thin_scratches_take_their_surroundings() { #[test] fn remove_bad_params_are_errors() { - assert!(Session::new().execute("paint.remove", json!({"points": [[1, 1]]})).is_err(), "no document"); + assert!(crate::session().execute("paint.remove", json!({"points": [[1, 1]]})).is_err(), "no document"); let mut s = square_session(8, "rgb"); for p in [ json!({}), @@ -2961,7 +2962,7 @@ fn periodic_clone_low_flow_revisits_accumulate_across_tile_aliases() { // Independent oracle: paint the same continuous stroke over two physical copies of a // tile, then combine the two coverage values using the brush's flow accumulation rule. let setup = |width| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":width,"height":24,"depth":32})).unwrap(); s.execute("tools.setBrush", json!({"brush": {"smoothing": {"catchUpOnEnd": true}}})).unwrap(); for x in (8..width).step_by(32) { @@ -2988,7 +2989,7 @@ fn periodic_clone_low_flow_revisits_accumulate_across_tile_aliases() { #[test] fn periodic_clone_live_offer_commits_and_undoes_the_same_pixels_as_replay() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":32,"height":24,"depth":depth})).unwrap(); s.execute("paint.pencil", json!({"points":[[8,8]],"size":12,"color":"#d03060"})).unwrap(); let before = s.active().unwrap().doc.clone(); @@ -3001,7 +3002,7 @@ fn periodic_clone_live_offer_commits_and_undoes_the_same_pixels_as_replay() { assert_eq!(result["fromLive"], true); let read = |s: &Session| s.active().unwrap().doc.layer(id).unwrap().surface().unwrap().read_region(before.bounds()); assert_eq!(read(&s), shown, "offered preview at depth {depth}"); - let mut replay = Session::new(); + let mut replay = crate::session(); replay.add_document((*before).clone(), None); replay.execute("paint.cloneStamp", params).unwrap(); assert_eq!(read(&s), read(&replay), "command replay at depth {depth}"); diff --git a/crates/engine/src/cmd/rotate_canvas_bitmap_tests.rs b/crates/engine-core/src/cmd/rotate_canvas_bitmap_tests.rs similarity index 98% rename from crates/engine/src/cmd/rotate_canvas_bitmap_tests.rs rename to crates/engine-core/src/cmd/rotate_canvas_bitmap_tests.rs index 16ce8fb5c5..de0e9b03e9 100644 --- a/crates/engine/src/cmd/rotate_canvas_bitmap_tests.rs +++ b/crates/engine-core/src/cmd/rotate_canvas_bitmap_tests.rs @@ -39,7 +39,7 @@ const TURNS: [TurnCase; 5] = [ /// A `w x h` document in `mode` at 8 bits, with a white Background. fn doc_in(mode: &str, w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "mode": mode, "background": "white"})).unwrap(); s } @@ -103,7 +103,7 @@ fn arbitrary_is_greyed_out_in_a_bitmap_document() { assert!(!s.is_enabled_with(ARBITRARY, &p), "{p}: still greyed"); } // With no document at all it stays off for the reason it already had. - assert_eq!(Session::new().disabled_reason(ARBITRARY).as_deref(), Some("no document open"), "no document open, as before"); + assert_eq!(crate::session().disabled_reason(ARBITRARY).as_deref(), Some("no document open"), "no document open, as before"); } #[test] @@ -174,7 +174,7 @@ fn only_a_bitmap_document_greys_the_arbitrary_turn_out() { // The other modes, the other expanded-pixel ones included, answer as they do today. for mode in [ColorMode::Rgb, ColorMode::Grayscale, ColorMode::Indexed, ColorMode::Cmyk, ColorMode::Lab, ColorMode::Multichannel, ColorMode::Duotone] { let d = Document::with_background("modes", Size::new(32, 24), mode, SampleType::U8, Color::WHITE); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(d, None); assert!(s.is_enabled(ARBITRARY), "{mode:?}: not measured, so it stays available"); } diff --git a/crates/engine/src/cmd/rotate_canvas_guides_tests.rs b/crates/engine-core/src/cmd/rotate_canvas_guides_tests.rs similarity index 97% rename from crates/engine/src/cmd/rotate_canvas_guides_tests.rs rename to crates/engine-core/src/cmd/rotate_canvas_guides_tests.rs index 32a7e9a14d..6a1b72e6a8 100644 --- a/crates/engine/src/cmd/rotate_canvas_guides_tests.rs +++ b/crates/engine-core/src/cmd/rotate_canvas_guides_tests.rs @@ -14,7 +14,7 @@ const TOL: f64 = 0.15; /// A 400×300 document with a vertical guide at x=100 and a horizontal guide at y=50. fn doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.edit("guides", |d, _| { d.guides.vertical = vec![100.0]; @@ -55,7 +55,7 @@ fn arbitrary_turn_keeps_both_measured_guide_positions() { fn arbitrary_turn_puts_a_guide_at_its_turned_canvas_edge_point() { // The guide follows the point it crossed the canvas edge, so the guide along the old left edge // ends up at the turned image's top corner: (0, 0) → (150, 0) for a 30° clockwise turn. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.edit("guides", |d, _| { d.guides.vertical = vec![0.0]; @@ -94,7 +94,7 @@ fn quarter_turn_swaps_the_guides_like_the_right_angle_command_does() { #[test] fn right_angle_turns_keep_the_number_of_guides() { for angle in [90.0, 180.0, 270.0] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.edit("guides", |d, _| { d.guides.vertical = vec![100.0, 250.0]; @@ -125,7 +125,7 @@ fn a_guide_outside_the_canvas_is_turned_rather_than_dropped() { // Nothing is clamped to the canvas: every point of the image's own edges lands inside the // turned canvas, and a guide that was already outside it (a mark left outside by Canvas Size, // cf. #11762) turns with the image and stays outside instead of going away. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.edit("guides", |d, _| { d.guides.vertical = vec![500.0]; @@ -145,7 +145,7 @@ fn a_guide_outside_the_canvas_is_turned_rather_than_dropped() { fn the_turn_drops_guide_colours_as_it_does_today() { // Guide colours for a turn are not measured, so they keep today's behaviour: the guide's // position stays, its own colour goes with the cleared colours. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("view.newGuide", json!({"orientation": "vertical", "position": 100, "color": "#ff00ff"})).unwrap(); s.execute("image.rotation.arbitrary", json!({"angle": 30, "direction": "cw"})).unwrap(); diff --git a/crates/engine/src/cmd/rotate_canvas_interpolation_pref_tests.rs b/crates/engine-core/src/cmd/rotate_canvas_interpolation_pref_tests.rs similarity index 99% rename from crates/engine/src/cmd/rotate_canvas_interpolation_pref_tests.rs rename to crates/engine-core/src/cmd/rotate_canvas_interpolation_pref_tests.rs index 6c2ce6c10f..362d337747 100644 --- a/crates/engine/src/cmd/rotate_canvas_interpolation_pref_tests.rs +++ b/crates/engine-core/src/cmd/rotate_canvas_interpolation_pref_tests.rs @@ -11,7 +11,7 @@ use super::*; use crate::prefs::Interpolation; fn green_edge_doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "depth": 8, "mode": "rgb", "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 174, "y": 100, "width": 100, "height": 160, "antiAlias": false})).unwrap(); s.execute("edit.fill", json!({"color": "#00ff00"})).unwrap(); diff --git a/crates/engine/src/cmd/rotate_canvas_right_angle_tests.rs b/crates/engine-core/src/cmd/rotate_canvas_right_angle_tests.rs similarity index 99% rename from crates/engine/src/cmd/rotate_canvas_right_angle_tests.rs rename to crates/engine-core/src/cmd/rotate_canvas_right_angle_tests.rs index 7af202e416..c2ef20dc15 100644 --- a/crates/engine/src/cmd/rotate_canvas_right_angle_tests.rs +++ b/crates/engine-core/src/cmd/rotate_canvas_right_angle_tests.rs @@ -7,7 +7,7 @@ const CCW: &str = "image.imageRotation.90ccw"; const HALF: &str = "image.imageRotation.180"; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth, "background": "white"})).unwrap(); s.execute("tools.setColors", json!({"background": "#ff00ff"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Top"})).unwrap(); diff --git a/crates/engine/src/cmd/rotate_canvas_selection_tests.rs b/crates/engine-core/src/cmd/rotate_canvas_selection_tests.rs similarity index 98% rename from crates/engine/src/cmd/rotate_canvas_selection_tests.rs rename to crates/engine-core/src/cmd/rotate_canvas_selection_tests.rs index 6d40613969..32d254ada8 100644 --- a/crates/engine/src/cmd/rotate_canvas_selection_tests.rs +++ b/crates/engine-core/src/cmd/rotate_canvas_selection_tests.rs @@ -7,7 +7,7 @@ use photocraft_geom::Rect; use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap(); s diff --git a/crates/engine/src/cmd/sample_cmds.rs b/crates/engine-core/src/cmd/sample_cmds.rs similarity index 99% rename from crates/engine/src/cmd/sample_cmds.rs rename to crates/engine-core/src/cmd/sample_cmds.rs index 5b676eb575..d1edc34f11 100644 --- a/crates/engine/src/cmd/sample_cmds.rs +++ b/crates/engine-core/src/cmd/sample_cmds.rs @@ -481,7 +481,7 @@ mod tests { #[test] fn the_command_validates_its_params() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("document.sampleColor", json!({"x": 1, "y": 1})).is_err(), "no document"); s.execute("file.new", json!({"width": 8, "height": 8, "background": "white"})).unwrap(); let v: Vec = serde_json::from_value(s.execute("document.sampleColor", json!({"x": 4, "y": 4, "size": 3})).unwrap()).unwrap(); diff --git a/crates/engine/src/cmd/sample_zoom_box_tests.rs b/crates/engine-core/src/cmd/sample_zoom_box_tests.rs similarity index 99% rename from crates/engine/src/cmd/sample_zoom_box_tests.rs rename to crates/engine-core/src/cmd/sample_zoom_box_tests.rs index 20fbcc08b0..23b8af81ee 100644 --- a/crates/engine/src/cmd/sample_zoom_box_tests.rs +++ b/crates/engine-core/src/cmd/sample_zoom_box_tests.rs @@ -12,7 +12,7 @@ use crate::Session; /// 354–355, …) and a grey ramp of ten 40 px blocks from x 100, values 100, 105, …, 145, at /// y 350–450. fn test_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({"name": "Pixels"})).unwrap(); let fill = |s: &mut Session, x: i32, y: i32, w: i32, h: i32, grey_or_hex: String| { @@ -34,7 +34,7 @@ fn test_document() -> Session { /// A black 400 × 400 document with one white pixel at 200,200 (the issue's probe). fn probe() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 400, "background": "white"})).unwrap(); s.execute("select.all", json!({})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#000000"})).unwrap(); diff --git a/crates/engine/src/cmd/sampler_cmds.rs b/crates/engine-core/src/cmd/sampler_cmds.rs similarity index 100% rename from crates/engine/src/cmd/sampler_cmds.rs rename to crates/engine-core/src/cmd/sampler_cmds.rs diff --git a/crates/engine/src/cmd/sampler_cmds/pixel_centre_tests.rs b/crates/engine-core/src/cmd/sampler_cmds/pixel_centre_tests.rs similarity index 99% rename from crates/engine/src/cmd/sampler_cmds/pixel_centre_tests.rs rename to crates/engine-core/src/cmd/sampler_cmds/pixel_centre_tests.rs index ff57d5ea9d..430f99f49e 100644 --- a/crates/engine/src/cmd/sampler_cmds/pixel_centre_tests.rs +++ b/crates/engine-core/src/cmd/sampler_cmds/pixel_centre_tests.rs @@ -7,7 +7,7 @@ use photocraft_geom::Rect; /// An 800 × 600 white document, as in the issue's measurement. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/sampler_cmds/sample_size_tests.rs b/crates/engine-core/src/cmd/sampler_cmds/sample_size_tests.rs similarity index 98% rename from crates/engine/src/cmd/sampler_cmds/sample_size_tests.rs rename to crates/engine-core/src/cmd/sampler_cmds/sample_size_tests.rs index 5b603037c4..ffd793e14d 100644 --- a/crates/engine/src/cmd/sampler_cmds/sample_size_tests.rs +++ b/crates/engine-core/src/cmd/sampler_cmds/sample_size_tests.rs @@ -8,7 +8,7 @@ use photocraft_geom::Rect; /// The issue's test document: 800 × 600 RGB/8 white, with 2 px black and 2 px white vertical /// stripes at 350,100 to 450,200 (black at x 350–351, 354–355, …). fn stripes() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); s.edit("stripes", |doc, _| { let surf = doc.layers[0].surface_mut().unwrap(); @@ -75,7 +75,7 @@ fn changing_the_size_rereads_every_point_without_moving_it() { #[test] fn a_box_at_the_canvas_edge_averages_only_the_pixels_inside() { // The corner pixel's 3 × 3 box keeps its 2 × 2 part on the canvas: one black pixel of four. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "background": "white"})).unwrap(); s.edit("dot", |doc, _| { let surf = doc.layers[0].surface_mut().unwrap(); diff --git a/crates/engine/src/cmd/sampler_cmds/tests.rs b/crates/engine-core/src/cmd/sampler_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/sampler_cmds/tests.rs rename to crates/engine-core/src/cmd/sampler_cmds/tests.rs index 652b5f58f0..80a7ed96e8 100644 --- a/crates/engine/src/cmd/sampler_cmds/tests.rs +++ b/crates/engine-core/src/cmd/sampler_cmds/tests.rs @@ -5,7 +5,7 @@ use photocraft_geom::Rect; /// A 100×80 white document. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 80, "background": "white"})).unwrap(); s } @@ -266,7 +266,7 @@ fn a_crop_to_a_target_size_scales_points() { #[test] fn bad_params_and_no_document_are_errors_not_panics() { - let mut s = Session::new(); + let mut s = crate::session(); for id in ["view.colorSamplers.add", "view.colorSamplers.move", "view.colorSamplers.delete", "view.colorSamplers.clear", "view.colorSamplers.list"] { assert!(s.execute(id, json!({})).is_err(), "{id} without a document"); } @@ -317,7 +317,7 @@ fn device_cmyk_clamps_out_of_range_and_nan_samples() { #[test] fn hdr_pixel_on_a_32_bit_document_reads_in_range() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": 32, "background": "white"})).unwrap(); s.edit("paint", |doc, _| { let surf = doc.layers[0].surface_mut().unwrap(); @@ -334,7 +334,7 @@ fn hdr_pixel_on_a_32_bit_document_reads_in_range() { #[test] fn points_work_at_every_depth_and_mode() { for (mode, depth) in [("rgb", 8), ("rgb", 16), ("rgb", 32), ("grayscale", 8), ("cmyk", 8), ("lab", 8)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20, "mode": mode, "depth": depth, "background": "white"})).unwrap(); let r = s.execute("view.colorSamplers.add", json!({"x": 10, "y": 10})).unwrap(); let rgb = r["point"]["rgb"].as_array().unwrap(); diff --git a/crates/engine/src/cmd/select_extra_cmds.rs b/crates/engine-core/src/cmd/select_extra_cmds.rs similarity index 98% rename from crates/engine/src/cmd/select_extra_cmds.rs rename to crates/engine-core/src/cmd/select_extra_cmds.rs index 3a112692c8..856ba927f6 100644 --- a/crates/engine/src/cmd/select_extra_cmds.rs +++ b/crates/engine-core/src/cmd/select_extra_cmds.rs @@ -269,7 +269,7 @@ mod tests { } fn landscape(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 160, "height": 100, "depth": depth})).unwrap(); s.edit("paint", |doc, active| { let l = doc.layer_mut(active.unwrap()).unwrap(); @@ -338,7 +338,7 @@ mod tests { #[test] fn sky_without_sky_changes_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("edit.fill", json!({"color": "#504020"})).ok(); let r = s.execute("select.sky", json!({})).unwrap(); @@ -348,7 +348,7 @@ mod tests { #[test] fn isolate_layers_toggles() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let active = s.active().unwrap().active_layer.unwrap(); @@ -376,7 +376,7 @@ mod tests { } isolated.is_empty() || isolated.contains(&id) || doc.layer(id).is_some_and(|l| contains(l, isolated)) } - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); let (inner, deep, side) = (Layer::raster("deep", PixelFormat::RGBA8), Layer::raster("side", PixelFormat::RGBA8), Layer::raster("loose", PixelFormat::RGBA8)); @@ -398,7 +398,7 @@ mod tests { } fn rect_sel() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("select.rect", json!({"x": 20, "y": 30, "width": 20, "height": 10})).unwrap(); s @@ -458,7 +458,7 @@ mod tests { #[test] fn transform_selection_step_name_is_restricted() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 40})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); let last = |s: &Session| s.active().unwrap().history.entries().last().cloned().unwrap(); @@ -475,7 +475,7 @@ mod tests { #[test] fn transform_selection_needs_a_selection() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 10, "height": 10})).unwrap(); assert!(!s.is_enabled("select.transformSelection")); } @@ -489,7 +489,7 @@ mod hang_tests { fn transform_selection_with_extreme_params_terminates() { // Regression (panic_hunt): a huge off-canvas transform used to allocate a buffer spanning // the old + new bounds and hang. It must return quickly without crashing. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 16})).unwrap(); s.execute("select.rect", json!({"x": 1, "y": 1, "width": 6, "height": 5})).unwrap(); // dx/dy move the selection far off-canvas; scaleX enlarges it — the old code allocated a diff --git a/crates/engine/src/cmd/selection_cmds.rs b/crates/engine-core/src/cmd/selection_cmds.rs similarity index 100% rename from crates/engine/src/cmd/selection_cmds.rs rename to crates/engine-core/src/cmd/selection_cmds.rs diff --git a/crates/engine/src/cmd/selection_cmds/color_range_performance.rs b/crates/engine-core/src/cmd/selection_cmds/color_range_performance.rs similarity index 98% rename from crates/engine/src/cmd/selection_cmds/color_range_performance.rs rename to crates/engine-core/src/cmd/selection_cmds/color_range_performance.rs index 639b7af4c6..6554c035ef 100644 --- a/crates/engine/src/cmd/selection_cmds/color_range_performance.rs +++ b/crates/engine-core/src/cmd/selection_cmds/color_range_performance.rs @@ -35,7 +35,7 @@ fn color_range_release_comparison() { // One warmup pair, followed by three alternating measured pairs. for round in 0..4 { for old in if round % 2 == 0 { [true, false] } else { [false, true] } { - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); let now = Instant::now(); if old { diff --git a/crates/engine/src/cmd/selection_cmds/color_range_window_tests.rs b/crates/engine-core/src/cmd/selection_cmds/color_range_window_tests.rs similarity index 98% rename from crates/engine/src/cmd/selection_cmds/color_range_window_tests.rs rename to crates/engine-core/src/cmd/selection_cmds/color_range_window_tests.rs index 26778c46e2..aaf4714792 100644 --- a/crates/engine/src/cmd/selection_cmds/color_range_window_tests.rs +++ b/crates/engine-core/src/cmd/selection_cmds/color_range_window_tests.rs @@ -4,7 +4,7 @@ use photocraft_geom::Size; use serde_json::json; fn fixture(depth: SampleType, p3: bool) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); let mut doc = Document::with_background("color range", Size::new(64, 48), ColorMode::Rgb, depth, photocraft_doc::Color::WHITE); if p3 { doc.icc_profile = Some(craft_cms::Builtin::DisplayP3.profile().to_bytes()); @@ -108,7 +108,7 @@ fn window_defaults_and_hostile_tiles_fall_back_and_empty_selection_is_safe() { assert_eq!(color_range_area(&doc, SelectionMode::Replace), canvas); assert_eq!(color_range_area(&doc, SelectionMode::Add), canvas); doc.selection = Some(Surface::new(PixelFormat::GRAY8)); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); assert!(sample_pixels(&s, true, Some(color_range_area(&s.active().unwrap().doc, SelectionMode::Replace))).unwrap().1.is_empty()); let err = s.execute("select.colorRange", json!({"select": "shadows", "tonalRange": -1})).unwrap_err(); @@ -125,7 +125,7 @@ fn sparse_large_selection_samples_only_its_clipped_window() { let mut doc = Document::new("sparse", Size::new(6000, 4000), ColorMode::Rgb, SampleType::U8); let selection = sel::mask_to_surface(&vec![1.0; 24 * 20], Rect::new(2990, 1990, 3014, 2010)); doc.selection = Some(selection); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); let win = color_range_area(&s.active().unwrap().doc, SelectionMode::Replace); assert_eq!(win, Rect::new(2990, 1990, 3014, 2010)); @@ -162,7 +162,7 @@ fn cropped_range_matches_full_canvas_combinations_with_soft_holes_and_clipped_ma let before = sel::mask_from_surface(prior.selection.as_ref(), canvas); let mut unselected = prior.clone(); unselected.selection = None; - let mut full = Session::new(); + let mut full = crate::session(); full.add_document(unselected, None); let params = json!({"select": preset, "points": [[40, 15]], "fuzziness": 40, "invert": invert}); full.execute("select.colorRange", params.clone()).unwrap(); diff --git a/crates/engine/src/cmd/selection_cmds/modify_window.rs b/crates/engine-core/src/cmd/selection_cmds/modify_window.rs similarity index 100% rename from crates/engine/src/cmd/selection_cmds/modify_window.rs rename to crates/engine-core/src/cmd/selection_cmds/modify_window.rs diff --git a/crates/engine/src/cmd/selection_cmds/modify_window/tests.rs b/crates/engine-core/src/cmd/selection_cmds/modify_window/tests.rs similarity index 96% rename from crates/engine/src/cmd/selection_cmds/modify_window/tests.rs rename to crates/engine-core/src/cmd/selection_cmds/modify_window/tests.rs index f26cd4c739..717c2f7590 100644 --- a/crates/engine/src/cmd/selection_cmds/modify_window/tests.rs +++ b/crates/engine-core/src/cmd/selection_cmds/modify_window/tests.rs @@ -1,5 +1,4 @@ use super::*; -use crate::Session; use crate::selection_cmds::{crop_mask, pad_mask, touches_edge}; use photocraft_algo::selection::{self as sel, SelectionMode}; use photocraft_color::{ColorMode, PixelFormat, SampleType}; @@ -43,7 +42,7 @@ fn sparse_36mp_command_only_materializes_the_selection_halo() { assert_eq!(area(&doc, sel::feather_reach(5.0) as f32), Rect::new(2984, 2984, 3066, 3066)); assert_eq!(area(&doc, sel::feather_reach(5.0) as f32).size().area(), 82 * 82); for op in ["expand", "contract", "border", "smooth", "feather"] { - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); session.execute(&format!("select.modify.{op}"), json!({"radius": 5})).unwrap(); assert!(session.active().unwrap().doc.selection.is_some()); @@ -84,7 +83,7 @@ fn cropped_commands_match_full_canvas_reads_padding_and_writeback() { } for at_bounds in [false, true] { let expected = full_canvas_reference(&doc, op, radius, at_bounds); - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); session.execute(&format!("select.modify.{op}"), json!({"radius": radius, "applyAtCanvasBounds": at_bounds})).unwrap(); let actual = &session.active().unwrap().doc.selection; @@ -117,7 +116,7 @@ fn cropped_blurs_preserve_soft_masks_at_every_depth() { for radius in [1.0, 2.5, 9.5] { for at_bounds in [false, true] { let expected = full_canvas_reference(&doc, op, radius, at_bounds); - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); session.execute(&format!("select.modify.{op}"), json!({"radius": radius, "applyAtCanvasBounds": at_bounds})).unwrap(); assert_eq!( @@ -142,7 +141,7 @@ fn cropped_blurs_preserve_single_pixel_and_thin_canvases() { for radius in [1.0, 9.5] { for at_bounds in [false, true] { let expected = full_canvas_reference(&doc, op, radius, at_bounds); - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); session.execute(&format!("select.modify.{op}"), json!({"radius": radius, "applyAtCanvasBounds": at_bounds})).unwrap(); assert_eq!( @@ -163,7 +162,7 @@ fn cropped_replacement_keeps_undo_and_redo() { let doc = document(75, 61, selection); let before = sel::mask_from_surface(doc.selection.as_ref(), canvas); for op in ["expand", "smooth", "feather"] { - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); session.execute(&format!("select.modify.{op}"), json!({"radius": 5})).unwrap(); let after = sel::mask_from_surface(session.active().unwrap().doc.selection.as_ref(), canvas); @@ -193,7 +192,7 @@ fn sparse_modify_release_comparison() { let mut new_times = Vec::new(); for round in 0..3 { for old in if round % 2 == 0 { [true, false] } else { [false, true] } { - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); let now = Instant::now(); if old { @@ -236,7 +235,7 @@ fn corrupt_tile_coordinates_do_not_panic_while_finding_the_window() { // Without the guard, content_bounds overflows while sorting these coordinates. assert_eq!(area(&doc, 5.0), doc.bounds()); for op in ["expand", "contract", "border", "smooth", "feather"] { - let mut session = Session::new(); + let mut session = crate::session(); session.add_document(doc.clone(), None); session.execute(&format!("select.modify.{op}"), json!({"radius": 5})).unwrap(); assert!(session.active().unwrap().doc.selection.is_none()); diff --git a/crates/engine/src/cmd/selection_cmds/tests.rs b/crates/engine-core/src/cmd/selection_cmds/tests.rs similarity index 98% rename from crates/engine/src/cmd/selection_cmds/tests.rs rename to crates/engine-core/src/cmd/selection_cmds/tests.rs index 24978ec738..f95caf9f83 100644 --- a/crates/engine/src/cmd/selection_cmds/tests.rs +++ b/crates/engine-core/src/cmd/selection_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -49,7 +49,7 @@ fn color_range_skin_tones_selects_skin_not_cream_and_refuses_detect_faces() { #[test] fn selection_sampling_refuses_oversized_canvases_before_reading_pixels() { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document( photocraft_doc::Document::new( "large", @@ -95,7 +95,7 @@ fn selection_sampling_all_layers_reports_a_failed_composite_and_keeps_the_select #[test] fn modify_rejects_oversized_canvases_before_reading_the_mask() { - let mut s = Session::new(); + let mut s = crate::session(); let mut doc = photocraft_doc::Document::new( "large", photocraft_geom::Size::new(300_000, 300_000), @@ -246,7 +246,7 @@ fn color_range_prepared_query_matches_the_command_at_all_depths() { let layer = doc.layers[0].surface_mut().unwrap(); layer.fill_rect(Rect::new(0, 0, 8, 12), &[0.65, 0.3, 0.2, 1.0]); layer.fill_rect(Rect::new(8, 0, 16, 12), &[0.2, 0.3, 0.65, 1.0]); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); for p in [ json!({"points": [[2, 3]], "fuzziness": 0}), @@ -316,7 +316,7 @@ fn color_range_selects_by_colour() { fn color_range_compares_in_lab_like_photoshop() { // Photoshop weighs hue (Lab a/b) three times as much as lightness; a per-channel RGB // distance can't tell a lighter shade from a redder one. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 30, "height": 10})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -338,7 +338,7 @@ fn color_range_compares_in_lab_like_photoshop() { #[test] fn color_range_fuzziness_zero_selects_exact_match_only() { // Sampled Colors at Fuzziness 0 selects only the exact match (TOOL-214-3, #214). - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 50, "height": 10})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -414,7 +414,7 @@ fn color_range_several_samples_points_and_invert() { #[test] fn color_range_subtract_follows_photoshop_and_the_click_order() { // Grey strips from dark to light; samples at both ends span the whole run. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 50, "height": 10})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -552,7 +552,7 @@ fn modify_commands() { #[test] fn modify_select_all_honours_canvas_bounds() { let all = || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.execute("select.all", json!({})).unwrap(); s @@ -657,7 +657,7 @@ fn grow_and_similar() { #[test] fn grow_and_similar_multi_color_does_not_select_intermediate_hull() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -691,7 +691,7 @@ fn grow_and_similar_multi_color_does_not_select_intermediate_hull() { #[test] fn grow_and_similar_report_a_failed_mask_allocation_and_keep_the_selection() { for cmd in ["select.grow", "select.similar"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.execute("select.rect", json!({"x": 6, "y": 6, "width": 4, "height": 4})).unwrap(); // The first fallible allocation samples the layer; the second is the canvas-sized result. @@ -705,7 +705,7 @@ fn grow_and_similar_report_a_failed_mask_allocation_and_keep_the_selection() { #[test] fn grow_reports_a_failed_frontier_push_mid_traversal_and_keeps_the_selection() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); s.execute("select.rect", json!({"x": 6, "y": 6, "width": 4, "height": 4})).unwrap(); // Two buffer allocations (sample, result), then the 12 ring pixels of the 4x4 selection seed the @@ -785,7 +785,7 @@ fn lasso_over_its_rows_matches_the_whole_canvas() { lo + (seed % 10_000) as f32 / 10_000.0 * (hi - lo) }; for case in 0..24 { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 520})).unwrap(); s.execute("select.rect", json!({"x": 40, "y": 60, "width": 200, "height": 300})).unwrap(); let n = 3 + case % 7; @@ -852,7 +852,7 @@ fn windowed_tool_feather_matches_full_canvas() { let mask = sel::feather(&input, area.width() as usize, area.height() as usize, radius); for m in ["replace", "add", "subtract", "intersect"] { for has_old in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": area.width(), "height": area.height()})).unwrap(); if has_old { s.edit("soft selection", |doc, _| { @@ -895,7 +895,7 @@ fn windowed_tool_feather_matches_full_canvas() { #[test] fn small_feathered_tools_work_on_large_sparse_documents_at_every_depth() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000, "depth": depth, "background": "transparent"})).unwrap(); for ellipse in [false, true] { s.execute("select.rect", json!({"x": 3000, "y": 2000, "width": 50, "height": 50, "ellipse": ellipse, "feather": 4})).unwrap(); diff --git a/crates/engine/src/cmd/selection_cmds/wand_seed_outside_tests.rs b/crates/engine-core/src/cmd/selection_cmds/wand_seed_outside_tests.rs similarity index 99% rename from crates/engine/src/cmd/selection_cmds/wand_seed_outside_tests.rs rename to crates/engine-core/src/cmd/selection_cmds/wand_seed_outside_tests.rs index 51540e3cfd..f6cbd33950 100644 --- a/crates/engine/src/cmd/selection_cmds/wand_seed_outside_tests.rs +++ b/crates/engine-core/src/cmd/selection_cmds/wand_seed_outside_tests.rs @@ -8,7 +8,7 @@ use crate::Session; /// 800 × 600, white, with a grey ramp of ten 40 px blocks from x 100 (100, 105, …, 145). fn ramp() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); for k in 0..10 { let v = 100 + 5 * k; diff --git a/crates/engine/src/cmd/slice_cmds.rs b/crates/engine-core/src/cmd/slice_cmds.rs similarity index 100% rename from crates/engine/src/cmd/slice_cmds.rs rename to crates/engine-core/src/cmd/slice_cmds.rs diff --git a/crates/engine/src/cmd/slice_cmds/tests.rs b/crates/engine-core/src/cmd/slice_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/slice_cmds/tests.rs rename to crates/engine-core/src/cmd/slice_cmds/tests.rs index 7e37fef365..087637f320 100644 --- a/crates/engine/src/cmd/slice_cmds/tests.rs +++ b/crates/engine-core/src/cmd/slice_cmds/tests.rs @@ -3,7 +3,7 @@ use photocraft_doc::LayerId; use photocraft_doc::effects::Effect; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 90, "depth": depth, "name": "site"})).unwrap(); s } @@ -379,7 +379,7 @@ fn divide_by_size_cuts_parts_that_long_and_the_last_takes_the_rest() { fn divide_refuses_more_parts_than_one_division_makes() { // #1020: 1000 x 1000 was accepted (a million slices), and resolving the list is quadratic in // the slice count. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1000, "height": 1000})).unwrap(); s.execute("slice.new", json!({"rect": [0, 0, 1000, 1000]})).unwrap(); let id = doc(&s).slices.list[0].id; diff --git a/crates/engine/src/cmd/smart_cmds.rs b/crates/engine-core/src/cmd/smart_cmds.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds.rs rename to crates/engine-core/src/cmd/smart_cmds.rs diff --git a/crates/engine/src/cmd/smart_cmds/contents.rs b/crates/engine-core/src/cmd/smart_cmds/contents.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/contents.rs rename to crates/engine-core/src/cmd/smart_cmds/contents.rs diff --git a/crates/engine/src/cmd/smart_cmds/filters.rs b/crates/engine-core/src/cmd/smart_cmds/filters.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/filters.rs rename to crates/engine-core/src/cmd/smart_cmds/filters.rs diff --git a/crates/engine/src/cmd/smart_cmds/placing.rs b/crates/engine-core/src/cmd/smart_cmds/placing.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/placing.rs rename to crates/engine-core/src/cmd/smart_cmds/placing.rs diff --git a/crates/engine/src/cmd/smart_cmds/rendering.rs b/crates/engine-core/src/cmd/smart_cmds/rendering.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/rendering.rs rename to crates/engine-core/src/cmd/smart_cmds/rendering.rs diff --git a/crates/engine/src/cmd/smart_cmds/source.rs b/crates/engine-core/src/cmd/smart_cmds/source.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/source.rs rename to crates/engine-core/src/cmd/smart_cmds/source.rs diff --git a/crates/engine/src/cmd/smart_cmds/stack_cache.rs b/crates/engine-core/src/cmd/smart_cmds/stack_cache.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/stack_cache.rs rename to crates/engine-core/src/cmd/smart_cmds/stack_cache.rs diff --git a/crates/engine/src/cmd/smart_cmds/tests.rs b/crates/engine-core/src/cmd/smart_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/smart_cmds/tests.rs rename to crates/engine-core/src/cmd/smart_cmds/tests.rs index 8465f33719..6ee2584ecf 100644 --- a/crates/engine/src/cmd/smart_cmds/tests.rs +++ b/crates/engine-core/src/cmd/smart_cmds/tests.rs @@ -83,7 +83,7 @@ fn non_normal_coverage_changes_retain_source_over_semantics() { /// A `depth`-bit document with one empty layer. fn session(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s @@ -662,7 +662,7 @@ fn reset_transform_refuses_a_stack_it_cannot_re_render() { /// Enabled for a smart object only, and one undo step back (#11662). #[test] fn reset_transform_needs_a_smart_object_and_undoes_in_one_step() { - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(!empty.is_enabled("layer.smartObjects.resetTransform"), "no document"); assert!(empty.execute("layer.smartObjects.resetTransform", json!({})).is_err()); let mut s = session(8); @@ -792,7 +792,7 @@ fn pcraft_round_trip_keeps_live_smart_objects() { assert_eq!(b.smart_filters.len(), 2); assert!(b.filter_mask.is_some()); // Still live after loading: re-editing works and matches a fresh render. - let mut s2 = Session::new(); + let mut s2 = crate::session(); s2.add_document(back, None); s2.select_layer(id).unwrap(); s2.execute("layer.smartFilter.setVisible", json!({"index": 1, "visible": false})).unwrap(); @@ -894,6 +894,7 @@ fn export_replace_and_linked_contents() { #[test] fn commands_are_registered_with_catalog_ids() { + crate::install().unwrap(); for id in [ "layer.smartObjects.convertToSmartObject", "filter.convertForSmartFilters", @@ -917,7 +918,7 @@ fn commands_are_registered_with_catalog_ids() { let spec = crate::commands::find(id).unwrap_or_else(|| panic!("{id}")); assert!(!spec.menu.is_empty(), "{id}"); } - let s = Session::new(); + let s = crate::session(); assert!(!s.is_enabled("layer.smartObjects.convertToSmartObject")); assert!(!s.is_enabled("layer.smartObjects.editContents")); } @@ -1143,7 +1144,7 @@ fn convert_to_layers_keeps_a_knockout_inside_a_group() { for knockout in ["none", "shallow", "deep"] { for (blend, mode, opacity) in [("normal", BlendMode::Normal, 1.0), ("multiply", BlendMode::Multiply, 0.6)] { let case = format!("{knockout}, {blend} at {opacity}"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H})).unwrap(); fill(&mut s, Rect::new(0, 0, W, H), [0.0, 0.0, 1.0, 1.0]); s.execute("layer.new.layer", json!({})).unwrap(); @@ -1356,7 +1357,7 @@ fn automation_smart_contents_checks_nested_reads_at_nontrivial_placements() { Some(cache), )), )); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(parent, None); s.authorize = Some(deny_contents_paths); let before = s.active().unwrap().doc.clone(); diff --git a/crates/engine/src/cmd/smart_cmds/tests/filter_mask_paint.rs b/crates/engine-core/src/cmd/smart_cmds/tests/filter_mask_paint.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/tests/filter_mask_paint.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/filter_mask_paint.rs diff --git a/crates/engine/src/cmd/smart_cmds/tests/selection.rs b/crates/engine-core/src/cmd/smart_cmds/tests/selection.rs similarity index 99% rename from crates/engine/src/cmd/smart_cmds/tests/selection.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/selection.rs index 793499f6f4..9d22d9713a 100644 --- a/crates/engine/src/cmd/smart_cmds/tests/selection.rs +++ b/crates/engine-core/src/cmd/smart_cmds/tests/selection.rs @@ -8,7 +8,7 @@ fn pixel(doc: &Document, name: &str, bounds: Rect, rgba: [f32; 4]) -> Layer { } fn selected_session(doc: Document, ids: &[LayerId]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); crate::layer_multi_cmds::set_selection(&mut s, ids.to_vec(), ids.last().copied(), None).unwrap(); s diff --git a/crates/engine/src/cmd/smart_cmds/tests/source_flatten.rs b/crates/engine-core/src/cmd/smart_cmds/tests/source_flatten.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/tests/source_flatten.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/source_flatten.rs diff --git a/crates/engine/src/cmd/smart_cmds/tests/source_work.rs b/crates/engine-core/src/cmd/smart_cmds/tests/source_work.rs similarity index 99% rename from crates/engine/src/cmd/smart_cmds/tests/source_work.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/source_work.rs index e8124c624f..da9c0cef81 100644 --- a/crates/engine/src/cmd/smart_cmds/tests/source_work.rs +++ b/crates/engine-core/src/cmd/smart_cmds/tests/source_work.rs @@ -28,7 +28,7 @@ fn saved_svgz_refresh_keeps_native_size_pixels_and_place_reports_omissions() { let svg = br#""#; let encoded = gzip(svg); let name = "saved-refresh.svgz"; - let mut session = crate::Session::new(); + let mut session = crate::session(); session.execute("file.new", serde_json::json!({"width":32,"height":32})).unwrap(); let placed = crate::file_cmds::place_bytes(&mut session, name, encoded.clone(), None, &serde_json::json!({"smartObject":true,"scale":175})).unwrap(); let warnings = placed["warnings"].as_array().unwrap(); diff --git a/crates/engine/src/cmd/smart_cmds/tests/stack_cache.rs b/crates/engine-core/src/cmd/smart_cmds/tests/stack_cache.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/tests/stack_cache.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/stack_cache.rs diff --git a/crates/engine/src/cmd/smart_cmds/tests/svg_profile.rs b/crates/engine-core/src/cmd/smart_cmds/tests/svg_profile.rs similarity index 99% rename from crates/engine/src/cmd/smart_cmds/tests/svg_profile.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/svg_profile.rs index ffcdfb8ffc..12d4a03461 100644 --- a/crates/engine/src/cmd/smart_cmds/tests/svg_profile.rs +++ b/crates/engine-core/src/cmd/smart_cmds/tests/svg_profile.rs @@ -59,7 +59,7 @@ fn svg_stack_mode_refuses_frames_past_its_budget() { fn ordinary_layered_svg_contents_replace_and_convert_to_layers() { let rects: String = (0..12).map(|i| format!("", i * 150)).collect(); let svg = format!("{rects}"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1920, "height": 1080})).unwrap(); crate::file_cmds::place_bytes(&mut s, "Layout.svg", svg.clone().into_bytes(), None, &json!({"smartObject": true})).unwrap(); let dir = std::env::temp_dir().join(format!("pcraft-svg-layout-{}", std::process::id())); @@ -79,7 +79,7 @@ fn ordinary_layered_svg_contents_replace_and_convert_to_layers() { #[test] fn convert_to_layers_unpacks_full_canvas_shapes_in_a_4k_document() { let svg = format!("{}", "".repeat(4)); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 3840, "height": 2160})).unwrap(); let placed = crate::file_cmds::place_bytes(&mut s, "Full.svg", svg.into_bytes(), None, &json!({"smartObject": true})).unwrap(); let id = LayerId(placed["layer"].as_u64().unwrap()); @@ -96,7 +96,7 @@ fn svg_with_an_unreadable_embedded_image_still_places() { let svg = format!( "" ); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let placed = crate::file_cmds::place_bytes(&mut s, "Logo.svg", svg.as_bytes().to_vec(), None, &json!({"smartObject": true})).unwrap(); let warnings = placed["warnings"].as_array().unwrap(); diff --git a/crates/engine/src/cmd/smart_cmds/tests/svg_stack_completeness.rs b/crates/engine-core/src/cmd/smart_cmds/tests/svg_stack_completeness.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/tests/svg_stack_completeness.rs rename to crates/engine-core/src/cmd/smart_cmds/tests/svg_stack_completeness.rs diff --git a/crates/engine/src/cmd/smart_cmds/unpack.rs b/crates/engine-core/src/cmd/smart_cmds/unpack.rs similarity index 100% rename from crates/engine/src/cmd/smart_cmds/unpack.rs rename to crates/engine-core/src/cmd/smart_cmds/unpack.rs diff --git a/crates/engine/src/cmd/smart_svg_cmds.rs b/crates/engine-core/src/cmd/smart_svg_cmds.rs similarity index 100% rename from crates/engine/src/cmd/smart_svg_cmds.rs rename to crates/engine-core/src/cmd/smart_svg_cmds.rs diff --git a/crates/engine/src/cmd/smart_svg_cmds/source_cache_tests.rs b/crates/engine-core/src/cmd/smart_svg_cmds/source_cache_tests.rs similarity index 99% rename from crates/engine/src/cmd/smart_svg_cmds/source_cache_tests.rs rename to crates/engine-core/src/cmd/smart_svg_cmds/source_cache_tests.rs index f65a3d88ea..09da081a86 100644 --- a/crates/engine/src/cmd/smart_svg_cmds/source_cache_tests.rs +++ b/crates/engine-core/src/cmd/smart_svg_cmds/source_cache_tests.rs @@ -43,7 +43,7 @@ fn draw(sources: &mut WarningRenderSources<'_>, sm: &SmartObject) -> photocraft_ } fn shared_session(instances: usize) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":32,"height":32})).unwrap(); let original = br#""#; let placed = crate::file_cmds::place_bytes(&mut s, "Shared.svg", original.to_vec(), None, &json!({"smartObject":true})).unwrap(); diff --git a/crates/engine/src/cmd/smart_svg_cmds/tests.rs b/crates/engine-core/src/cmd/smart_svg_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/smart_svg_cmds/tests.rs rename to crates/engine-core/src/cmd/smart_svg_cmds/tests.rs index 088d37a033..cb3c73ddb8 100644 --- a/crates/engine/src/cmd/smart_svg_cmds/tests.rs +++ b/crates/engine-core/src/cmd/smart_svg_cmds/tests.rs @@ -7,7 +7,7 @@ const BLUE: &str = r#""#; fn session(depth: u32) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":32,"height":24,"depth":depth})).unwrap(); let result = crate::file_cmds::place_bytes(&mut s, "Artwork.svg", RED.as_bytes().to_vec(), None, &json!({"smartObject":true})).unwrap(); let id = LayerId(result["layer"].as_u64().unwrap()); diff --git a/crates/engine/src/cmd/smartselect_cmds.rs b/crates/engine-core/src/cmd/smartselect_cmds.rs similarity index 100% rename from crates/engine/src/cmd/smartselect_cmds.rs rename to crates/engine-core/src/cmd/smartselect_cmds.rs diff --git a/crates/engine/src/cmd/smartselect_cmds/object_hard_edge_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/object_hard_edge_tests.rs similarity index 99% rename from crates/engine/src/cmd/smartselect_cmds/object_hard_edge_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/object_hard_edge_tests.rs index 664466eee3..3cf6f35348 100644 --- a/crates/engine/src/cmd/smartselect_cmds/object_hard_edge_tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/object_hard_edge_tests.rs @@ -11,7 +11,7 @@ fn inside(x: i32, y: i32) -> bool { } fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": depth})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -202,7 +202,7 @@ fn the_params_string_documents_hard_edge() { /// transparent layer with a red (220,30,30) rectangle 100,100-300,250 and a blue (30,30,220) /// anti-aliased disc, centre 500,175, radius 75 (8x8 samples a pixel). fn reference_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, _| { diff --git a/crates/engine/src/cmd/smartselect_cmds/object_mode_refusal_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/object_mode_refusal_tests.rs similarity index 99% rename from crates/engine/src/cmd/smartselect_cmds/object_mode_refusal_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/object_mode_refusal_tests.rs index d8b4f0f3b7..f89f04b2cd 100644 --- a/crates/engine/src/cmd/smartselect_cmds/object_mode_refusal_tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/object_mode_refusal_tests.rs @@ -17,7 +17,7 @@ pub(super) fn session(mode: ColorMode, depth: SampleType) -> Session { let bg = doc.layers[0].surface_mut().unwrap(); let light = photocraft_raster::from_rgba(&bg.format(), [0.9, 0.9, 0.9, 1.0]); bg.fill_rect(Rect::new(20, 20, 44, 44), &light); - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); s } diff --git a/crates/engine/src/cmd/smartselect_cmds/object_transparent_layer_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/object_transparent_layer_tests.rs similarity index 98% rename from crates/engine/src/cmd/smartselect_cmds/object_transparent_layer_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/object_transparent_layer_tests.rs index 47b809a9cb..950e03d1c8 100644 --- a/crates/engine/src/cmd/smartselect_cmds/object_transparent_layer_tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/object_transparent_layer_tests.rs @@ -11,7 +11,7 @@ const H: u32 = 600; /// The issue's document: white Background, then a transparent pixel layer holding a red /// rectangle, a blue disc and a ten-block grey ramp (100, 105, …, 145 from x 100). fn issue_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); paint_new_layer(&mut s, W, H, |x, y| { @@ -34,7 +34,7 @@ fn issue_document() -> Session { /// A Grayscale 8-bit document with a grey-87 rectangle on a transparent layer. fn gray_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "mode": "gray", "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); paint_new_layer(&mut s, 400, 300, |x, y| { @@ -146,7 +146,7 @@ const HOLE: [u32; 2] = [242, 217]; /// A 1 px hole is transparent on the selected layer and opaque in the composite. fn one_pixel_hole() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "background": "transparent"})).unwrap(); for hole in [false, true] { if hole { diff --git a/crates/engine/src/cmd/smartselect_cmds/quick_drop_transparent_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/quick_drop_transparent_tests.rs similarity index 99% rename from crates/engine/src/cmd/smartselect_cmds/quick_drop_transparent_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/quick_drop_transparent_tests.rs index 2f7582e74b..89e822e57e 100644 --- a/crates/engine/src/cmd/smartselect_cmds/quick_drop_transparent_tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/quick_drop_transparent_tests.rs @@ -15,7 +15,7 @@ const RED1: [i32; 4] = [100, 100, 300, 250]; const RED2: [i32; 4] = [500, 100, 600, 200]; fn issue_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Shapes"})).unwrap(); for [x0, y0, x1, y1] in [RED1, RED2] { diff --git a/crates/engine/src/cmd/smartselect_cmds/quick_enhance_edge_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/quick_enhance_edge_tests.rs similarity index 99% rename from crates/engine/src/cmd/smartselect_cmds/quick_enhance_edge_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/quick_enhance_edge_tests.rs index e108d71f8a..880213e6e7 100644 --- a/crates/engine/src/cmd/smartselect_cmds/quick_enhance_edge_tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/quick_enhance_edge_tests.rs @@ -21,7 +21,7 @@ const CLICK: (f32, f32) = (200.0, 175.0); /// The issue's document: white Background, then the pixel layer Shapes (active) holding "red 1". fn shapes_document(w: i32, h: i32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Shapes"})).unwrap(); fill_rect(&mut s, RECT, "#dc1e1e"); @@ -192,7 +192,7 @@ fn enhance_edge_gives_the_same_rim_on_a_smaller_shape() { fn enhance_edge_gives_the_same_rim_in_a_16_bit_document() { let mut eight = shapes_document(W, H); quick_click(&mut eight, true); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": 16})).unwrap(); s.execute("layer.new.layer", json!({"name": "Shapes"})).unwrap(); fill_rect(&mut s, RECT, "#dc1e1e"); @@ -266,7 +266,7 @@ fn select_and_mask_feathering_and_shift_edge_are_unchanged() { /// the edges away from the border get the same soft rim. Guard on the border, red on the rim. #[test] fn enhance_edge_keeps_a_cut_at_the_document_border_fully_selected_there() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Blue"})).unwrap(); fill_rect(&mut s, [0, 0, 300, 200], "#1e3cdc"); diff --git a/crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/quick_group_target_tests.rs similarity index 99% rename from crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/quick_group_target_tests.rs index fec29d8167..8c1fc454c5 100644 --- a/crates/engine/src/cmd/smartselect_cmds/quick_group_target_tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/quick_group_target_tests.rs @@ -15,7 +15,7 @@ const RED2_CLICK: [f32; 2] = [550.0, 150.0]; /// 100,100-300,250 ("red 1") and 500,100-600,200 ("red 2"); an empty pixel layer Blue on top; then /// a new, empty group, which is left active. fn issue_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": W, "height": H, "depth": 8})).unwrap(); s.execute("layer.new.layer", json!({"name": "Shapes"})).unwrap(); for [x, y, w, h] in [[100, 100, 200, 150], [500, 100, 100, 100]] { diff --git a/crates/engine/src/cmd/smartselect_cmds/quick_mode_refusal_tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/quick_mode_refusal_tests.rs similarity index 100% rename from crates/engine/src/cmd/smartselect_cmds/quick_mode_refusal_tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/quick_mode_refusal_tests.rs diff --git a/crates/engine/src/cmd/smartselect_cmds/tests.rs b/crates/engine-core/src/cmd/smartselect_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/smartselect_cmds/tests.rs rename to crates/engine-core/src/cmd/smartselect_cmds/tests.rs index 823e0883b5..f62614971f 100644 --- a/crates/engine/src/cmd/smartselect_cmds/tests.rs +++ b/crates/engine-core/src/cmd/smartselect_cmds/tests.rs @@ -3,7 +3,7 @@ use photocraft_algo::segment::Rng; /// A document whose background shows `px(x, y)` (RGB, 0–1), at the given depth. fn session_with(w: u32, h: u32, depth: u32, px: impl Fn(u32, u32) -> [f32; 3]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "depth": depth})).unwrap(); s.edit("paint", |doc, _| { let bg = doc.layers[0].surface_mut().unwrap(); @@ -549,7 +549,7 @@ fn sel_bytes(s: &Session, w: i32, h: i32) -> Vec { /// Huge sparse selections refine without a dense bounding-box result. #[test] fn refine_edge_accepts_huge_sparse_and_solid_selections() { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::new("huge", photocraft_doc::Size::new(100_000, 100_000), photocraft_doc::ColorMode::Rgb, photocraft_color::SampleType::U8), None); s.execute("select.rect", json!({"x": 10, "y": 60, "width": 10, "height": 10})).unwrap(); s.execute("select.refineEdge", json!({"edits": [{"tool": "brush", "points": [[0, 0], [99_999, 99_999]], "size": 1}]})).expect("sparse refine"); @@ -573,7 +573,7 @@ fn refine_edge_accepts_huge_sparse_and_solid_selections() { /// stays as it was. #[test] fn refine_edge_refuses_edits_that_cross_too_many_tiles() { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::new("huge", photocraft_doc::Size::new(100_000, 100_000), photocraft_doc::ColorMode::Rgb, photocraft_color::SampleType::U8), None); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 10, "height": 10})).unwrap(); let before = s.active().and_then(|d| d.doc.selection.clone()).expect("selected"); @@ -703,7 +703,7 @@ fn refine_edge_rejects_bad_edits_and_keeps_the_selection() { #[test] fn refine_edge_rejects_excessive_scratch_before_changing_selection() { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(Document::new("scratch", photocraft_doc::Size::new(10_000, 10_000), photocraft_doc::ColorMode::Rgb, photocraft_color::SampleType::U8), None); s.execute("select.rect", json!({"x": 5000, "y": 5000, "width": 1, "height": 1})).unwrap(); let before = s.active().unwrap().doc.selection.clone(); diff --git a/crates/engine/src/cmd/solid_fill_cmds.rs b/crates/engine-core/src/cmd/solid_fill_cmds.rs similarity index 98% rename from crates/engine/src/cmd/solid_fill_cmds.rs rename to crates/engine-core/src/cmd/solid_fill_cmds.rs index 5763868d25..b61ec7172f 100644 --- a/crates/engine/src/cmd/solid_fill_cmds.rs +++ b/crates/engine-core/src/cmd/solid_fill_cmds.rs @@ -97,7 +97,7 @@ mod tests { #[test] fn named_nonactive_solid_fill_can_be_edited() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let id = s.execute("layer.newFillLayer.solidColor", json!({"color": "#000000"})).unwrap()["layer"].as_u64().unwrap(); let name = s.active().unwrap().doc.layer(photocraft_doc::LayerId(id)).unwrap().name.clone(); @@ -119,7 +119,7 @@ mod tests { LayerContent::Fill(Fill::Solid(c)) => c, _ => panic!("not a solid fill"), }; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("image.mode.cmyk", json!({})).unwrap(); let id = s.execute("layer.newFillLayer.solidColor", json!({"color": hex(inks), "cmyk": inks})).unwrap()["layer"].as_u64().unwrap(); @@ -140,7 +140,7 @@ mod tests { assert!(s.execute(SET, json!({"layer": id, "color": "#000000", "cmyk": bad})).is_err(), "{bad}"); } // An RGB document takes the colour, not the inks. - let mut rgb = Session::new(); + let mut rgb = crate::session(); rgb.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let id = rgb.execute("layer.newFillLayer.solidColor", json!({"color": "#336699", "cmyk": inks})).unwrap()["layer"].as_u64().unwrap(); assert_eq!(stored(&rgb, id).mode, ColorMode::Rgb); @@ -149,7 +149,7 @@ mod tests { #[test] fn edit_preserves_layer_and_masks_at_all_depths_and_undo_redo() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 24, "depth": depth})).unwrap(); let id = s.execute("layer.newFillLayer.solidColor", json!({"color": "#12345680"})).unwrap()["layer"].as_u64().unwrap(); s.execute("layer.layerMask.revealAll", json!({})).unwrap(); @@ -177,7 +177,7 @@ mod tests { #[test] fn bad_params_wrong_layer_and_stale_document_leave_history_untouched() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute(SET, json!({"color": "#ffffff"})).is_err()); s.execute("file.new", json!({"width": 2, "height": 2})).unwrap(); let pixels = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); @@ -204,7 +204,7 @@ mod tests { #[test] fn edits_respect_layer_and_transparency_locks() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 2})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({"color": "#12345680"})).unwrap(); for locks in [json!({"all": true}), json!({"all": false, "pixels": true}), json!({"pixels": false, "transparency": true})] { @@ -219,7 +219,7 @@ mod tests { #[test] fn rgb_picker_inputs_follow_document_mode_and_preserve_alpha() { for (mode_command, mode) in [(None, ColorMode::Rgb), (Some("image.mode.cmyk"), ColorMode::Cmyk), (Some("image.mode.lab"), ColorMode::Lab)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "depth": 16})).unwrap(); if let Some(cmd) = mode_command { s.execute(cmd, json!({})).unwrap(); @@ -263,7 +263,7 @@ mod tests { #[test] fn stored_colour_remains_exact_without_rgb_conversion_or_extra_history() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.execute("image.mode.cmyk", json!({})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({})).unwrap(); @@ -279,7 +279,7 @@ mod tests { #[test] fn invalid_rgb_components_leave_document_and_history_unchanged() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({})).unwrap(); let before = s.active().unwrap().doc.clone(); diff --git a/crates/engine/src/cmd/stamp_cmds.rs b/crates/engine-core/src/cmd/stamp_cmds.rs similarity index 99% rename from crates/engine/src/cmd/stamp_cmds.rs rename to crates/engine-core/src/cmd/stamp_cmds.rs index 8349141a11..38c2c5f7e3 100644 --- a/crates/engine/src/cmd/stamp_cmds.rs +++ b/crates/engine-core/src/cmd/stamp_cmds.rs @@ -210,7 +210,7 @@ mod tests { /// 64 × 64 at `depth`: a red Background, a blue square (16..48) on "Blue", and "Hidden" (green /// all over, hidden). The Blue layer is active. fn session(depth: u32) -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "depth": depth, "background": "#ff0000"})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; s.execute("layer.new.layer", json!({"name": "Hidden"})).unwrap(); @@ -340,7 +340,7 @@ mod tests { #[test] fn stamp_visible_fails_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("layer.stampVisible", json!({})).is_err(), "no document"); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; @@ -410,7 +410,7 @@ mod tests { s.execute("layer.select", json!({"layer": blue.0})).unwrap(); assert!(s.execute("layer.stampDown", json!({})).is_err()); assert!(s.active().unwrap().revision > rev); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute("layer.stampDown", json!({})).is_err(), "no document"); } @@ -429,10 +429,11 @@ mod tests { #[test] fn shortcuts_are_photoshops_and_rebindable() { + crate::install().unwrap(); let spec = |id: &str| crate::commands::find(id).unwrap(); assert_eq!(spec("layer.stampVisible").shortcut, Some("Cmd+Alt+Shift+E")); assert_eq!(spec("layer.stampDown").shortcut, Some("Cmd+Alt+E")); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.keyboardShortcuts", json!({"set": {"layer.stampVisible": "F7"}})).unwrap(); assert_eq!(s.prefs().shortcut("layer.stampVisible", Some("Cmd+Alt+Shift+E")), Some("F7")); assert_eq!(alt_variant("layer.mergeVisible"), Some("layer.stampVisible")); @@ -445,7 +446,7 @@ mod tests { #[test] #[ignore] fn stamp_visible_24mp() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 6000, "height": 4000})).unwrap(); for k in 0..3 { s.execute("layer.new.layer", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/style_asl_cmds.rs b/crates/engine-core/src/cmd/style_asl_cmds.rs similarity index 99% rename from crates/engine/src/cmd/style_asl_cmds.rs rename to crates/engine-core/src/cmd/style_asl_cmds.rs index 1a7eaf4fe1..d40709b1ee 100644 --- a/crates/engine/src/cmd/style_asl_cmds.rs +++ b/crates/engine-core/src/cmd/style_asl_cmds.rs @@ -167,7 +167,7 @@ mod tests { use photocraft_paint::tile::{b64_decode, b64_encode}; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s diff --git a/crates/engine/src/cmd/swatch_cmds.rs b/crates/engine-core/src/cmd/swatch_cmds.rs similarity index 100% rename from crates/engine/src/cmd/swatch_cmds.rs rename to crates/engine-core/src/cmd/swatch_cmds.rs diff --git a/crates/engine/src/cmd/swatch_cmds/act_zero_count_tests.rs b/crates/engine-core/src/cmd/swatch_cmds/act_zero_count_tests.rs similarity index 98% rename from crates/engine/src/cmd/swatch_cmds/act_zero_count_tests.rs rename to crates/engine-core/src/cmd/swatch_cmds/act_zero_count_tests.rs index 121113f3bd..89e0797f04 100644 --- a/crates/engine/src/cmd/swatch_cmds/act_zero_count_tests.rs +++ b/crates/engine-core/src/cmd/swatch_cmds/act_zero_count_tests.rs @@ -31,7 +31,7 @@ fn count_zero_loads_one_white_entry() { #[test] fn the_loaded_table_applies_and_saves_with_count_one() { let (colors, transparent) = act_table(&act(Some(0))).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("image.mode.indexedColor", json!({"palette": "uniform", "colors": 8, "dither": "none", "forced": "none"})).unwrap(); // What the dialog's OK sends after Load…. diff --git a/crates/engine/src/cmd/swatch_cmds/tests.rs b/crates/engine-core/src/cmd/swatch_cmds/tests.rs similarity index 97% rename from crates/engine/src/cmd/swatch_cmds/tests.rs rename to crates/engine-core/src/cmd/swatch_cmds/tests.rs index 3e3f16c52c..0275bb5904 100644 --- a/crates/engine/src/cmd/swatch_cmds/tests.rs +++ b/crates/engine-core/src/cmd/swatch_cmds/tests.rs @@ -16,7 +16,7 @@ fn export_bytes(s: &mut Session, p: Value) -> Vec { #[test] fn defaults_and_listing() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("swatches.list", json!({})).unwrap(); assert_eq!(r["count"], 46); assert_eq!(r["groups"][0]["name"], "Grays"); @@ -27,7 +27,7 @@ fn defaults_and_listing() { #[test] fn add_from_foreground_and_explicit_models() { - let mut s = Session::new(); + let mut s = crate::session(); s.tools.foreground = [1.0, 0.5, 0.0, 1.0]; let r = s.execute("swatches.add", json!({})).unwrap(); assert_eq!((r["name"].as_str(), r["group"].as_str()), (Some("Color Swatch 1"), Some("Grays"))); @@ -48,7 +48,7 @@ fn add_from_foreground_and_explicit_models() { #[test] fn use_sets_foreground_and_background_through_colour_management() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("swatches.use", json!({"swatch": "Red"})).unwrap(); assert_eq!(s.tools.foreground, [230.0 / 255.0, 40.0 / 255.0, 40.0 / 255.0, 1.0]); s.execute("swatches.use", json!({"index": 9, "target": "background"})).unwrap(); @@ -65,7 +65,7 @@ fn use_sets_foreground_and_background_through_colour_management() { /// instead of reading back as what its sRGB stand-in converts to (0/0/100/0 -> 5/1/92/0). #[test] fn using_a_cmyk_swatch_remembers_its_inks() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("swatches.add", json!({"name": "P 1-8 C", "kind": "spot", "color": {"model": "cmyk", "values": [0, 0, 100, 0]}})).unwrap(); s.execute("swatches.use", json!({"swatch": "P 1-8 C"})).unwrap(); let fg = s.tools.foreground; @@ -82,7 +82,7 @@ fn using_a_cmyk_swatch_remembers_its_inks() { #[test] fn rename_delete_move_and_groups() { - let mut s = Session::new(); + let mut s = crate::session(); // A group moves to an index, clamped to the list, and the change is saved with the prefs. let rev = s.presets.revision(); let r = s.execute("swatches.moveGroup", json!({"group": "Dark", "to": 0})).unwrap(); @@ -133,14 +133,14 @@ fn rename_delete_move_and_groups() { #[test] fn changes_persist_with_the_preferences() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("swatches.add", json!({"name": "Keep me", "color": {"model": "lab", "values": [40, 12.5, -7.25]}})).unwrap(); let saved = s.presets.to_json(&s); - let mut t = Session::new(); + let mut t = crate::session(); t.load_presets_json(saved); assert_eq!(t.presets.swatches, s.presets.swatches); // A prefs file from before swatches existed keeps the defaults. - let mut u = Session::new(); + let mut u = crate::session(); u.load_presets_json(json!({"gradients": null})); assert_eq!(u.presets.swatches, default_swatches()); } @@ -156,7 +156,7 @@ fn aco_round_trip_keeps_16_bit_values_and_books() { AcoSwatch { name: "Book".into(), color: AcoColor::Other { space: 3, values: [9, 8, 7, 6] } }, ]; let file = craft_psd::aco::write(&swatches).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("swatches.import", json!({"data": b64_encode(&file), "group": "Pro", "mode": "replace"})).unwrap(); assert_eq!((r["format"].as_str(), r["count"].as_u64()), (Some("aco"), Some(6))); assert_eq!(r["warnings"].as_array().unwrap().len(), 1, "the colour book is reported"); @@ -190,7 +190,7 @@ fn act_round_trip_loads_a_photoshop_color_table() { } let file = craft_psd::act::write(&colors, Some(256), Some(255)).unwrap(); assert_eq!(file.len(), 772); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("swatches.import", json!({"data": b64_encode(&file), "group": "Table", "mode": "replace"})).unwrap(); assert_eq!((r["format"].as_str(), r["count"].as_u64()), (Some("act"), Some(256))); assert_eq!(r["warnings"].as_array().unwrap().len(), 1, "the transparent color is reported"); @@ -225,7 +225,7 @@ fn act_that_starts_like_an_aco_is_still_an_act() { } for file in [craft_psd::act::write(&colors, None, None).unwrap(), craft_psd::act::write(&colors, Some(256), None).unwrap()] { assert_eq!(&file[..4], &[0, 1, 0, 5]); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("swatches.import", json!({"data": b64_encode(&file), "mode": "replace"})).unwrap(); assert_eq!((r["format"].as_str(), r["count"].as_u64()), (Some("act"), Some(256)), "{} bytes", file.len()); } @@ -233,7 +233,7 @@ fn act_that_starts_like_an_aco_is_still_an_act() { let swatches: Vec = (0..10u16).map(|i| AcoSwatch { name: format!("{i:0>25}"), color: AcoColor::Rgb([i * 1000, 0, 65535]) }).collect(); let file = craft_psd::aco::write(&swatches).unwrap(); assert_eq!(file.len(), craft_psd::act::PALETTE_LEN); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("swatches.import", json!({"data": b64_encode(&file), "mode": "replace"})).unwrap(); assert_eq!((r["format"].as_str(), r["count"].as_u64()), (Some("aco"), Some(10))); assert_eq!(s.presets.swatches[0].entries[9].name, format!("{:0>25}", 9)); @@ -256,7 +256,7 @@ fn ase_round_trip_keeps_groups_floats_and_kinds() { ], }; let bytes = craft_psd::ase::write(&src).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("swatches.import", json!({"data": b64_encode(&bytes), "group": "Exchange"})).unwrap(); assert_eq!(r["groups"], json!(["Exchange", "Brand"])); assert_eq!(r["count"], 4); @@ -299,7 +299,7 @@ fn ase_round_trip_keeps_groups_floats_and_kinds() { #[test] fn bad_params_fail_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); let before = s.presets.swatches.clone(); let cases: &[(&str, Value)] = &[ ("swatches.add", json!({"color": "#12"})), @@ -371,7 +371,7 @@ fn bad_params_fail_gracefully() { #[test] fn library_limits() { - let mut s = Session::new(); + let mut s = crate::session(); let one = vec![AcoSwatch { name: "x".into(), color: AcoColor::Gray(0) }; 60_000]; let file = b64_encode(&craft_psd::aco::write(&one).unwrap()); s.execute("swatches.import", json!({"data": file, "mode": "replace"})).unwrap(); @@ -391,7 +391,7 @@ fn library_limits() { fn unnamed_groups_are_numbered_in_linear_time() { let (tx, rx) = std::sync::mpsc::channel(); std::thread::spawn(move || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("swatches.newGroup", json!({"name": "Ink 2"})).unwrap(); let n = MAX_GROUPS - s.presets.swatches.len(); let paper = AseSwatch { name: "Paper".into(), color: AseColor::Gray(1.0), kind: AseKind::Process }; @@ -416,7 +416,7 @@ fn unnamed_groups_are_numbered_in_linear_time() { #[test] fn repeated_group_names_take_the_first_free_number() { - let mut s = Session::new(); + let mut s = crate::session(); for name in ["Brand", "Brand 2"] { s.execute("swatches.newGroup", json!({"name": name})).unwrap(); } @@ -432,7 +432,7 @@ fn repeated_group_names_take_the_first_free_number() { /// hue, which the prefs file stores as `null`; the next launch then dropped every saved preset. #[test] fn values_beyond_f32_range_are_rejected_so_presets_survive_a_restart() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("swatches.add", json!({"name": "Keep me", "color": {"model": "lab", "values": [40, 12.5, -7.25]}})).unwrap(); let before = s.presets.swatches.clone(); for (model, values) in [ @@ -449,7 +449,7 @@ fn values_beyond_f32_range_are_rejected_so_presets_survive_a_restart() { assert_eq!(s.presets.swatches, before, "a rejected colour leaves the library unchanged"); // The largest f32 hue is still accepted and stays finite. s.execute("swatches.add", json!({"name": "Big hue", "color": {"model": "hsb", "values": [f64::from(f32::MAX), 100, 100]}})).unwrap(); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(t.presets.swatches, s.presets.swatches, "user swatches survive a save and reload"); assert!(names(&t).contains(&"Keep me".to_string())); diff --git a/crates/engine/src/cmd/symmetry_cmds.rs b/crates/engine-core/src/cmd/symmetry_cmds.rs similarity index 98% rename from crates/engine/src/cmd/symmetry_cmds.rs rename to crates/engine-core/src/cmd/symmetry_cmds.rs index 97781c3ff3..a1da94f0c3 100644 --- a/crates/engine/src/cmd/symmetry_cmds.rs +++ b/crates/engine-core/src/cmd/symmetry_cmds.rs @@ -275,7 +275,7 @@ mod tests { #[test] fn invalid_and_empty_path_fail_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); assert!(s.execute("paint.symmetryFromPath", json!({"name": "missing"})).is_err()); assert!(s.execute("paint.symmetryFromPath", json!({"name": "work"})).is_err()); @@ -287,7 +287,7 @@ mod tests { #[test] fn canvas_edits_move_the_symmetry_with_the_pixels() { let preset = |s: &Session| s.active().unwrap().symmetry.as_ref().unwrap().preset().unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("paint.setSymmetry", json!({"mode": "vertical"})).unwrap(); s.execute("image.crop", json!({"x": 40, "y": 0, "width": 60, "height": 100})).unwrap(); @@ -310,7 +310,7 @@ mod tests { assert!((preset(&s).rotation - 315.0).abs() < 1e-9, "a flip keeps right angles (axes at 45° and 135° again): {}", preset(&s).rotation); // A path axis keeps lying on its (moved) source path. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("path.set", json!({"name": "work", "path": {"subpaths": [{"closed": false, "knots": [[40, 0], [60, 100]]}]}})).unwrap(); s.execute("paint.symmetryFromPath", json!({"name": "work"})).unwrap(); @@ -322,7 +322,7 @@ mod tests { #[test] fn symmetry_paints_mirrored_pixels_and_disable_stops_it() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "background": "white"})).unwrap(); s.execute("path.set", json!({"name": "work", "path": {"subpaths": [{"closed": false, "knots": [[40, 0], [40, 60]]}]}})).unwrap(); s.execute("paint.symmetryFromPath", json!({"name": "work"})).unwrap(); @@ -349,9 +349,9 @@ mod tests { #[test] fn stroke_on_axis_is_not_painted_twice_at_half_opacity() { - let mut plain = Session::new(); + let mut plain = crate::session(); plain.execute("file.new", json!({"width": 80, "height": 60, "background": "white"})).unwrap(); - let mut symmetric = Session::new(); + let mut symmetric = crate::session(); symmetric.execute("file.new", json!({"width": 80, "height": 60, "background": "white"})).unwrap(); symmetric.execute("path.set", json!({"name": "work", "path": {"subpaths": [{"closed": false, "knots": [[40, 0], [40, 60]]}]}})).unwrap(); symmetric.execute("paint.symmetryFromPath", json!({"name": "work"})).unwrap(); @@ -381,9 +381,9 @@ mod tests { #[test] fn mixed_axis_and_off_axis_stroke_unions_coverage_once() { - let mut plain = Session::new(); + let mut plain = crate::session(); plain.execute("file.new", json!({"width": 80, "height": 60, "background": "white"})).unwrap(); - let mut symmetric = Session::new(); + let mut symmetric = crate::session(); symmetric.execute("file.new", json!({"width": 80, "height": 60, "background": "white"})).unwrap(); symmetric.execute("path.set", json!({"name": "work", "path": {"subpaths": [{"closed": false, "knots": [[40, 0], [40, 60]]}]}})).unwrap(); symmetric.execute("paint.symmetryFromPath", json!({"name": "work"})).unwrap(); diff --git a/crates/engine/src/cmd/symmetry_cmds/preset_tests.rs b/crates/engine-core/src/cmd/symmetry_cmds/preset_tests.rs similarity index 99% rename from crates/engine/src/cmd/symmetry_cmds/preset_tests.rs rename to crates/engine-core/src/cmd/symmetry_cmds/preset_tests.rs index cdce342336..aa704fecbb 100644 --- a/crates/engine/src/cmd/symmetry_cmds/preset_tests.rs +++ b/crates/engine-core/src/cmd/symmetry_cmds/preset_tests.rs @@ -3,7 +3,7 @@ use crate::brush_cmds::LiveStroke; use photocraft_doc::{Layer, LayerMask}; fn session(depth: u8, mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":81,"height":61,"depth":depth,"mode":mode,"background":"white"})).unwrap(); s } @@ -54,7 +54,7 @@ fn presets_validate_atomically_and_leave_document_paths_and_history_untouched() assert!(s.active().unwrap().symmetry.is_none()); assert!(s.set_active(0)); assert!(s.active().unwrap().symmetry.is_some()); - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(!empty.is_enabled("paint.setSymmetry")); assert!(empty.execute("paint.setSymmetry", json!({"mode":"vertical"})).is_err()); } diff --git a/crates/engine/src/cmd/table.rs b/crates/engine-core/src/cmd/table.rs similarity index 100% rename from crates/engine/src/cmd/table.rs rename to crates/engine-core/src/cmd/table.rs diff --git a/crates/engine/src/cmd/table/core.rs b/crates/engine-core/src/cmd/table/core.rs similarity index 100% rename from crates/engine/src/cmd/table/core.rs rename to crates/engine-core/src/cmd/table/core.rs diff --git a/crates/engine/src/cmd/table/core/edit_menu.rs b/crates/engine-core/src/cmd/table/core/edit_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/core/edit_menu.rs rename to crates/engine-core/src/cmd/table/core/edit_menu.rs diff --git a/crates/engine/src/cmd/table/core/file_menu.rs b/crates/engine-core/src/cmd/table/core/file_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/core/file_menu.rs rename to crates/engine-core/src/cmd/table/core/file_menu.rs diff --git a/crates/engine/src/cmd/table/core/queries.rs b/crates/engine-core/src/cmd/table/core/queries.rs similarity index 100% rename from crates/engine/src/cmd/table/core/queries.rs rename to crates/engine-core/src/cmd/table/core/queries.rs diff --git a/crates/engine/src/cmd/table/core/select_menu.rs b/crates/engine-core/src/cmd/table/core/select_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/core/select_menu.rs rename to crates/engine-core/src/cmd/table/core/select_menu.rs diff --git a/crates/engine/src/cmd/table/core/tools.rs b/crates/engine-core/src/cmd/table/core/tools.rs similarity index 100% rename from crates/engine/src/cmd/table/core/tools.rs rename to crates/engine-core/src/cmd/table/core/tools.rs diff --git a/crates/engine/src/cmd/table/image.rs b/crates/engine-core/src/cmd/table/image.rs similarity index 100% rename from crates/engine/src/cmd/table/image.rs rename to crates/engine-core/src/cmd/table/image.rs diff --git a/crates/engine/src/cmd/table/image/adjustments.rs b/crates/engine-core/src/cmd/table/image/adjustments.rs similarity index 100% rename from crates/engine/src/cmd/table/image/adjustments.rs rename to crates/engine-core/src/cmd/table/image/adjustments.rs diff --git a/crates/engine/src/cmd/table/image/image_menu.rs b/crates/engine-core/src/cmd/table/image/image_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/image/image_menu.rs rename to crates/engine-core/src/cmd/table/image/image_menu.rs diff --git a/crates/engine/src/cmd/table/model.rs b/crates/engine-core/src/cmd/table/model.rs similarity index 100% rename from crates/engine/src/cmd/table/model.rs rename to crates/engine-core/src/cmd/table/model.rs diff --git a/crates/engine/src/cmd/table/model/edit_menu.rs b/crates/engine-core/src/cmd/table/model/edit_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/model/edit_menu.rs rename to crates/engine-core/src/cmd/table/model/edit_menu.rs diff --git a/crates/engine/src/cmd/table/model/image_menu.rs b/crates/engine-core/src/cmd/table/model/image_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/model/image_menu.rs rename to crates/engine-core/src/cmd/table/model/image_menu.rs diff --git a/crates/engine/src/cmd/table/model/layer_menu.rs b/crates/engine-core/src/cmd/table/model/layer_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/model/layer_menu.rs rename to crates/engine-core/src/cmd/table/model/layer_menu.rs diff --git a/crates/engine/src/cmd/table/paint.rs b/crates/engine-core/src/cmd/table/paint.rs similarity index 100% rename from crates/engine/src/cmd/table/paint.rs rename to crates/engine-core/src/cmd/table/paint.rs diff --git a/crates/engine/src/cmd/table/paint/edit_menu.rs b/crates/engine-core/src/cmd/table/paint/edit_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/paint/edit_menu.rs rename to crates/engine-core/src/cmd/table/paint/edit_menu.rs diff --git a/crates/engine/src/cmd/table/paint/stroke.rs b/crates/engine-core/src/cmd/table/paint/stroke.rs similarity index 100% rename from crates/engine/src/cmd/table/paint/stroke.rs rename to crates/engine-core/src/cmd/table/paint/stroke.rs diff --git a/crates/engine/src/cmd/table/store.rs b/crates/engine-core/src/cmd/table/store.rs similarity index 100% rename from crates/engine/src/cmd/table/store.rs rename to crates/engine-core/src/cmd/table/store.rs diff --git a/crates/engine/src/cmd/table/store/file_menu.rs b/crates/engine-core/src/cmd/table/store/file_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/store/file_menu.rs rename to crates/engine-core/src/cmd/table/store/file_menu.rs diff --git a/crates/engine/src/cmd/table/store/layer_menu.rs b/crates/engine-core/src/cmd/table/store/layer_menu.rs similarity index 100% rename from crates/engine/src/cmd/table/store/layer_menu.rs rename to crates/engine-core/src/cmd/table/store/layer_menu.rs diff --git a/crates/engine/src/cmd/timeline_cmds.rs b/crates/engine-core/src/cmd/timeline_cmds.rs similarity index 98% rename from crates/engine/src/cmd/timeline_cmds.rs rename to crates/engine-core/src/cmd/timeline_cmds.rs index 5f5136e8ed..cedda5497e 100644 --- a/crates/engine/src/cmd/timeline_cmds.rs +++ b/crates/engine-core/src/cmd/timeline_cmds.rs @@ -159,7 +159,7 @@ mod tests { #[test] fn create_navigate_delete() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); assert_eq!(s.execute("timeline.info", json!({})).unwrap()["timeline"], Value::Null); let r = s.execute("timeline.create", json!({"duration": 24, "fps": 24.0})).unwrap(); @@ -196,7 +196,7 @@ mod tests { /// panicked in `i64::clamp`. Bad values are now rejected before anything changes. #[test] fn create_rejects_out_of_range_params() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("timeline.create", json!({"duration": 24, "fps": 24.0})).unwrap(); s.execute("timeline.setFrame", json!({"frame": 5})).unwrap(); @@ -241,7 +241,7 @@ mod tests { /// #1009: `timeline.setProps` could store the same out-of-range `duration` and `fps`. #[test] fn set_props_rejects_out_of_range_params() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("timeline.create", json!({"duration": 24, "fps": 24.0})).unwrap(); let before = snapshot(&s); @@ -259,7 +259,7 @@ mod tests { #[test] fn set_props_longer_duration_moves_full_work_area() { let work = |r: &Value| (r["timeline"]["workStart"].as_u64(), r["timeline"]["workEnd"].as_u64()); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("timeline.create", json!({"duration": 30})).unwrap(); let r = s.execute("timeline.setProps", json!({"duration": 60})).unwrap(); @@ -278,7 +278,7 @@ mod tests { for duration in [0, 1, usize::MAX] { for current in [0, usize::MAX] { for (cmd, delta) in [("timeline.nextFrame", 1i64), ("timeline.previousFrame", -1)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let st = s.active_mut().unwrap(); let mut doc = (*st.doc).clone(); @@ -299,7 +299,7 @@ mod tests { #[test] fn navigation_without_timeline_errors() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); assert!(s.execute("timeline.setFrame", json!({"frame": 1})).is_err()); } diff --git a/crates/engine/src/cmd/transform_cmds.rs b/crates/engine-core/src/cmd/transform_cmds.rs similarity index 100% rename from crates/engine/src/cmd/transform_cmds.rs rename to crates/engine-core/src/cmd/transform_cmds.rs diff --git a/crates/engine/src/cmd/transform_cmds/multi_tests.rs b/crates/engine-core/src/cmd/transform_cmds/multi_tests.rs similarity index 99% rename from crates/engine/src/cmd/transform_cmds/multi_tests.rs rename to crates/engine-core/src/cmd/transform_cmds/multi_tests.rs index 7eff291b7a..449bb4fee9 100644 --- a/crates/engine/src/cmd/transform_cmds/multi_tests.rs +++ b/crates/engine-core/src/cmd/transform_cmds/multi_tests.rs @@ -5,7 +5,7 @@ use super::*; /// A 200 x 200 document: a red 40 x 20 block on "Paint" (x 10..50, y 10..30) and a type layer /// over it, both selected, the type layer active (as after creating it and ⌘-clicking Paint). fn two_layers() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "background": "white"})).unwrap(); let paint = LayerId(s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap()["layer"].as_u64().unwrap()); s.edit("paint", |doc, _| { @@ -280,7 +280,7 @@ fn a_recorded_transform_of_the_selected_layers_replays_on_the_selection_in_anoth /// A 200 x 200 document with three 20 x 20 blocks, "A" (x 10..30), "B" (x 60..80) and "C" /// (x 120..140), all at y 10..30. A and B are linked; C isn't. Only A is selected, and active. fn linked_layers() -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "background": "white"})).unwrap(); let mut ids = Vec::new(); for (name, x) in [("A", 10), ("B", 60), ("C", 120)] { @@ -387,7 +387,7 @@ fn a_locked_linked_layer_refuses_the_transform_of_its_link_group() { /// The Background (white, 200 x 200) linked to "A", a red block at x 10..30, y 10..30; A is /// selected, and active. fn background_linked_to_a_layer() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "background": "white"})).unwrap(); let bg = s.active().unwrap().doc.layers[0].id; let a = LayerId(s.execute("layer.new.layer", json!({"name": "A"})).unwrap()["layer"].as_u64().unwrap()); diff --git a/crates/engine/src/cmd/transform_cmds/reconciliation_tests.rs b/crates/engine-core/src/cmd/transform_cmds/reconciliation_tests.rs similarity index 99% rename from crates/engine/src/cmd/transform_cmds/reconciliation_tests.rs rename to crates/engine-core/src/cmd/transform_cmds/reconciliation_tests.rs index 04e990daae..203362d7fb 100644 --- a/crates/engine/src/cmd/transform_cmds/reconciliation_tests.rs +++ b/crates/engine-core/src/cmd/transform_cmds/reconciliation_tests.rs @@ -5,7 +5,7 @@ fn session() -> Session { } fn session_depth(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { diff --git a/crates/engine/src/cmd/transform_cmds/tests.rs b/crates/engine-core/src/cmd/transform_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/transform_cmds/tests.rs rename to crates/engine-core/src/cmd/transform_cmds/tests.rs index 124e69198d..fd0eb554be 100644 --- a/crates/engine/src/cmd/transform_cmds/tests.rs +++ b/crates/engine-core/src/cmd/transform_cmds/tests.rs @@ -5,7 +5,7 @@ fn session() -> Session { } fn session_depth(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -93,7 +93,7 @@ fn a_gigapixel_layer_transforms_within_memory_usage() { /// A 16 x 16 document whose active layer is a 1 x 8 column at x = 10. fn column() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -232,7 +232,7 @@ fn affine_matrix_and_perspective() { #[test] fn background_becomes_layer_0() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("edit.transform", json!({"quad": [[0, 0], [20, 0], [20, 20], [0, 20]]})).unwrap(); let st = s.active().unwrap(); @@ -312,7 +312,7 @@ fn type_layers_transform_as_vectors() { #[test] fn shapes_move_and_transform_as_vectors() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); s.execute("shape.create", json!({"kind": "rect", "rect": [10, 10, 40, 20], "fill": "#ff0000"})).unwrap(); s.execute("layer.translate", json!({"dx": 30, "dy": 5})).unwrap(); @@ -581,7 +581,7 @@ fn split_gray_selected_rejects_non_gray() { /// Transform (and the frame-based presets) act on the whole type layer. #[test] fn a_selection_does_not_narrow_a_type_layers_frame() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 120})).unwrap(); s.execute("type.create", json!({"x": 20, "y": 60, "text": "Hello", "size": 36})).unwrap(); let whole = active_bounds(&s); @@ -623,7 +623,7 @@ fn the_frame_is_the_selections_own_bounds() { s.execute("select.rect", json!({"x": 60, "y": 60, "width": 10, "height": 10})).unwrap(); assert!(frame(&s).0.is_empty(), "nothing of the layer is selected"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 120})).unwrap(); s.execute("type.create", json!({"x": 20, "y": 60, "text": "Hello", "size": 36})).unwrap(); let whole = active_bounds(&s); @@ -693,7 +693,7 @@ fn group_transform_with_selection(selection: Rect) { #[test] fn feathered_selection_identity_transform_preserves_pixels() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "transparent"})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); s.execute("select.rect", json!({"x": 4, "y": 4, "width": 8, "height": 8})).unwrap(); @@ -731,7 +731,7 @@ fn feathered_selection_identity_transform_preserves_pixels() { /// A 1 x 8 px column on a 256 x 256 canvas (#3773). fn column_session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 256, "height": 256})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -766,7 +766,7 @@ fn a_one_pixel_column_stretches_5000_percent() { /// The technique as done in Photoshop: select a 1 px column of an image and stretch it across. #[test] fn a_selected_column_stretches_solid_over_the_image() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 256, "height": 256})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -790,7 +790,7 @@ fn a_selected_column_stretches_solid_over_the_image() { /// three canvas widths right and back comes back whole. #[test] fn a_layer_moved_far_off_the_canvas_and_back_keeps_its_pixels() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -818,7 +818,7 @@ fn a_layer_moved_far_off_the_canvas_and_back_keeps_its_pixels() { #[test] fn relative_params_scale_and_rotate_about_the_frame_centre() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 20, "y": 30, "width": 40, "height": 20})).unwrap(); @@ -847,7 +847,7 @@ fn relative_params_scale_and_rotate_about_the_frame_centre() { /// shape for Free Transform, the Move tool's controls and snapping, never the canvas. #[test] fn a_soft_shapes_frame_follows_its_path() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); let id = s.execute("shape.create", json!({"kind": "rect", "rect": [20, 30, 60, 40], "fill": "#000000"})).unwrap()["layer"].as_u64().unwrap(); let id = photocraft_doc::LayerId(id); @@ -886,7 +886,7 @@ fn a_soft_shapes_frame_follows_its_path() { #[test] fn a_stroked_soft_shapes_frame_matches_the_hard_shapes() { for (align, reach, x) in [("center", 5, 50), ("inside", 0, 50), ("outside", 10, 50), ("center", 5, -20)] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); let stroke = json!({"width": 10, "color": "#ff0000", "align": align, "join": "round"}); let id = s.execute("shape.create", json!({"kind": "rect", "rect": [x, 50, 60, 40], "fill": "#000000", "stroke": stroke})).unwrap()["layer"] @@ -913,7 +913,7 @@ fn a_stroked_soft_shapes_frame_matches_the_hard_shapes() { /// anti-aliased 60 px ellipse moved 150 px with Free Transform: no pixel left behind. #[test] fn transforming_a_layers_own_transparency_leaves_no_ghost() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 120, "background": "transparent"})).unwrap(); s.execute("select.rect", json!({"x": 20, "y": 20, "width": 60, "height": 60, "ellipse": true, "antiAlias": true})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#cc2222"})).unwrap(); diff --git a/crates/engine/src/cmd/trap_cmds.rs b/crates/engine-core/src/cmd/trap_cmds.rs similarity index 98% rename from crates/engine/src/cmd/trap_cmds.rs rename to crates/engine-core/src/cmd/trap_cmds.rs index 6bd99200ac..d8d658d12c 100644 --- a/crates/engine/src/cmd/trap_cmds.rs +++ b/crates/engine-core/src/cmd/trap_cmds.rs @@ -95,7 +95,7 @@ mod tests { #[test] fn traps_a_cmyk_document() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "mode": "cmyk"})).unwrap(); paint_halves(&mut s); @@ -120,7 +120,7 @@ mod tests { // pixels and the history as they were. for lock in [json!({"all": true}), json!({"pixels": true})] { for on_group in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "mode": "cmyk"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); paint_halves(&mut s); @@ -145,7 +145,7 @@ mod tests { #[test] fn rejects_non_cmyk() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 4, "mode": "rgb"})).unwrap(); assert!(s.execute("image.trap", json!({"width": 1})).is_err()); } diff --git a/crates/engine/src/cmd/type_area_cmds.rs b/crates/engine-core/src/cmd/type_area_cmds.rs similarity index 100% rename from crates/engine/src/cmd/type_area_cmds.rs rename to crates/engine-core/src/cmd/type_area_cmds.rs diff --git a/crates/engine/src/cmd/type_area_cmds/tests.rs b/crates/engine-core/src/cmd/type_area_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/type_area_cmds/tests.rs rename to crates/engine-core/src/cmd/type_area_cmds/tests.rs index ea296015e8..bbef8c95d0 100644 --- a/crates/engine/src/cmd/type_area_cmds/tests.rs +++ b/crates/engine-core/src/cmd/type_area_cmds/tests.rs @@ -5,7 +5,7 @@ use photocraft_doc::{LayerContent, LayerId, TextLayer}; use serde_json::json; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/type_caret_cmds.rs b/crates/engine-core/src/cmd/type_caret_cmds.rs similarity index 99% rename from crates/engine/src/cmd/type_caret_cmds.rs rename to crates/engine-core/src/cmd/type_caret_cmds.rs index 75ca3e0730..bb381038b1 100644 --- a/crates/engine/src/cmd/type_caret_cmds.rs +++ b/crates/engine-core/src/cmd/type_caret_cmds.rs @@ -233,7 +233,7 @@ mod tests { use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "background": "white"})).unwrap(); s } @@ -280,6 +280,7 @@ mod tests { #[test] fn commands_are_registered_queries() { + crate::install().unwrap(); for id in ["type.hitTest", "type.caret", "type.navigate"] { let spec = crate::command_specs().iter().find(|c| c.id == id).unwrap_or_else(|| panic!("missing {id}")); assert!(!spec.journal, "{id}"); @@ -474,7 +475,7 @@ mod tests { #[test] fn bad_params_are_errors() { - let mut bare = Session::new(); + let mut bare = crate::session(); assert!(matches!(bare.execute("type.hitTest", json!({"x": 0, "y": 0})), Err(EngineError::Disabled(..)))); assert!(matches!(bare.execute("type.caret", json!({"index": 0})), Err(EngineError::Disabled(..)))); assert!(matches!(bare.execute("type.navigate", json!({"index": 0, "move": "end"})), Err(EngineError::Disabled(..)))); diff --git a/crates/engine/src/cmd/type_cmds.rs b/crates/engine-core/src/cmd/type_cmds.rs similarity index 100% rename from crates/engine/src/cmd/type_cmds.rs rename to crates/engine-core/src/cmd/type_cmds.rs diff --git a/crates/engine/src/cmd/type_cmds/tests.rs b/crates/engine-core/src/cmd/type_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/type_cmds/tests.rs rename to crates/engine-core/src/cmd/type_cmds/tests.rs index 4cd7705fd3..583c38b502 100644 --- a/crates/engine/src/cmd/type_cmds/tests.rs +++ b/crates/engine-core/src/cmd/type_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100, "background": "transparent"})).unwrap(); s } @@ -643,7 +643,7 @@ fn rasterize_and_fonts() { /// that, not the document), and a drag's coalesced steps are one history step. #[test] fn type_edits_damage_only_the_layer_and_coalesce() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 3000, "height": 2000})).unwrap(); let id = s.execute("type.create", json!({"x": 100, "y": 100, "text": "Hi", "size": 20})).unwrap()["layer"].as_u64().unwrap(); let steps = s.active().unwrap().history.entries().len(); @@ -883,7 +883,7 @@ fn kern_pair_cost() { ("paragraph", para.as_str(), 12, true, "metrics"), ("optical paragraph", para.as_str(), 12, true, "optical"), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2000, "height": 1500})).unwrap(); let mut p = json!({"x": 20, "y": 100, "text": text, "size": size, "font": "Inter", "kerning": kerning}); if bx { diff --git a/crates/engine/src/cmd/type_extra_cmds.rs b/crates/engine-core/src/cmd/type_extra_cmds.rs similarity index 100% rename from crates/engine/src/cmd/type_extra_cmds.rs rename to crates/engine-core/src/cmd/type_extra_cmds.rs diff --git a/crates/engine/src/cmd/type_extra_cmds/tests.rs b/crates/engine-core/src/cmd/type_extra_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/type_extra_cmds/tests.rs rename to crates/engine-core/src/cmd/type_extra_cmds/tests.rs index 748134c455..1bea6cbee5 100644 --- a/crates/engine/src/cmd/type_extra_cmds/tests.rs +++ b/crates/engine-core/src/cmd/type_extra_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 120, "depth": depth, "background": "white"})).unwrap(); s } @@ -85,7 +85,7 @@ fn vertical_orientation_params_match_horizontal() { /// Issue #199: vertical type is laid out top to bottom, columns right to left, on the canvas. #[test] fn vertical_orientation_renders_columns_inside_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 1000, "height": 600, "background": "#fff8e7", "name": "flyer"})).unwrap(); // The issue's repro (its font may be missing here: fallback fonts then cover the text). let r = s.execute("type.create", json!({"x": 900, "y": 30, "text": "縦書きテスト", "size": 40, "font": "Noto Sans CJK JP", "name": "vertical"})).unwrap(); @@ -258,6 +258,7 @@ fn on_at(s: &Session, id: LayerId, ci: usize, tag: &str) -> bool { #[test] fn numerals_are_registered_with_their_menu_path() { + crate::install().unwrap(); for style in NumeralsStyle::ALL { let spec = crate::commands::find(&format!("type.openType.numerals.{}", style.id())).unwrap(); assert_eq!(spec.label, style.label()); @@ -379,6 +380,7 @@ const SET_IDS: [&str; 3] = ["type.openType.stylisticSets.set1", "type.openType.s #[test] fn stylistic_sets_are_registered_with_their_menu_path() { + crate::install().unwrap(); for n in 1..=20 { let spec = crate::commands::find(&format!("type.openType.stylisticSets.set{n}")).unwrap(); assert_eq!(spec.label, format!("Set {n}")); @@ -843,7 +845,7 @@ fn a_document_without_type_never_waits_for_the_text_engine() { /// Verifies `type.setPathPlacement` commits valid range updates with undo/redo and rejects inverted, infinite, or out-of-bounds inputs. #[test] fn path_placement_updates_and_rejects_invalid_inputs() { - let mut empty = Session::new(); + let mut empty = crate::session(); assert!(empty.execute("type.setPathPlacement", json!({})).is_err()); let mut s = session(8); let id = text_layer(&mut s, "Path"); diff --git a/crates/engine/src/cmd/type_indexed_mode_tests.rs b/crates/engine-core/src/cmd/type_indexed_mode_tests.rs similarity index 99% rename from crates/engine/src/cmd/type_indexed_mode_tests.rs rename to crates/engine-core/src/cmd/type_indexed_mode_tests.rs index 8f6a8058fb..a7d2d515d5 100644 --- a/crates/engine/src/cmd/type_indexed_mode_tests.rs +++ b/crates/engine-core/src/cmd/type_indexed_mode_tests.rs @@ -39,7 +39,7 @@ fn typed(coalesce: bool) -> Value { /// A blank RGB document, to be converted to the mode under test. fn blank() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 240, "height": 120, "background": "transparent"})).unwrap(); s } @@ -170,7 +170,7 @@ fn the_selection_is_the_glyph_shape_the_type_mask_of_the_same_text_makes() { fn rgb_grayscale_cmyk_and_lab_keep_making_type_layers_at_every_depth() { for (id, want) in [("rgb", ColorMode::Rgb), ("gray", ColorMode::Grayscale), ("cmyk", ColorMode::Cmyk), ("lab", ColorMode::Lab)] { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 240, "height": 120, "mode": id, "depth": depth, "background": "transparent"})).unwrap(); assert_eq!(mode(&s), want, "{id} at {depth} bit: the document really is that mode"); let point = new_text_layer(&s, &typed(false), "type.create").unwrap(); diff --git a/crates/engine/src/cmd/type_mask_cmds.rs b/crates/engine-core/src/cmd/type_mask_cmds.rs similarity index 98% rename from crates/engine/src/cmd/type_mask_cmds.rs rename to crates/engine-core/src/cmd/type_mask_cmds.rs index 2aa4739e87..54b1508bf6 100644 --- a/crates/engine/src/cmd/type_mask_cmds.rs +++ b/crates/engine-core/src/cmd/type_mask_cmds.rs @@ -150,7 +150,7 @@ mod tests { use photocraft_doc::LayerId; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 300})).unwrap(); s } @@ -197,6 +197,6 @@ mod tests { for p in [json!({"layer": "x"}), json!({"removeLayer": true}), json!({"operation": 3}), json!({"antialias": "blurry"}), json!({"layer": 999})] { assert!(s.execute(CMD, p.clone()).is_err(), "{p}"); } - assert!(Session::new().execute(CMD, json!({"text": "I"})).is_err()); + assert!(crate::session().execute(CMD, json!({"text": "I"})).is_err()); } } diff --git a/crates/engine/src/cmd/type_mask_off_canvas_tests.rs b/crates/engine-core/src/cmd/type_mask_off_canvas_tests.rs similarity index 99% rename from crates/engine/src/cmd/type_mask_off_canvas_tests.rs rename to crates/engine-core/src/cmd/type_mask_off_canvas_tests.rs index c3db4dcf5c..0c4efd49c9 100644 --- a/crates/engine/src/cmd/type_mask_off_canvas_tests.rs +++ b/crates/engine-core/src/cmd/type_mask_off_canvas_tests.rs @@ -9,7 +9,7 @@ use serde_json::{Value, json}; use crate::Session; fn session(width: u32, height: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": width, "height": height})).unwrap(); s } diff --git a/crates/engine/src/cmd/type_spell_cmds.rs b/crates/engine-core/src/cmd/type_spell_cmds.rs similarity index 99% rename from crates/engine/src/cmd/type_spell_cmds.rs rename to crates/engine-core/src/cmd/type_spell_cmds.rs index a4db50c50e..6e8dfd5e74 100644 --- a/crates/engine/src/cmd/type_spell_cmds.rs +++ b/crates/engine-core/src/cmd/type_spell_cmds.rs @@ -327,7 +327,7 @@ mod tests { } fn session(text: &str) -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 100, "background": "white"})).unwrap(); let r = s.execute("type.create", json!({"x": 10, "y": 50, "text": text, "size": 12})).unwrap(); (s, r["layer"].as_u64().unwrap()) @@ -478,7 +478,7 @@ mod tests { #[test] fn enabled_only_with_a_document() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("edit.checkSpelling")); s.execute("file.new", json!({"width": 10, "height": 10})).unwrap(); assert!(s.is_enabled("edit.checkSpelling")); diff --git a/crates/engine/src/cmd/type_spell_enabled_tests.rs b/crates/engine-core/src/cmd/type_spell_enabled_tests.rs similarity index 97% rename from crates/engine/src/cmd/type_spell_enabled_tests.rs rename to crates/engine-core/src/cmd/type_spell_enabled_tests.rs index d1b5c15138..96292ad89f 100644 --- a/crates/engine/src/cmd/type_spell_enabled_tests.rs +++ b/crates/engine-core/src/cmd/type_spell_enabled_tests.rs @@ -10,7 +10,7 @@ pub(super) const CMD: &str = "edit.checkSpelling"; /// A white document with only its Background, as File > New makes one. pub(super) fn blank() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 500, "background": "white"})).unwrap(); s } @@ -21,7 +21,7 @@ pub(super) fn history(s: &Session) -> Vec { #[test] fn greyed_without_a_document() { - let s = Session::new(); + let s = crate::session(); assert!(!s.is_enabled(CMD)); assert_eq!(s.disabled_reason(CMD).as_deref(), Some("no document open")); } diff --git a/crates/engine/src/cmd/type_spell_order_tests.rs b/crates/engine-core/src/cmd/type_spell_order_tests.rs similarity index 100% rename from crates/engine/src/cmd/type_spell_order_tests.rs rename to crates/engine-core/src/cmd/type_spell_order_tests.rs diff --git a/crates/engine/src/cmd/type_styles_cmds.rs b/crates/engine-core/src/cmd/type_styles_cmds.rs similarity index 100% rename from crates/engine/src/cmd/type_styles_cmds.rs rename to crates/engine-core/src/cmd/type_styles_cmds.rs diff --git a/crates/engine/src/cmd/type_styles_cmds/tests.rs b/crates/engine-core/src/cmd/type_styles_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/type_styles_cmds/tests.rs rename to crates/engine-core/src/cmd/type_styles_cmds/tests.rs index 023af4302a..e9c2bcc88d 100644 --- a/crates/engine/src/cmd/type_styles_cmds/tests.rs +++ b/crates/engine-core/src/cmd/type_styles_cmds/tests.rs @@ -1,7 +1,7 @@ use super::*; fn session(text: &str) -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 200, "background": "transparent"})).unwrap(); let r = s.execute("type.create", json!({"x": 10, "y": 50, "text": text, "size": 12})).unwrap(); (s, r["layer"].as_u64().unwrap()) @@ -157,7 +157,7 @@ fn styles_survive_typing_and_save() { #[test] fn disabled_states() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("type.characterStyle.new")); s.execute("file.new", json!({"width": 10, "height": 10})).unwrap(); assert!(s.is_enabled("type.characterStyle.new")); @@ -203,7 +203,7 @@ fn exhausted_style_ids_return_errors_without_history_changes() { fn isolated_options_preview_matches_commit_with_multiple_layers_and_local_overrides() { for paragraph in [false, true] { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":400,"height":200,"depth":depth,"background":"transparent"})).unwrap(); let a = s.execute("type.create", json!({"x":10,"y":50,"text":"Hello world","size":24})).unwrap()["layer"].as_u64().unwrap(); let b = s.execute("type.create", json!({"x":10,"y":100,"text":"Second layer","size":24})).unwrap()["layer"].as_u64().unwrap(); diff --git a/crates/engine/src/cmd/type_vertical_history_name_tests.rs b/crates/engine-core/src/cmd/type_vertical_history_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/type_vertical_history_name_tests.rs rename to crates/engine-core/src/cmd/type_vertical_history_name_tests.rs index 7d50656ad8..8bec61111a 100644 --- a/crates/engine/src/cmd/type_vertical_history_name_tests.rs +++ b/crates/engine-core/src/cmd/type_vertical_history_name_tests.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; use crate::Session; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300, "height": 300})).unwrap(); s } diff --git a/crates/engine/src/cmd/variables_cmds.rs b/crates/engine-core/src/cmd/variables_cmds.rs similarity index 100% rename from crates/engine/src/cmd/variables_cmds.rs rename to crates/engine-core/src/cmd/variables_cmds.rs diff --git a/crates/engine/src/cmd/variables_cmds/apply_history_name_tests.rs b/crates/engine-core/src/cmd/variables_cmds/apply_history_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/variables_cmds/apply_history_name_tests.rs rename to crates/engine-core/src/cmd/variables_cmds/apply_history_name_tests.rs index 5830d6f8ca..a652dc6d61 100644 --- a/crates/engine/src/cmd/variables_cmds/apply_history_name_tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/apply_history_name_tests.rs @@ -8,7 +8,7 @@ const NAME: &str = "Apply Data Set"; /// A document with a raster "photo", a togglable raster "badge" and a text layer "title". fn session() -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); let ids = s .edit("setup", |doc, _| { @@ -74,7 +74,7 @@ fn one_undo_reverts_visibility_text_and_pixels_together() { std::fs::create_dir_all(&dir).unwrap(); let png = dir.join("blue.png").to_string_lossy().into_owned(); { - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap(); let bytes = photocraft_io::export(&src.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes; std::fs::write(&png, bytes).unwrap(); diff --git a/crates/engine/src/cmd/variables_cmds/import_enabled_tests.rs b/crates/engine-core/src/cmd/variables_cmds/import_enabled_tests.rs similarity index 94% rename from crates/engine/src/cmd/variables_cmds/import_enabled_tests.rs rename to crates/engine-core/src/cmd/variables_cmds/import_enabled_tests.rs index 823a226a72..1989cfec50 100644 --- a/crates/engine/src/cmd/variables_cmds/import_enabled_tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/import_enabled_tests.rs @@ -31,14 +31,14 @@ fn other_imports(s: &Session) -> Vec<(&'static str, bool)> { #[test] fn import_is_disabled_without_a_document() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled(IMPORT)); assert_eq!(refusal(&mut s), "no document"); } #[test] fn import_is_disabled_without_variables_and_leaves_the_document_alone() { - let mut s = Session::new(); + let mut s = crate::session(); new_doc(&mut s); assert!(!s.is_enabled(IMPORT)); assert_eq!(refusal(&mut s), "no variables in document"); @@ -47,7 +47,7 @@ fn import_is_disabled_without_variables_and_leaves_the_document_alone() { #[test] fn import_is_enabled_with_a_variable_and_no_data_sets() { - let mut s = Session::new(); + let mut s = crate::session(); new_doc(&mut s); define_variable(&mut s); assert!(s.active().unwrap().doc.variables.data_sets.is_empty()); @@ -62,7 +62,7 @@ fn import_is_enabled_with_a_variable_and_no_data_sets() { #[test] fn import_follows_the_active_document() { - let mut s = Session::new(); + let mut s = crate::session(); new_doc(&mut s); define_variable(&mut s); new_doc(&mut s); @@ -78,7 +78,7 @@ fn import_follows_the_active_document() { #[test] fn other_import_entries_do_not_depend_on_variables() { - let mut s = Session::new(); + let mut s = crate::session(); new_doc(&mut s); let without = other_imports(&s); assert!(!without.is_empty(), "File > Import has other entries"); diff --git a/crates/engine/src/cmd/variables_cmds/import_history_tests.rs b/crates/engine-core/src/cmd/variables_cmds/import_history_tests.rs similarity index 99% rename from crates/engine/src/cmd/variables_cmds/import_history_tests.rs rename to crates/engine-core/src/cmd/variables_cmds/import_history_tests.rs index d7306fae9c..a0442ce860 100644 --- a/crates/engine/src/cmd/variables_cmds/import_history_tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/import_history_tests.rs @@ -9,7 +9,7 @@ use crate::Session; const IMPORT: &str = "file.import.variableDataSets"; fn template() -> Session { - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"width": 32, "height": 24})).unwrap(); let (title, badge) = session .edit("Create template layers", |doc, active| { diff --git a/crates/engine/src/cmd/variables_cmds/import_visibility_tests.rs b/crates/engine-core/src/cmd/variables_cmds/import_visibility_tests.rs similarity index 97% rename from crates/engine/src/cmd/variables_cmds/import_visibility_tests.rs rename to crates/engine-core/src/cmd/variables_cmds/import_visibility_tests.rs index 403af150d2..cf7a01bdfe 100644 --- a/crates/engine/src/cmd/variables_cmds/import_visibility_tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/import_visibility_tests.rs @@ -6,7 +6,7 @@ use photocraft_doc::Layer; /// Import one data set per `cells` entry into a document with a Visibility variable `show`, and /// return each set's stored visibility. fn imported_visibility(cells: &[&str]) -> Vec { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let badge = s .edit("setup", |doc, _| { diff --git a/crates/engine/src/cmd/variables_cmds/locked_text_layer_tests.rs b/crates/engine-core/src/cmd/variables_cmds/locked_text_layer_tests.rs similarity index 99% rename from crates/engine/src/cmd/variables_cmds/locked_text_layer_tests.rs rename to crates/engine-core/src/cmd/variables_cmds/locked_text_layer_tests.rs index c5e2151a5c..ed128db375 100644 --- a/crates/engine/src/cmd/variables_cmds/locked_text_layer_tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/locked_text_layer_tests.rs @@ -12,7 +12,7 @@ const APPLY: &str = "image.applyDataSet"; /// A document with a raster layer "photo", a red raster "badge" and a text layer "title", bound /// to the variables `photo` (pixels), `showBadge`, `showTitle` (visibility) and `headline` (text). fn session() -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); let (photo, badge, title) = s .edit("setup", |doc, _| { @@ -45,7 +45,7 @@ fn blue_png(name: &str) -> (String, String) { let dir = std::env::temp_dir().join(format!("pc-vars-{}-locked-{name}", std::process::id())); let _ = std::fs::create_dir_all(&dir); let png = dir.join("blue.png"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap(); let bytes = photocraft_io::export(&src.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes; std::fs::write(&png, bytes).unwrap(); diff --git a/crates/engine/src/cmd/variables_cmds/missing_file_tests.rs b/crates/engine-core/src/cmd/variables_cmds/missing_file_tests.rs similarity index 98% rename from crates/engine/src/cmd/variables_cmds/missing_file_tests.rs rename to crates/engine-core/src/cmd/variables_cmds/missing_file_tests.rs index 87d78575ce..7034d5e92c 100644 --- a/crates/engine/src/cmd/variables_cmds/missing_file_tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/missing_file_tests.rs @@ -12,7 +12,7 @@ const APPLY: &str = "image.applyDataSet"; /// A document with a grey raster "photo", a red raster "badge" and a text layer "title", bound to /// the variables `photo` (pixels), `showBadge` (visibility) and `headline` (text). fn session() -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); let (photo, badge, title) = s .edit("setup", |doc, _| { @@ -148,7 +148,7 @@ fn the_same_set_applies_once_the_file_is_back() { set_two(&mut s, &png.to_string_lossy()); assert!(s.execute(APPLY, json!({"name": "Two"})).is_err()); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap(); let bytes = photocraft_io::export(&src.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes; std::fs::write(&png, bytes).unwrap(); diff --git a/crates/engine/src/cmd/variables_cmds/tests.rs b/crates/engine-core/src/cmd/variables_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/variables_cmds/tests.rs rename to crates/engine-core/src/cmd/variables_cmds/tests.rs index fa10b051cc..177ee9481b 100644 --- a/crates/engine/src/cmd/variables_cmds/tests.rs +++ b/crates/engine-core/src/cmd/variables_cmds/tests.rs @@ -4,7 +4,7 @@ use photocraft_geom::Rect; /// A document with a raster layer "photo", a togglable raster "badge" and a text layer "title". fn session() -> (Session, LayerId, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); let ids = s .edit("setup", |doc, _| { @@ -258,7 +258,7 @@ fn csv_multiline_values_apply_persist_and_export_as_two_data_sets() { let native = format!("{dir}/multiline.pcraft"); crate::file_cmds::save_doc(doc(&s), &native, None).unwrap(); - let mut reopened = Session::new(); + let mut reopened = crate::session(); crate::file_cmds::open_bytes_as(&mut reopened, "multiline.pcraft", &std::fs::read(&native).unwrap(), None, Some(native)).unwrap(); assert_eq!(doc(&reopened).variables, doc(&s).variables); assert_eq!(text_of(&reopened, title), second); @@ -307,7 +307,7 @@ fn csv_import_preserves_unicode_pixel_paths() { let dir = tmp("unicode-pixels"); let png = format!("{dir}/изображение,日本語.png"); let csv = format!("{dir}/sets.csv"); - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap(); let bytes = photocraft_io::export(&src.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes; std::fs::write(&png, bytes).unwrap(); @@ -373,7 +373,7 @@ fn export_data_sets_as_files() { } fn visibility_export_session(names: &[&str]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "white", "name": "card"})).unwrap(); let layer = doc(&s).layers[0].id; s.execute("image.variables.define", json!({"defs": [{"name": "show", "layer": layer.0, "type": "visibility"}]})).unwrap(); @@ -494,7 +494,7 @@ fn pixel_replacement_changes_the_layer() { let dir = tmp("px"); let png = format!("{dir}/blue.png"); { - let mut src = Session::new(); + let mut src = crate::session(); src.execute("file.new", json!({"width": 8, "height": 8, "background": "#0000ff"})).unwrap(); let bytes = photocraft_io::export(&src.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes; std::fs::write(&png, bytes).unwrap(); @@ -531,7 +531,7 @@ fn pixel_replacement_changes_the_layer() { fn applied_text_is_rendered_in_the_document_and_in_exports() { // Applying a text value cleared the type layer's render cache and nothing rebuilt it, so the // text vanished from the canvas and from every exported file (#990). - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 60, "background": "white"})).unwrap(); let id = s.execute("type.create", json!({"x": 4, "y": 40, "text": "HELLO", "size": 32, "color": "#000000"})).unwrap()["layer"].clone(); let dark = |d: &Document| photocraft_compose::render(d, d.bounds()).px.iter().filter(|p| p[0] < 0.5).count(); @@ -552,7 +552,7 @@ fn applied_text_is_rendered_in_the_document_and_in_exports() { /// A text layer created bold-italic with tracking, underline, all caps and colour, bound to a /// `headline` text variable with one data set per value. fn styled_text_session(values: &[&str]) -> (Session, Value) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 120, "background": "white"})).unwrap(); let id = s .execute( @@ -655,7 +655,7 @@ fn exported_data_sets_keep_the_character_style() { #[test] fn data_set_commands_require_data_sets_to_be_enabled() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("file.export.dataSetsAsFiles")); assert!(!s.is_enabled("image.applyDataSet")); diff --git a/crates/engine/src/cmd/vector_clipboard.rs b/crates/engine-core/src/cmd/vector_clipboard.rs similarity index 100% rename from crates/engine/src/cmd/vector_clipboard.rs rename to crates/engine-core/src/cmd/vector_clipboard.rs diff --git a/crates/engine/src/cmd/vector_cmds.rs b/crates/engine-core/src/cmd/vector_cmds.rs similarity index 100% rename from crates/engine/src/cmd/vector_cmds.rs rename to crates/engine-core/src/cmd/vector_cmds.rs diff --git a/crates/engine/src/cmd/vector_cmds/ellipse_tool_history_name_tests.rs b/crates/engine-core/src/cmd/vector_cmds/ellipse_tool_history_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/vector_cmds/ellipse_tool_history_name_tests.rs rename to crates/engine-core/src/cmd/vector_cmds/ellipse_tool_history_name_tests.rs index 10c5af2a8d..d13cb1ddad 100644 --- a/crates/engine/src/cmd/vector_cmds/ellipse_tool_history_name_tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/ellipse_tool_history_name_tests.rs @@ -6,7 +6,7 @@ use crate::Session; const LABEL: &str = "Ellipse Tool"; fn document() -> Session { - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"width": 160, "height": 120})).unwrap(); session } diff --git a/crates/engine/src/cmd/vector_cmds/line_arrowhead_history_names_tests.rs b/crates/engine-core/src/cmd/vector_cmds/line_arrowhead_history_names_tests.rs similarity index 97% rename from crates/engine/src/cmd/vector_cmds/line_arrowhead_history_names_tests.rs rename to crates/engine-core/src/cmd/vector_cmds/line_arrowhead_history_names_tests.rs index a88d6c04d5..667ef37d24 100644 --- a/crates/engine/src/cmd/vector_cmds/line_arrowhead_history_names_tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/line_arrowhead_history_names_tests.rs @@ -7,7 +7,7 @@ use super::*; /// A document whose active layer is a line with arrowhead settings (a live `ArrowLine`). fn arrow_line() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s.execute( "shape.create", @@ -101,7 +101,7 @@ fn a_refused_arrowhead_edit_adds_no_step() { #[test] fn a_plain_line_turning_an_arrowhead_on_is_change_arrowhead_end() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s.execute("shape.create", json!({"kind": "line", "from": [100, 300], "to": [600, 300], "weight": 4})).unwrap(); edit(&mut s, json!({"arrowEnd": true})); @@ -110,7 +110,7 @@ fn a_plain_line_turning_an_arrowhead_on_is_change_arrowhead_end() { #[test] fn arrowhead_keys_on_a_shape_that_is_not_a_line_stay_edit_shape() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s.execute("shape.create", json!({"kind": "rect", "rect": [10, 10, 100, 80]})).unwrap(); edit(&mut s, json!({"arrowWidth": 15})); diff --git a/crates/engine/src/cmd/vector_cmds/line_tool_history_name_tests.rs b/crates/engine-core/src/cmd/vector_cmds/line_tool_history_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/vector_cmds/line_tool_history_name_tests.rs rename to crates/engine-core/src/cmd/vector_cmds/line_tool_history_name_tests.rs index 7bb8af9d2a..fc299c2959 100644 --- a/crates/engine/src/cmd/vector_cmds/line_tool_history_name_tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/line_tool_history_name_tests.rs @@ -6,7 +6,7 @@ use serde_json::{Value, json}; use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s } diff --git a/crates/engine/src/cmd/vector_cmds/params.rs b/crates/engine-core/src/cmd/vector_cmds/params.rs similarity index 100% rename from crates/engine/src/cmd/vector_cmds/params.rs rename to crates/engine-core/src/cmd/vector_cmds/params.rs diff --git a/crates/engine/src/cmd/vector_cmds/paths.rs b/crates/engine-core/src/cmd/vector_cmds/paths.rs similarity index 100% rename from crates/engine/src/cmd/vector_cmds/paths.rs rename to crates/engine-core/src/cmd/vector_cmds/paths.rs diff --git a/crates/engine/src/cmd/vector_cmds/shape.rs b/crates/engine-core/src/cmd/vector_cmds/shape.rs similarity index 100% rename from crates/engine/src/cmd/vector_cmds/shape.rs rename to crates/engine-core/src/cmd/vector_cmds/shape.rs diff --git a/crates/engine/src/cmd/vector_cmds/tests.rs b/crates/engine-core/src/cmd/vector_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/vector_cmds/tests.rs rename to crates/engine-core/src/cmd/vector_cmds/tests.rs index aabd0364e9..c22de4bb39 100644 --- a/crates/engine/src/cmd/vector_cmds/tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/tests.rs @@ -154,7 +154,7 @@ fn adding_components_validates_the_existing_strokes_combined_workload() { } fn session(w: u32, h: u32, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": "white", "depth": depth})).unwrap(); s } @@ -1102,6 +1102,7 @@ fn translate_vectors_moves_shapes_and_masks() { #[test] fn all_vector_commands_are_registered() { + crate::install().unwrap(); for id in [ "shape.create", "shape.edit", diff --git a/crates/engine/src/cmd/vector_cmds/triangle_box_geometry_tests.rs b/crates/engine-core/src/cmd/vector_cmds/triangle_box_geometry_tests.rs similarity index 99% rename from crates/engine/src/cmd/vector_cmds/triangle_box_geometry_tests.rs rename to crates/engine-core/src/cmd/vector_cmds/triangle_box_geometry_tests.rs index 7dcc5de64f..948c3f297f 100644 --- a/crates/engine/src/cmd/vector_cmds/triangle_box_geometry_tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/triangle_box_geometry_tests.rs @@ -8,7 +8,7 @@ use super::shape_path; use crate::Session; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/vector_cmds/triangle_history_names_tests.rs b/crates/engine-core/src/cmd/vector_cmds/triangle_history_names_tests.rs similarity index 99% rename from crates/engine/src/cmd/vector_cmds/triangle_history_names_tests.rs rename to crates/engine-core/src/cmd/vector_cmds/triangle_history_names_tests.rs index a2159545d4..d1cf5d035c 100644 --- a/crates/engine/src/cmd/vector_cmds/triangle_history_names_tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/triangle_history_names_tests.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; use super::*; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s } diff --git a/crates/engine/src/cmd/vector_cmds/triangle_layer_name_tests.rs b/crates/engine-core/src/cmd/vector_cmds/triangle_layer_name_tests.rs similarity index 98% rename from crates/engine/src/cmd/vector_cmds/triangle_layer_name_tests.rs rename to crates/engine-core/src/cmd/vector_cmds/triangle_layer_name_tests.rs index 7c4376e64c..a03bf601b1 100644 --- a/crates/engine/src/cmd/vector_cmds/triangle_layer_name_tests.rs +++ b/crates/engine-core/src/cmd/vector_cmds/triangle_layer_name_tests.rs @@ -6,7 +6,7 @@ use super::super::{LayerContent, LayerId, LiveShape, shape_path}; use crate::Session; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 160, "background": "white"})).unwrap(); s } diff --git a/crates/engine/src/cmd/vector_cmds/vector_mask.rs b/crates/engine-core/src/cmd/vector_cmds/vector_mask.rs similarity index 100% rename from crates/engine/src/cmd/vector_cmds/vector_mask.rs rename to crates/engine-core/src/cmd/vector_cmds/vector_mask.rs diff --git a/crates/engine/src/cmd/video_cmds.rs b/crates/engine-core/src/cmd/video_cmds.rs similarity index 100% rename from crates/engine/src/cmd/video_cmds.rs rename to crates/engine-core/src/cmd/video_cmds.rs diff --git a/crates/engine/src/cmd/video_cmds/tests.rs b/crates/engine-core/src/cmd/video_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/video_cmds/tests.rs rename to crates/engine-core/src/cmd/video_cmds/tests.rs index 44d45f41e7..5e2b74b00d 100644 --- a/crates/engine/src/cmd/video_cmds/tests.rs +++ b/crates/engine-core/src/cmd/video_cmds/tests.rs @@ -3,7 +3,7 @@ use photocraft_doc::LayerId; use serde_json::json; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 12})).unwrap(); s } @@ -68,7 +68,7 @@ fn scrub_keeps_content_a_raster() { } fn write_png(path: &str, w: u32, h: u32, color: &str) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": color})).unwrap(); let bytes = photocraft_io::export(&s.active().unwrap().doc, "png", &photocraft_io::ExportOptions::default()).unwrap().bytes; std::fs::write(path, bytes).unwrap(); @@ -376,7 +376,7 @@ fn render_video_to_animated_gif() { #[test] fn animated_gif_keeps_transparency() { // #3061: a transparent document rendered as an animated GIF came out opaque black. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "transparent"})).unwrap(); s.execute("timeline.create", json!({"duration": 2, "fps": 10})).unwrap(); s.execute("select.rect", json!({"x": 2, "y": 2, "width": 4, "height": 4})).unwrap(); @@ -957,7 +957,7 @@ fn render_video_rejects_a_loaded_timeline_past_the_frame_cap() { #[test] fn render_video_rejects_gif_frames_too_large_to_stage() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 9000, "height": 8000})).unwrap(); let err = s.execute("file.export.renderVideo", json!({"dir": tmpdir("large-gif"), "format": "gif"})).unwrap_err(); assert!(err.to_string().contains("too large"), "{err}"); @@ -966,7 +966,7 @@ fn render_video_rejects_gif_frames_too_large_to_stage() { #[test] fn render_video_rejects_a_gif_whose_frames_together_are_too_large() { // Each 4000 x 4000 frame is under the per-frame cap, but 100,000 of them keep ~1.6 TB staged. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4000, "height": 4000})).unwrap(); s.execute("timeline.create", json!({"duration": 100_000, "fps": 30})).unwrap(); let err = s.execute("file.export.renderVideo", json!({"dir": tmpdir("many-gif"), "format": "gif"})).unwrap_err(); diff --git a/crates/engine/src/cmd/vp_cmds.rs b/crates/engine-core/src/cmd/vp_cmds.rs similarity index 99% rename from crates/engine/src/cmd/vp_cmds.rs rename to crates/engine-core/src/cmd/vp_cmds.rs index 1a3ac8e0ca..d44bc3a174 100644 --- a/crates/engine/src/cmd/vp_cmds.rs +++ b/crates/engine-core/src/cmd/vp_cmds.rs @@ -315,7 +315,7 @@ mod tests { #[test] fn planes_paste_and_clone() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); s.execute("layer.new.layer", json!({"name": "floor"})).unwrap(); s.execute("edit.fill", json!({"color": "#404040"})).unwrap(); @@ -361,7 +361,7 @@ mod tests { #[test] fn rejects_planes_that_are_not_convex() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "depth": 16})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let bowtie = json!([[20, 20], [180, 180], [180, 20], [20, 180]]); @@ -376,7 +376,7 @@ mod tests { #[test] fn rejects_hostile_clone_and_tear_off_params() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200, "depth": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let floor = json!({"corners": [[60, 60], [140, 60], [190, 190], [10, 190]]}); @@ -415,7 +415,7 @@ mod tests { #[test] fn new_layer_clone_stays_on_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#40c040"})).unwrap(); @@ -443,7 +443,7 @@ mod tests { /// 1e7 px away). #[test] fn layer_clone_stays_on_the_canvas() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#40c040"})).unwrap(); @@ -460,7 +460,7 @@ mod tests { #[test] fn layer_param_paints_that_layer_not_the_active_one() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 200})).unwrap(); s.execute("layer.new.layer", json!({"name": "floor"})).unwrap(); s.execute("edit.fill", json!({"color": "#40c040"})).unwrap(); diff --git a/crates/engine/src/cmd/warp_cmds.rs b/crates/engine-core/src/cmd/warp_cmds.rs similarity index 100% rename from crates/engine/src/cmd/warp_cmds.rs rename to crates/engine-core/src/cmd/warp_cmds.rs diff --git a/crates/engine/src/cmd/warp_cmds/tests.rs b/crates/engine-core/src/cmd/warp_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/warp_cmds/tests.rs rename to crates/engine-core/src/cmd/warp_cmds/tests.rs index cbbbc942ec..089b515a81 100644 --- a/crates/engine/src/cmd/warp_cmds/tests.rs +++ b/crates/engine-core/src/cmd/warp_cmds/tests.rs @@ -31,7 +31,7 @@ fn a_warp_box_holding_the_whole_layer_gives_what_compositing_over_the_cleared_la } fn session(depth: u64) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 80, "height": 60, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("paint", |doc, active| { @@ -58,7 +58,7 @@ fn active_surface(s: &Session) -> Surface { /// refused rather than rasterizing. #[test] fn warp_style_on_type_is_warp_text() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); s.execute("type.create", json!({"x": 10, "y": 60, "text": "Hi"})).unwrap(); let n = s.active().unwrap().history.past_len(); @@ -433,7 +433,7 @@ fn warp_grid_fits_the_surface_and_rejects_bad_sizes() { /// up with the moved pixels and the unselected part stays put. #[test] fn linked_mask_with_a_selection_warps_only_the_selected_region() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("layer.layerMask.revealAll", json!({})).unwrap(); @@ -482,7 +482,7 @@ fn linked_mask_with_a_selection_warps_only_the_selected_region() { /// no pixels to warp, so the mask is the only part that can see the cancel. #[test] fn a_cancelled_warp_stops_in_a_selected_linked_mask() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 100, "height": 100})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({})).unwrap(); s.execute("layer.layerMask.revealAll", json!({})).unwrap(); diff --git a/crates/engine/src/cmd/warp_remove_split_default_grid_tests.rs b/crates/engine-core/src/cmd/warp_remove_split_default_grid_tests.rs similarity index 99% rename from crates/engine/src/cmd/warp_remove_split_default_grid_tests.rs rename to crates/engine-core/src/cmd/warp_remove_split_default_grid_tests.rs index c7cdda0bce..d9ae0b3e6a 100644 --- a/crates/engine/src/cmd/warp_remove_split_default_grid_tests.rs +++ b/crates/engine-core/src/cmd/warp_remove_split_default_grid_tests.rs @@ -9,7 +9,7 @@ const BOX: [f64; 4] = [200.0, 150.0, 600.0, 450.0]; const THIRDS: [f64; 4] = [0.0, 1.0 / 3.0, 2.0 / 3.0, 1.0]; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s diff --git a/crates/engine/src/cmd/warp_split_default_grid_tests.rs b/crates/engine-core/src/cmd/warp_split_default_grid_tests.rs similarity index 99% rename from crates/engine/src/cmd/warp_split_default_grid_tests.rs rename to crates/engine-core/src/cmd/warp_split_default_grid_tests.rs index b6cbd78011..d02fe34b2f 100644 --- a/crates/engine/src/cmd/warp_split_default_grid_tests.rs +++ b/crates/engine-core/src/cmd/warp_split_default_grid_tests.rs @@ -6,7 +6,7 @@ use super::*; const BOX: [f64; 4] = [200.0, 150.0, 600.0, 450.0]; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 600})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s diff --git a/crates/engine/src/cmd/web_cmds.rs b/crates/engine-core/src/cmd/web_cmds.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds.rs rename to crates/engine-core/src/cmd/web_cmds.rs diff --git a/crates/engine/src/cmd/web_cmds/assets.rs b/crates/engine-core/src/cmd/web_cmds/assets.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds/assets.rs rename to crates/engine-core/src/cmd/web_cmds/assets.rs diff --git a/crates/engine/src/cmd/web_cmds/color_table_tests.rs b/crates/engine-core/src/cmd/web_cmds/color_table_tests.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds/color_table_tests.rs rename to crates/engine-core/src/cmd/web_cmds/color_table_tests.rs diff --git a/crates/engine/src/cmd/web_cmds/optimizer.rs b/crates/engine-core/src/cmd/web_cmds/optimizer.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds/optimizer.rs rename to crates/engine-core/src/cmd/web_cmds/optimizer.rs diff --git a/crates/engine/src/cmd/web_cmds/png_embed_icc_tests.rs b/crates/engine-core/src/cmd/web_cmds/png_embed_icc_tests.rs similarity index 98% rename from crates/engine/src/cmd/web_cmds/png_embed_icc_tests.rs rename to crates/engine-core/src/cmd/web_cmds/png_embed_icc_tests.rs index f295d8409a..eee6bc3cd1 100644 --- a/crates/engine/src/cmd/web_cmds/png_embed_icc_tests.rs +++ b/crates/engine-core/src/cmd/web_cmds/png_embed_icc_tests.rs @@ -14,7 +14,7 @@ fn tmp(name: &str) -> String { /// A red document with a wide-gamut profile (Adobe RGB) assigned. fn tagged() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "background": "#c81e1e"})).unwrap(); s.execute("edit.assignProfile", json!({"profile": "adobe-rgb-compat"})).unwrap(); assert!(s.active().unwrap().doc.icc_profile.is_some(), "the document has a profile"); diff --git a/crates/engine/src/cmd/web_cmds/quick.rs b/crates/engine-core/src/cmd/web_cmds/quick.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds/quick.rs rename to crates/engine-core/src/cmd/web_cmds/quick.rs diff --git a/crates/engine/src/cmd/web_cmds/quick_jpg_progressive_tests.rs b/crates/engine-core/src/cmd/web_cmds/quick_jpg_progressive_tests.rs similarity index 99% rename from crates/engine/src/cmd/web_cmds/quick_jpg_progressive_tests.rs rename to crates/engine-core/src/cmd/web_cmds/quick_jpg_progressive_tests.rs index e394d3483c..7d8a256e1f 100644 --- a/crates/engine/src/cmd/web_cmds/quick_jpg_progressive_tests.rs +++ b/crates/engine-core/src/cmd/web_cmds/quick_jpg_progressive_tests.rs @@ -12,7 +12,7 @@ fn tmp(name: &str) -> String { /// A 64×48 8-bit document: a white background with a flat blue block over its left half. fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": 8, "name": "quick.psd", "background": "white"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 32, "height": 48})).unwrap(); s.execute("edit.fill", json!({"color": "#3366cc"})).unwrap(); diff --git a/crates/engine/src/cmd/web_cmds/save_web.rs b/crates/engine-core/src/cmd/web_cmds/save_web.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds/save_web.rs rename to crates/engine-core/src/cmd/web_cmds/save_web.rs diff --git a/crates/engine/src/cmd/web_cmds/settings.rs b/crates/engine-core/src/cmd/web_cmds/settings.rs similarity index 100% rename from crates/engine/src/cmd/web_cmds/settings.rs rename to crates/engine-core/src/cmd/web_cmds/settings.rs diff --git a/crates/engine/src/cmd/web_cmds/tests.rs b/crates/engine-core/src/cmd/web_cmds/tests.rs similarity index 99% rename from crates/engine/src/cmd/web_cmds/tests.rs rename to crates/engine-core/src/cmd/web_cmds/tests.rs index ee4abbd846..01b1e9a78d 100644 --- a/crates/engine/src/cmd/web_cmds/tests.rs +++ b/crates/engine-core/src/cmd/web_cmds/tests.rs @@ -11,7 +11,7 @@ fn tmp(name: &str) -> String { /// A 64×48 document: white background, a red square with soft (half-transparent) edges on a /// transparent layer, and a gradient band. fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth, "name": "web.psd", "background": "transparent"})).unwrap(); s.edit("paint", |doc, active| { let fmt = doc.pixel_format(); @@ -263,7 +263,7 @@ fn gif_and_png8_keep_transparency_and_palette() { #[test] fn png8_has_no_matte_by_default() { let dir = tmp("matte"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 256, "height": 8, "background": "transparent"})).unwrap(); s.edit("paint", |doc, active| { let fmt = doc.pixel_format(); @@ -796,7 +796,7 @@ fn image_assets_are_generated_now_and_on_save() { #[test] fn a_save_script_closing_another_tab_still_generates_the_saved_documents_assets() { let dir = tmp("script_close_tab"); - let mut s = Session::new(); + let mut s = crate::session(); // Document B first (tab 0), then document A with an eligible layer (tab 1, active). s.execute("file.new", json!({"width": 8, "height": 8, "name": "b"})).unwrap(); s.execute("file.new", json!({"width": 64, "height": 48, "name": "a"})).unwrap(); @@ -828,7 +828,7 @@ fn a_save_script_closing_another_tab_still_generates_the_saved_documents_assets( #[test] fn a_save_script_closing_the_saved_document_generates_no_replacement_assets() { let dir = tmp("script_close_saved"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "name": "a"})).unwrap(); let a = s.active().unwrap().doc.id; s.edit("logo", |doc, active| { @@ -872,7 +872,7 @@ fn a_save_script_closing_the_saved_document_generates_no_replacement_assets() { #[test] fn image_assets_keep_full_artboards() { let dir = tmp("asset-artboards"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "name": "boards.psd", "background": "transparent"})).unwrap(); s.edit("board", |doc, _| { let fmt = doc.pixel_format(); @@ -907,7 +907,7 @@ fn image_assets_keep_full_artboards() { #[test] fn image_assets_refuse_empty_artboards() { let dir = tmp("asset-empty-artboards"); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "name": "boards.psd", "background": "transparent"})).unwrap(); s.edit("boards", |doc, _| { let fmt = doc.pixel_format(); @@ -1365,7 +1365,7 @@ fn quick_export_exr_preserves_linear_hdr_and_alpha() { let image = Image::from_f32(2, 1, ChannelLayout::Rgba, &samples).unwrap(); let bytes = photocraft_codecs::encode(&image, Format::OpenExr, &Default::default()).unwrap(); let doc = photocraft_io::import("hdr.exr", &bytes).unwrap().document; - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, Some(format!("{dir}/source.psd"))); for convert in [true, false] { s.execute("file.export.exportPreferences", json!({"quickExportFormat": "exr", "quickExportLocation": "sameFolder", "convertToSrgb": convert})).unwrap(); diff --git a/crates/engine/src/cmd/wia_cmds.rs b/crates/engine-core/src/cmd/wia_cmds.rs similarity index 97% rename from crates/engine/src/cmd/wia_cmds.rs rename to crates/engine-core/src/cmd/wia_cmds.rs index 540b59dc2f..022fab03a5 100644 --- a/crates/engine/src/cmd/wia_cmds.rs +++ b/crates/engine-core/src/cmd/wia_cmds.rs @@ -40,7 +40,7 @@ mod tests { #[test] fn reports_availability() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("file.import.wiaSupport", json!({})).unwrap(); assert!(r["devices"].is_array()); assert_eq!(r["available"], cfg!(target_os = "windows")); diff --git a/crates/engine/src/color_channels.rs b/crates/engine-core/src/color_channels.rs similarity index 100% rename from crates/engine/src/color_channels.rs rename to crates/engine-core/src/color_channels.rs diff --git a/crates/engine/src/color_channels/tone.rs b/crates/engine-core/src/color_channels/tone.rs similarity index 100% rename from crates/engine/src/color_channels/tone.rs rename to crates/engine-core/src/color_channels/tone.rs diff --git a/crates/engine/src/color_channels/tone_dialog_tests.rs b/crates/engine-core/src/color_channels/tone_dialog_tests.rs similarity index 100% rename from crates/engine/src/color_channels/tone_dialog_tests.rs rename to crates/engine-core/src/color_channels/tone_dialog_tests.rs diff --git a/crates/engine/src/command_hints.rs b/crates/engine-core/src/command_hints.rs similarity index 97% rename from crates/engine/src/command_hints.rs rename to crates/engine-core/src/command_hints.rs index 2cc210ea25..8dd1fb53a4 100644 --- a/crates/engine/src/command_hints.rs +++ b/crates/engine-core/src/command_hints.rs @@ -91,7 +91,7 @@ mod tests { use serde_json::json; use super::*; - use crate::{EngineError, Session}; + use crate::EngineError; fn unknown(id: &str) -> String { EngineError::UnknownCommand(id.into()).to_string() @@ -99,8 +99,9 @@ mod tests { #[test] fn protocol_listing_method_points_at_command_list() { + crate::install().unwrap(); assert_eq!(unknown("engine.commands"), "unknown command `engine.commands`; did you mean `command.list`?"); - let mut s = Session::new(); + let mut s = crate::session(); let e = s.execute("engine.commands", json!({})).unwrap_err().to_string(); assert!(e.contains("did you mean `command.list`"), "{e}"); assert!(s.disabled_reason("engine.commands").unwrap().contains("`command.list`")); @@ -108,6 +109,7 @@ mod tests { #[test] fn near_misses_suggest_registered_ids() { + crate::install().unwrap(); // Typo, case, and the same verb in another namespace. assert!(unknown("edit.undoo").contains("did you mean `edit.undo`"), "{}", unknown("edit.undoo")); assert!(unknown("Edit.Undo").contains("did you mean `edit.undo`"), "{}", unknown("Edit.Undo")); @@ -135,6 +137,7 @@ mod tests { #[test] fn protocol_method_hints() { + crate::install().unwrap(); let methods = ["engine.execute", "doc.inspect", "doc.open", "methods"]; assert_eq!(unknown_method("doc.inspct", &methods), "unknown method `doc.inspct`; did you mean `doc.inspect`?"); assert!(unknown_method("edit.undo", &methods).contains("engine.execute {\"command\": \"edit.undo\"}")); diff --git a/crates/engine/src/crop_fill.rs b/crates/engine-core/src/crop_fill.rs similarity index 99% rename from crates/engine/src/crop_fill.rs rename to crates/engine-core/src/crop_fill.rs index d127168220..cbef2df1e7 100644 --- a/crates/engine/src/crop_fill.rs +++ b/crates/engine-core/src/crop_fill.rs @@ -347,7 +347,7 @@ mod tests { #[test] fn only_a_visible_unlocked_active_raster_adds_a_target() { use photocraft_doc::{Layer, LayerContent, TextLayer}; - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", serde_json::json!({"width": 8, "height": 8, "background": "white"})).unwrap(); let base = (*s.active().unwrap().doc).clone(); let fmt = base.pixel_format(); diff --git a/crates/engine/src/dense_budget_tests.rs b/crates/engine-core/src/dense_budget_tests.rs similarity index 95% rename from crates/engine/src/dense_budget_tests.rs rename to crates/engine-core/src/dense_budget_tests.rs index dd74a70de3..c24ca94828 100644 --- a/crates/engine/src/dense_budget_tests.rs +++ b/crates/engine-core/src/dense_budget_tests.rs @@ -22,7 +22,7 @@ fn distant_blocks(s: &Surface) -> Surface { /// A small document whose active layer holds [`distant_blocks`]. fn sparse_session() -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64})).unwrap(); let id = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap()); let doc = Arc::make_mut(s.active_mut().unwrap().doc_mut()); @@ -53,7 +53,7 @@ fn shadows_highlights_over_distant_tiles_is_refused() { #[test] fn image_size_without_distant_tiles_still_resamples() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "background": "white"})).unwrap(); s.execute("image.imageSize", json!({"width": 128, "height": 128})).unwrap(); assert_eq!(s.active().unwrap().doc.size.width, 128); @@ -61,7 +61,7 @@ fn image_size_without_distant_tiles_still_resamples() { #[test] fn face_detection_on_a_huge_empty_canvas_is_refused() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300_000, "height": 300_000, "background": "transparent"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let e = s.execute("image.detectFaces", json!({"sampleAllLayers": false})).unwrap_err().to_string(); @@ -70,7 +70,7 @@ fn face_detection_on_a_huge_empty_canvas_is_refused() { #[test] fn multichannel_on_a_huge_empty_canvas_is_refused() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300_000, "height": 300_000, "background": "transparent"})).unwrap(); refused(&mut s, "image.mode.multichannel", json!({})); } @@ -82,7 +82,7 @@ fn multichannel_on_a_huge_empty_canvas_is_refused() { fn multichannel_counts_every_duotone_ink() { use photocraft_color::ColorMode; use photocraft_doc::{Duotone, DuotoneInk}; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 15_000, "height": 15_000, "background": "transparent"})).unwrap(); let doc = Arc::make_mut(s.active_mut().unwrap().doc_mut()); doc.mode = ColorMode::Duotone; diff --git a/crates/engine/src/display_color.rs b/crates/engine-core/src/display_color.rs similarity index 100% rename from crates/engine/src/display_color.rs rename to crates/engine-core/src/display_color.rs diff --git a/crates/engine/src/display_color/tests.rs b/crates/engine-core/src/display_color/tests.rs similarity index 98% rename from crates/engine/src/display_color/tests.rs rename to crates/engine-core/src/display_color/tests.rs index 8f0e6cc5b3..bfb74bc108 100644 --- a/crates/engine/src/display_color/tests.rs +++ b/crates/engine-core/src/display_color/tests.rs @@ -74,7 +74,7 @@ fn far(a: [f32; 3], b: [f32; 3], d: f32) -> bool { #[test] fn srgb_is_the_identity_fast_path() { - let s = Session::new(); + let s = crate::session(); for d in [rgb_doc(None, [0.8, 0.5, 0.3], SampleType::U8), rgb_doc(Some(Builtin::Srgb.profile()), [0.8, 0.5, 0.3], SampleType::U16)] { let cd = s.color.canvas_display(&d).unwrap(); assert!(cd.is_identity(), "sRGB on an sRGB monitor costs nothing"); @@ -97,7 +97,7 @@ fn srgb_is_the_identity_fast_path() { fn display_p3_matches_hand_computed_srgb() { // P3 (0.8, 0.5, 0.3): linear (0.6038, 0.2140, 0.0732) → linear sRGB through the published // P3 → sRGB matrix (0.6915, 0.1976, 0.0517) → encoded (216.7, 122.9, 64.3). - let s = Session::new(); + let s = crate::session(); let d = rgb_doc(Some(Builtin::DisplayP3.profile()), [0.8, 0.5, 0.3], SampleType::U8); let got = shown(&s, &d); assert!(close(got, [216.7, 122.9, 64.3], TOL), "{got:?}"); @@ -109,7 +109,7 @@ fn display_p3_matches_hand_computed_srgb() { #[test] fn wide_gamut_and_gray_fixtures_display_correctly() { - let s = Session::new(); + let s = crate::session(); let cases: [(&Profile, [f32; 3]); 3] = [ (Builtin::AdobeRgbCompat.profile(), [0.3, 0.7, 0.4]), (Builtin::ProPhotoCompat.profile(), [0.55, 0.35, 0.25]), @@ -133,7 +133,7 @@ fn wide_gamut_and_gray_fixtures_display_correctly() { #[test] fn embedded_cmyk_profile_is_used_for_display_and_flat_export() { - let s = Session::new(); + let s = crate::session(); let p = test_cmyk(); let ink = [0.1, 0.6, 0.7, 0.05]; let want = reference(&p, &ink); @@ -160,7 +160,7 @@ fn embedded_cmyk_profile_is_used_for_display_and_flat_export() { #[test] fn linear_documents_are_encoded_for_the_texture() { - let s = Session::new(); + let s = crate::session(); // Linear 0.2 is sRGB 0.4845 (123.5). let d = rgb_doc(Some(Builtin::LinearSrgb.profile()), [0.2, 0.2, 0.2], SampleType::F32); let cd = s.color.canvas_display(&d).unwrap(); @@ -177,7 +177,7 @@ fn linear_documents_are_encoded_for_the_texture() { #[test] fn exr_round_trip_is_linear() { - let mut s = Session::new(); + let mut s = crate::session(); // An sRGB document exported to EXR is linearised; re-opened it is tagged linear sRGB and // displays as before. let d = rgb_doc(None, [0.5, 0.25, 0.75], SampleType::F32); @@ -196,7 +196,7 @@ fn exr_round_trip_is_linear() { #[test] fn gray_exr_round_trip_is_linear() { - let mut s = Session::new(); + let mut s = crate::session(); // An sGray document exported to EXR is linearised (#2386); re-opened it is tagged linear gray // and displays as before. let mut d = Document::with_background("t", Size::new(8, 8), ColorMode::Grayscale, SampleType::U8, Color::gray(128.0 / 255.0)); @@ -216,7 +216,7 @@ fn gray_exr_round_trip_is_linear() { #[test] fn monitor_profile_setting() { - let mut s = Session::new(); + let mut s = crate::session(); let srgb = rgb_doc(None, [0.8, 0.5, 0.3], SampleType::U8); let p3 = rgb_doc(Some(Builtin::DisplayP3.profile()), [0.8, 0.5, 0.3], SampleType::U8); let r = s.execute("edit.colorSettings", json!({"monitorProfile": "display-p3"})).unwrap(); @@ -257,7 +257,7 @@ fn p3() -> Option> { #[test] fn monitor_status_says_what_is_applied() { use crate::display_color::MonitorDetection; - let mut s = Session::new(); + let mut s = crate::session(); let status = |s: &mut Session| s.execute("edit.colorSettings", json!({})).unwrap()["monitorStatus"].clone(); // No platform reader: sRGB, and the reply says it's a fallback. let st = status(&mut s); @@ -306,7 +306,7 @@ fn monitor_status_says_what_is_applied() { s.color.set_displays(Ok(vec![display(2, [0.0, 0.0, 100.0, 100.0], p3())])); assert_eq!(status(&mut s)["detection"]["state"], "found"); // Without displays read before, the failure is the reason. - let mut fresh = Session::new(); + let mut fresh = crate::session(); assert_eq!(fresh.color.set_displays(Err("osascript failed".into())), None); let st = status(&mut fresh); assert_eq!((st["source"].as_str(), st["reason"].as_str()), (Some("fallback"), Some("osascript failed"))); @@ -319,7 +319,7 @@ fn monitor_status_says_what_is_applied() { #[test] fn each_display_gets_its_own_profile() { - let mut s = Session::new(); + let mut s = crate::session(); // Built-in (primary, menu bar) left, a wide-gamut external display right and higher up, // as on the #569 setup (frames in points, y down). s.color.set_displays(Ok(vec![display(1, [0.0, 0.0, 1728.0, 1117.0], None), display(4, [1728.0, -667.0, 3008.0, 1692.0], p3())])); @@ -363,7 +363,7 @@ fn each_display_gets_its_own_profile() { #[test] fn saved_monitor_profile_that_is_gone_is_reported() { // Preferences load settings without validating them: a saved .icc path deleted since. - let mut s = Session::new(); + let mut s = crate::session(); s.color.settings.monitor_profile = "/nonexistent/photocraft/display.icc".into(); let st = s.color.monitor_status(); assert_eq!((st.requested.as_str(), st.source), ("/nonexistent/photocraft/display.icc", "fallback")); @@ -373,7 +373,7 @@ fn saved_monitor_profile_that_is_gone_is_reported() { #[test] fn monitor_profile_bad_params_fail_gracefully() { - let mut s = Session::new(); + let mut s = crate::session(); for bad in [ json!({"monitorProfile": "coated-cmyk"}), json!({"monitorProfile": "sgray"}), @@ -389,7 +389,7 @@ fn monitor_profile_bad_params_fail_gracefully() { #[test] fn proof_colors_still_apply_on_top() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "mode": "rgb", "depth": 8})).unwrap(); s.execute("edit.assignProfile", json!({"profile": "display-p3"})).unwrap(); let d = s.active().unwrap().doc.clone(); diff --git a/crates/engine/src/doc_path.rs b/crates/engine-core/src/doc_path.rs similarity index 100% rename from crates/engine/src/doc_path.rs rename to crates/engine-core/src/doc_path.rs diff --git a/crates/engine/src/doc_path/tests.rs b/crates/engine-core/src/doc_path/tests.rs similarity index 99% rename from crates/engine/src/doc_path/tests.rs rename to crates/engine-core/src/doc_path/tests.rs index 049e126a47..1e3b44c701 100644 --- a/crates/engine/src/doc_path/tests.rs +++ b/crates/engine-core/src/doc_path/tests.rs @@ -42,7 +42,7 @@ fn network_alias(p: &Path) -> String { /// A 32×32 white document saved (as far as its links know) at `d/doc.pcraft`, with `file` placed /// linked → (session, layer id). fn document(d: &Path, file: &Path) -> (Session, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.active_mut().unwrap().path = Some(d.join("doc.pcraft").to_string_lossy().into_owned()); s.execute("file.placeLinked", json!({"path": file.to_string_lossy()})).unwrap(); @@ -225,7 +225,7 @@ fn smart_displace_keeps_a_relative_map_path() { fn data_sets_and_footage_read_only_followed_files() { let d = dir("datasets"); png(&d.join("blue.png"), |_| [0, 0, 255]); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32, "background": "#ff0000"})).unwrap(); s.active_mut().unwrap().path = Some(d.join("doc.pcraft").to_string_lossy().into_owned()); let layer = s.active().unwrap().active_layer.unwrap(); diff --git a/crates/engine/src/doc_state.rs b/crates/engine-core/src/doc_state.rs similarity index 100% rename from crates/engine/src/doc_state.rs rename to crates/engine-core/src/doc_state.rs diff --git a/crates/engine/src/embed_all_linked_tests.rs b/crates/engine-core/src/embed_all_linked_tests.rs similarity index 98% rename from crates/engine/src/embed_all_linked_tests.rs rename to crates/engine-core/src/embed_all_linked_tests.rs index 70bed5c0c1..11fd04dc6b 100644 --- a/crates/engine/src/embed_all_linked_tests.rs +++ b/crates/engine-core/src/embed_all_linked_tests.rs @@ -23,7 +23,7 @@ fn painted_layer(s: &mut Session, red: f32) { /// Three smart objects: the first two linked to files in `dir`, the third embedded. fn three(dir: &std::path::Path) -> (Session, [u64; 3]) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 24})).unwrap(); let mut ids = [0u64; 3]; for (i, slot) in ids.iter_mut().enumerate() { @@ -68,6 +68,7 @@ fn temp_dir(name: &str) -> std::path::PathBuf { #[test] fn embed_linked_and_embed_all_linked_are_named_in_the_engine() { + crate::install().unwrap(); assert_eq!(label("layer.smartObjects.convertToEmbedded"), "Embed Linked"); assert_eq!(label("layer.smartObjects.embedAllLinked"), "Embed All Linked"); // The warp commands stay registered for scripts and the Edit menu routes. @@ -109,7 +110,7 @@ fn embed_all_linked_embeds_both_linked_objects_in_one_undoable_step() { #[test] fn embed_all_linked_with_no_linked_object_is_an_error_not_a_panic() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("layer.smartObjects.embedAllLinked"), "no document"); assert!(s.execute("layer.smartObjects.embedAllLinked", json!({})).is_err()); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); diff --git a/crates/engine/src/eraser_gray_background_tests.rs b/crates/engine-core/src/eraser_gray_background_tests.rs similarity index 98% rename from crates/engine/src/eraser_gray_background_tests.rs rename to crates/engine-core/src/eraser_gray_background_tests.rs index 33ae4915c8..b8bed101bc 100644 --- a/crates/engine/src/eraser_gray_background_tests.rs +++ b/crates/engine-core/src/eraser_gray_background_tests.rs @@ -9,7 +9,7 @@ use serde_json::json; const GREEN_200: [f32; 4] = [0.0, 200.0 / 255.0, 0.0, 1.0]; fn session(mode: &str) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "mode": mode, "depth": 8, "background": "white"})).unwrap(); s.tools.background = GREEN_200; s @@ -114,7 +114,7 @@ fn other_gray_working_spaces_keep_the_plain_luma() { #[test] fn a_gray_document_tagged_with_another_profile_keeps_the_plain_luma() { for profile in ["sgray", "gray-gamma-2.2"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "mode": "grayscale", "depth": 8, "background": "white", "profile": profile})).unwrap(); s.tools.background = GREEN_200; assert_erase_and_fill_give_luma(s, &format!("document profile {profile}")); @@ -123,7 +123,7 @@ fn a_gray_document_tagged_with_another_profile_keeps_the_plain_luma() { #[test] fn a_gray_document_tagged_with_the_default_profile_still_gets_the_measured_gray() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "mode": "grayscale", "depth": 8, "background": "white", "profile": "dot-gain-20-compat"})).unwrap(); s.tools.background = GREEN_200; erase_at(&mut s, 20, 16); diff --git a/crates/engine/src/error.rs b/crates/engine-core/src/error.rs similarity index 100% rename from crates/engine/src/error.rs rename to crates/engine-core/src/error.rs diff --git a/crates/engine/src/fill_layer_mode_tests.rs b/crates/engine-core/src/fill_layer_mode_tests.rs similarity index 99% rename from crates/engine/src/fill_layer_mode_tests.rs rename to crates/engine-core/src/fill_layer_mode_tests.rs index 4bcc25ef26..728f37f3eb 100644 --- a/crates/engine/src/fill_layer_mode_tests.rs +++ b/crates/engine-core/src/fill_layer_mode_tests.rs @@ -9,7 +9,7 @@ const BLUE: [f32; 4] = [0.0, 0.0, 1.0, 1.0]; const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "mode": mode, "depth": depth, "background": "white"})).unwrap(); s.tools.foreground = BLUE; s.tools.background = GREEN; diff --git a/crates/engine/src/filters.rs b/crates/engine-core/src/filters.rs similarity index 100% rename from crates/engine/src/filters.rs rename to crates/engine-core/src/filters.rs diff --git a/crates/engine/src/filters/tests.rs b/crates/engine-core/src/filters/tests.rs similarity index 99% rename from crates/engine/src/filters/tests.rs rename to crates/engine-core/src/filters/tests.rs index 718b30edaf..a34e7d6c1d 100644 --- a/crates/engine/src/filters/tests.rs +++ b/crates/engine-core/src/filters/tests.rs @@ -52,7 +52,7 @@ fn channel_filter_transparency_follows_native_alpha_format() { } fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#3366cc"})).ok(); @@ -66,7 +66,7 @@ fn active_pixels(s: &Session) -> Vec { } fn mask_session(reveal_selection: bool) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "#ff0000"})).unwrap(); if reveal_selection { s.execute("select.all", json!({})).unwrap(); @@ -132,7 +132,7 @@ const ALL: [&str; 24] = [ #[test] fn enormous_global_filter_is_refused_before_allocating_and_preserves_document() { - let mut s = Session::new(); + let mut s = crate::session(); // A sparse document exercises admission without allocating a giant background first. s.add_document( photocraft_doc::Document::new("large", photocraft_doc::Size::new(300000, 300000), photocraft_color::ColorMode::Rgb, photocraft_color::SampleType::U8), @@ -210,7 +210,7 @@ fn specs_are_complete_and_documented() { #[test] fn disabled_without_pixel_layer() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("filter.blur.gaussianBlur")); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); @@ -278,7 +278,7 @@ fn solarize_and_add_noise_process_untouched_reveal_all_masks() { fn minimum_signed_offset_matches_its_wrapped_distance() { for depth in [8, 16, 32] { let make_session = || { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); paint_pattern(&mut s); @@ -387,7 +387,7 @@ fn params_map_to_algorithm_units() { #[test] fn minimum_maximum_preserve_roundness() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "depth": depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); // A white dot on black. @@ -532,7 +532,7 @@ fn keep_alpha_stops_when_cancelled_and_keeps_the_tiles() { /// object re-renders. A map chosen again replaces it. #[test] fn displace_on_a_smart_object_embeds_its_map() { - let mut s = Session::new(); + let mut s = crate::session(); // Documents 0 and 1: a white and a black displacement map. s.execute("file.new", json!({"width": 8, "height": 8, "background": "white"})).unwrap(); s.execute("file.new", json!({"width": 8, "height": 8, "background": "black"})).unwrap(); diff --git a/crates/engine/src/filters/validation.rs b/crates/engine-core/src/filters/validation.rs similarity index 100% rename from crates/engine/src/filters/validation.rs rename to crates/engine-core/src/filters/validation.rs diff --git a/crates/engine/src/filters/validation/tests.rs b/crates/engine-core/src/filters/validation/tests.rs similarity index 99% rename from crates/engine/src/filters/validation/tests.rs rename to crates/engine-core/src/filters/validation/tests.rs index ebfede162e..e004e618db 100644 --- a/crates/engine/src/filters/validation/tests.rs +++ b/crates/engine-core/src/filters/validation/tests.rs @@ -7,7 +7,7 @@ use super::*; use crate::Session; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width":16,"height":12,"depth":depth})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("pattern", |doc, active| { diff --git a/crates/engine/src/filters_ext.rs b/crates/engine-core/src/filters_ext.rs similarity index 100% rename from crates/engine/src/filters_ext.rs rename to crates/engine-core/src/filters_ext.rs diff --git a/crates/engine/src/filters_ext/tests.rs b/crates/engine-core/src/filters_ext/tests.rs similarity index 98% rename from crates/engine/src/filters_ext/tests.rs rename to crates/engine-core/src/filters_ext/tests.rs index 60db1cbb45..ad9f0d2bdb 100644 --- a/crates/engine/src/filters_ext/tests.rs +++ b/crates/engine-core/src/filters_ext/tests.rs @@ -2,7 +2,7 @@ use super::*; use photocraft_geom::Rect; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("pattern", |doc, active| { @@ -110,6 +110,7 @@ fn test_params(id: &str) -> Value { #[test] fn ids_match_the_menu_catalog_and_are_unique() { + crate::install().unwrap(); let all = crate::command_specs(); for id in IDS { assert!(crate::commands::find(id).is_some(), "{id} not registered"); @@ -137,7 +138,7 @@ fn every_new_filter_runs_changes_pixels_and_undoes_in_one_step() { #[test] fn new_filters_work_at_16_and_32_bit() { for (depth, mode) in [(16, "rgb"), (32, "rgb"), (8, "cmyk"), (16, "lab"), (8, "gray")] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 16, "depth": depth, "mode": mode})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"color": "#3366cc"})).ok(); @@ -149,7 +150,7 @@ fn new_filters_work_at_16_and_32_bit() { #[test] fn disabled_without_pixel_layer() { - let mut s = Session::new(); + let mut s = crate::session(); for id in IDS { assert!(!s.is_enabled(id), "{id}"); } @@ -197,7 +198,7 @@ fn colour_filters_use_and_record_tool_colours() { fn fibers_fill_an_empty_layer() { // #5241: Fibers renders from the colours, not the layer's pixels, so an empty layer fills // like in Photoshop (and can be transformed afterwards). - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("filter.render.fibers", json!({"seed": 3})).unwrap(); @@ -342,7 +343,7 @@ fn paint_shaded_disc(s: &mut Session, size: i32) { } fn relight_session(w: i32, h: i32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); paint_shaded_disc(&mut s, w.min(h)); @@ -351,11 +352,12 @@ fn relight_session(w: i32, h: i32) -> Session { #[test] fn relight_command_exists_and_toggles_with_document() { + crate::install().unwrap(); let spec = crate::commands::find("filter.render.relight").expect("registered"); assert_eq!(spec.menu, &["Filter", "Render"]); assert_eq!(spec.label, "Relight…"); assert!(spec.journal); - let mut s = Session::new(); + let mut s = crate::session(); assert!(!s.is_enabled("filter.render.relight")); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); diff --git a/crates/engine/src/fx_mode_tests.rs b/crates/engine-core/src/fx_mode_tests.rs similarity index 99% rename from crates/engine/src/fx_mode_tests.rs rename to crates/engine-core/src/fx_mode_tests.rs index 660a69b10a..9160d82f83 100644 --- a/crates/engine/src/fx_mode_tests.rs +++ b/crates/engine-core/src/fx_mode_tests.rs @@ -8,7 +8,7 @@ use serde_json::{Value, json}; const KINDS: [&str; 9] = ["dropShadow", "innerShadow", "outerGlow", "innerGlow", "satin", "colorOverlay", "gradientOverlay", "stroke", "bevelEmboss"]; fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 32, "mode": mode, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 12, "y": 8, "width": 24, "height": 16})).unwrap(); diff --git a/crates/engine/src/group_options.rs b/crates/engine-core/src/group_options.rs similarity index 99% rename from crates/engine/src/group_options.rs rename to crates/engine-core/src/group_options.rs index a2a50f027b..4c72b2f078 100644 --- a/crates/engine/src/group_options.rs +++ b/crates/engine-core/src/group_options.rs @@ -97,7 +97,7 @@ mod tests { /// Background, then `A` and `B` (`B` active). fn session() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let a = id(s.execute("layer.new.layer", json!({"name": "A"})).unwrap()); let b = id(s.execute("layer.new.layer", json!({"name": "B"})).unwrap()); diff --git a/crates/engine/src/guide_layout.rs b/crates/engine-core/src/guide_layout.rs similarity index 100% rename from crates/engine/src/guide_layout.rs rename to crates/engine-core/src/guide_layout.rs diff --git a/crates/engine/src/hidden_target.rs b/crates/engine-core/src/hidden_target.rs similarity index 99% rename from crates/engine/src/hidden_target.rs rename to crates/engine-core/src/hidden_target.rs index 01e9ec0959..ec64dcf69c 100644 --- a/crates/engine/src/hidden_target.rs +++ b/crates/engine-core/src/hidden_target.rs @@ -70,7 +70,7 @@ mod tests { use crate::Session; fn session() -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 64, "background": "white"})).unwrap(); let id = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); (s, id) diff --git a/crates/engine/src/inspect.rs b/crates/engine-core/src/inspect.rs similarity index 99% rename from crates/engine/src/inspect.rs rename to crates/engine-core/src/inspect.rs index 7ecceaa3e0..dbca3b7d58 100644 --- a/crates/engine/src/inspect.rs +++ b/crates/engine-core/src/inspect.rs @@ -281,7 +281,7 @@ mod tests { #[test] fn an_adjustment_layer_is_reported_with_the_params_its_command_takes() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.execute("layer.newAdjustmentLayer.levels", json!({"inBlack": 10, "inWhite": 240, "gamma": 1.2})).unwrap(); let info = s.execute("document.inspect", json!({})).unwrap(); @@ -301,7 +301,7 @@ mod tests { /// #6541: an adjustment PhotoCraft keeps but cannot render is reported as such, not as an Invert. #[test] fn an_unsupported_adjustment_layer_is_reported_as_kept_not_rendered() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); s.edit("unsupported fixture", |doc, active| { @@ -327,7 +327,7 @@ mod tests { #[test] fn document_inspect_reports_raster_and_vector_masks_when_nested() { let cases = [(false, None), (true, None), (false, Some(true)), (false, Some(false)), (true, Some(true))]; - let mut session = Session::new(); + let mut session = crate::session(); session.execute("file.new", json!({"width": 1, "height": 1})).unwrap(); let layers = cases .iter() diff --git a/crates/engine/src/install.rs b/crates/engine-core/src/install.rs similarity index 100% rename from crates/engine/src/install.rs rename to crates/engine-core/src/install.rs diff --git a/crates/engine/src/install/command_ids.txt b/crates/engine-core/src/install/command_ids.txt similarity index 100% rename from crates/engine/src/install/command_ids.txt rename to crates/engine-core/src/install/command_ids.txt diff --git a/crates/engine/src/install/order_tests.rs b/crates/engine-core/src/install/order_tests.rs similarity index 100% rename from crates/engine/src/install/order_tests.rs rename to crates/engine-core/src/install/order_tests.rs diff --git a/crates/engine/src/installed_profiles.rs b/crates/engine-core/src/installed_profiles.rs similarity index 99% rename from crates/engine/src/installed_profiles.rs rename to crates/engine-core/src/installed_profiles.rs index 406240683b..10e38b75da 100644 --- a/crates/engine/src/installed_profiles.rs +++ b/crates/engine-core/src/installed_profiles.rs @@ -226,7 +226,7 @@ mod tests { #[test] fn command_filters_and_rejects_bad_params() { - let mut s = Session::new(); + let mut s = crate::session(); let r = s.execute("edit.installedProfiles", json!({})).unwrap(); assert!(r["profiles"].is_array() && r["dirs"].is_array()); let r = s.execute("edit.installedProfiles", json!({"class": "output", "colorSpace": "cmyk"})).unwrap(); diff --git a/crates/engine/src/jobs.rs b/crates/engine-core/src/jobs.rs similarity index 99% rename from crates/engine/src/jobs.rs rename to crates/engine-core/src/jobs.rs index 53b0e343bd..bee59a15a9 100644 --- a/crates/engine/src/jobs.rs +++ b/crates/engine-core/src/jobs.rs @@ -2281,7 +2281,7 @@ mod psd_open_confirmation_tests { /// Verifies headless opens return readable PSD content and warnings without a held prompt. #[test] fn headless_open_keeps_best_effort_psd_import() { - let mut s = Session::new(); + let mut s = crate::session(); let started = s.start_open("damaged.psd", OpenSource::Bytes(Arc::new(super::psd_open_fixture::make_psd(true)))).unwrap(); let v = result(&mut s, started); assert!(v.get("document").is_some(), "{v}"); @@ -2294,7 +2294,7 @@ mod psd_open_confirmation_tests { #[test] fn interactive_open_holds_only_a_damaged_psd() { for corrupt in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); let started = s.start_open_for_user("file.psd", OpenSource::Bytes(Arc::new(super::psd_open_fixture::make_psd(corrupt)))).unwrap(); let v = result(&mut s, started); if corrupt { diff --git a/crates/engine/src/jobs/tests.rs b/crates/engine-core/src/jobs/tests.rs similarity index 99% rename from crates/engine/src/jobs/tests.rs rename to crates/engine-core/src/jobs/tests.rs index 949f5cbb9d..c96eed72ca 100644 --- a/crates/engine/src/jobs/tests.rs +++ b/crates/engine-core/src/jobs/tests.rs @@ -9,7 +9,7 @@ use crate::Session; /// A document `w`×`h` with a textured pixel layer (so blurs change every pixel). fn session(w: u32, h: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.edit("pattern", |doc, active| { @@ -736,7 +736,7 @@ fn open_runs_as_a_job_and_cancel_adds_nothing() { let doc = (*src.active().unwrap().doc).clone(); let bytes = photocraft_io::export(&doc, "x.psd", &Default::default()).unwrap().bytes; src.close(0); - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s.start_open("x.psd", OpenSource::Bytes(Arc::new(bytes.clone()))).unwrap()); let e = wait_event(&mut s, id); let JobOutcome::Done(v) = &e.outcome else { panic!("{e:?}") }; @@ -756,7 +756,7 @@ fn open_runs_as_a_job_and_cancel_adds_nothing() { #[test] fn cancelled_batch_job_returns_its_partial_result() { - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s .start_job( "file.automate.batch", @@ -787,7 +787,7 @@ fn cancelled_batch_job_returns_its_partial_result() { #[cfg(not(target_arch = "wasm32"))] #[test] fn programmatic_cancel_wakes_a_batch_waiting_for_the_desktop_decision() { - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s .start_job( "file.automate.batch", @@ -819,7 +819,7 @@ fn programmatic_cancel_wakes_a_batch_waiting_for_the_desktop_decision() { #[test] fn accepted_batch_cancellation_after_result_snapshot_is_reported() { - let mut s = Session::new(); + let mut s = crate::session(); let (ready_tx, ready_rx) = std::sync::mpsc::channel(); let (resume_tx, resume_rx) = std::sync::mpsc::channel(); let id = job(s @@ -850,7 +850,7 @@ fn accepted_batch_cancellation_after_result_snapshot_is_reported() { #[test] fn cancel_all_counts_an_accepted_batch_cancellation() { - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s .start_job( "file.automate.batch", @@ -875,7 +875,7 @@ fn cancel_all_counts_an_accepted_batch_cancellation() { #[cfg(not(target_arch = "wasm32"))] #[test] fn a_finished_batch_worker_rejects_late_cancellation() { - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s .start_job("file.automate.batch", json!({}), "Batch", false, |_| Ok(json!({"files": ["done.png"], "cancelled": false})), |_, result| Ok(result)) .unwrap()); @@ -902,7 +902,7 @@ fn an_exr_path_open_decodes_in_bands_and_cancels_cleanly() { let path = std::env::temp_dir().join(format!("photocraft-open-job-{}.exr", std::process::id())); std::fs::write(&path, &bytes).unwrap(); let reference = photocraft_io::import("band.exr", &bytes).unwrap().document; - let mut s = Session::new(); + let mut s = crate::session(); let id = job(s.start_open("band.exr", OpenSource::Path(path.to_string_lossy().into_owned())).unwrap()); let e = wait_event(&mut s, id); assert!(matches!(e.outcome, JobOutcome::Done(_)), "{e:?}"); @@ -931,7 +931,7 @@ fn an_open_that_asks_about_its_profile_holds_the_document_back() { doc.icc_profile = Some(craft_cms::Builtin::from_id("adobe-rgb-compat").unwrap().profile().to_bytes()); let bytes = Arc::new(photocraft_io::export(&doc, "x.png", &Default::default()).unwrap().bytes); src.close(0); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("edit.colorSettings", json!({"askOnMismatch": true, "policyRgb": "preserve"})).unwrap(); let id = job(s.start_open("x.png", OpenSource::Bytes(Arc::clone(&bytes))).unwrap()); let JobOutcome::Done(v) = wait_event(&mut s, id).outcome else { panic!() }; @@ -1450,7 +1450,7 @@ fn an_inline_stepped_job_stops_when_cancelled() { fn background_admission_counts_cancelled_workers_until_they_finish() { // Dropping the senders releases every worker even if an assertion unwinds. let mut gates = Vec::new(); - let mut s = Session::new(); + let mut s = crate::session(); let mut ids = Vec::new(); for _ in 0..MAX_BACKGROUND_JOBS { let (tx, rx) = std::sync::mpsc::channel::<()>(); @@ -1539,7 +1539,7 @@ fn approved_open_forwards_the_flag_and_the_bound_estimate() { let snapshot = photocraft_io::memory::MemorySnapshot { available_ram: Some(8 * gb), swap_free: None, commit_headroom: None }; photocraft_io::memory::with_mock_memory(snapshot, || { photocraft_io::psd_budget::with_test_estimate_charge(4 * gb + 1, || { - let mut s = Session::new(); + let mut s = crate::session(); let started = s.start_open_for_user_with_background("tiny.psd", OpenSource::Bytes(Arc::clone(&bytes)), false).unwrap(); let v = match started { Started::Done(v) => v, @@ -1566,7 +1566,7 @@ fn approval_is_bound_to_the_approved_estimate() { let snapshot = photocraft_io::memory::MemorySnapshot { available_ram: Some(8 * gb), swap_free: None, commit_headroom: None }; photocraft_io::memory::with_mock_memory(snapshot, || { photocraft_io::psd_budget::with_test_estimate_charge(4 * gb + 1, || { - let mut s = Session::new(); + let mut s = crate::session(); let source = OpenSource::Bytes(Arc::clone(&bytes)); let fingerprint = SourceFingerprint::of(&source).unwrap(); // Consent given for a much smaller estimate does not cover this file. @@ -1588,7 +1588,7 @@ fn unknown_capacity_metadata_never_invents_available_ram() { photocraft_io::memory::with_mock_memory(snapshot, || { // Above both the 2 GiB unknown-capacity allowance and the 8 GiB warning threshold. photocraft_io::psd_budget::with_test_estimate_charge(8 * gb + 1, || { - let mut s = Session::new(); + let mut s = crate::session(); let started = s.start_open_for_user_with_background("unknown.psd", OpenSource::Bytes(Arc::clone(&bytes)), false).unwrap(); let v = match started { Started::Done(v) => v, @@ -1613,7 +1613,7 @@ fn an_open_reports_a_typed_hard_budget_refusal() { assert!(hard < u64::MAX, "the test needs a finite hard limit"); photocraft_io::memory::with_mock_memory(snapshot, || { photocraft_io::psd_budget::with_test_estimate_charge(hard + 1, || { - let mut s = Session::new(); + let mut s = crate::session(); let err = s.start_open_for_user_with_background("over.psd", OpenSource::Bytes(Arc::clone(&bytes)), false).unwrap_err(); match &err { EngineError::PsdHardBudget { required, limit, .. } => assert!(*required > hard && *limit == hard), @@ -1627,7 +1627,7 @@ fn an_open_reports_a_typed_hard_budget_refusal() { #[cfg(not(target_arch = "wasm32"))] #[test] fn a_failed_job_keeps_its_typed_error_for_wait_and_events() { - let mut s = Session::new(); + let mut s = crate::session(); let started = s .start_job( "test.hardBudget", @@ -1664,7 +1664,7 @@ fn a_replaced_path_is_refused_with_the_source_identity_reason() { let replacement = dir.join("replacement.psd"); std::fs::write(&replacement, &bytes).unwrap(); std::fs::rename(&replacement, &path).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let err = s .start_open_approved_with_background("source.psd", source.clone(), false, Some(1024), Some(fingerprint.clone()), false) .expect_err("the handle is not the approved file"); @@ -1693,7 +1693,7 @@ fn a_same_size_rewrite_with_a_restored_mtime_is_refused_with_the_identity_reason // Same inode, same length, same bytes, restored modification time: only ctime differs. std::fs::write(&path, &bytes).unwrap(); std::fs::OpenOptions::new().write(true).open(&path).unwrap().set_times(std::fs::FileTimes::new().set_modified(modified)).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let err = s .start_open_approved_with_background("source.psd", source, false, Some(1024), Some(fingerprint), false) .expect_err("the rewrite is not the file whose estimate was approved"); diff --git a/crates/engine/src/keymap_defs.rs b/crates/engine-core/src/keymap_defs.rs similarity index 98% rename from crates/engine/src/keymap_defs.rs rename to crates/engine-core/src/keymap_defs.rs index d8753c3a04..c26cc4b253 100644 --- a/crates/engine/src/keymap_defs.rs +++ b/crates/engine-core/src/keymap_defs.rs @@ -157,6 +157,7 @@ mod tests { #[test] fn preferences_and_overrides_convert_both_ways() { + crate::install().unwrap(); let mut prefs = Preferences::default(); prefs.shortcuts.insert("edit.copy".into(), "F9".into()); prefs.shortcuts.insert("edit.cut".into(), String::new()); @@ -178,6 +179,7 @@ mod tests { #[test] fn a_binding_equal_to_the_defaults_is_no_override() { + crate::install().unwrap(); let mut prefs = Preferences::default(); prefs.shortcuts.insert("edit.copy".into(), "Cmd+C".into()); assert!(prefs_overrides(&prefs).is_empty()); @@ -185,6 +187,7 @@ mod tests { #[test] fn the_catalog_holds_commands_tools_and_held_keys_once() { + crate::install().unwrap(); let defs = command_defs(); let mut ids: Vec = defs.iter().map(|d| d.command.key()).collect(); let n = ids.len(); diff --git a/crates/engine/src/layer_place.rs b/crates/engine-core/src/layer_place.rs similarity index 100% rename from crates/engine/src/layer_place.rs rename to crates/engine-core/src/layer_place.rs diff --git a/crates/engine/src/layer_place_tests.rs b/crates/engine-core/src/layer_place_tests.rs similarity index 99% rename from crates/engine/src/layer_place_tests.rs rename to crates/engine-core/src/layer_place_tests.rs index aa818ca47f..ee95707ae4 100644 --- a/crates/engine/src/layer_place_tests.rs +++ b/crates/engine-core/src/layer_place_tests.rs @@ -6,7 +6,7 @@ use crate::Session; /// Background, then `A` and `B` (`B` active). fn session() -> (Session, LayerId, LayerId) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let a = id(s.execute("layer.new.layer", json!({"name": "A"})).unwrap()); let b = id(s.execute("layer.new.layer", json!({"name": "B"})).unwrap()); diff --git a/crates/engine/src/layer_style.rs b/crates/engine-core/src/layer_style.rs similarity index 100% rename from crates/engine/src/layer_style.rs rename to crates/engine-core/src/layer_style.rs diff --git a/crates/engine/src/layer_style/gradient_overlay.rs b/crates/engine-core/src/layer_style/gradient_overlay.rs similarity index 100% rename from crates/engine/src/layer_style/gradient_overlay.rs rename to crates/engine-core/src/layer_style/gradient_overlay.rs diff --git a/crates/engine/src/layer_style/inner_shadow_ranges_tests.rs b/crates/engine-core/src/layer_style/inner_shadow_ranges_tests.rs similarity index 98% rename from crates/engine/src/layer_style/inner_shadow_ranges_tests.rs rename to crates/engine-core/src/layer_style/inner_shadow_ranges_tests.rs index a2860a0f8a..ead55e0435 100644 --- a/crates/engine/src/layer_style/inner_shadow_ranges_tests.rs +++ b/crates/engine-core/src/layer_style/inner_shadow_ranges_tests.rs @@ -8,7 +8,7 @@ use crate::Session; use serde_json::json; fn session(width: u32, height: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": width, "height": height, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s @@ -85,7 +85,7 @@ fn a_drop_shadow_still_stores_what_it_is_given() { /// levels are the ones the compositor already gave, so the range change moves no pixel. #[test] fn an_inner_shadow_reaching_past_the_layer_paints_it_as_before() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 100, "y": 75, "width": 200, "height": 150})).unwrap(); diff --git a/crates/engine/src/layer_style/outer_glow_defaults_tests.rs b/crates/engine-core/src/layer_style/outer_glow_defaults_tests.rs similarity index 99% rename from crates/engine/src/layer_style/outer_glow_defaults_tests.rs rename to crates/engine-core/src/layer_style/outer_glow_defaults_tests.rs index 3fdac39f7e..11011665b2 100644 --- a/crates/engine/src/layer_style/outer_glow_defaults_tests.rs +++ b/crates/engine-core/src/layer_style/outer_glow_defaults_tests.rs @@ -10,7 +10,7 @@ use serde_json::json; /// The issue's test document: 400 x 300 px at 72 ppi, RGB 8 bit, a filled (64,64,64) /// Background and a pixel layer with an orange (255,128,0) rectangle at x 100..299, y 75..224. fn test_document() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 400, "height": 300, "resolution": 72, "background": "#404040"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 100, "y": 75, "width": 200, "height": 150})).unwrap(); @@ -20,7 +20,7 @@ fn test_document() -> Session { } fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s diff --git a/crates/engine/src/layer_style/tests.rs b/crates/engine-core/src/layer_style/tests.rs similarity index 99% rename from crates/engine/src/layer_style/tests.rs rename to crates/engine-core/src/layer_style/tests.rs index 66cedde5c0..cf6616020c 100644 --- a/crates/engine/src/layer_style/tests.rs +++ b/crates/engine-core/src/layer_style/tests.rs @@ -2,7 +2,7 @@ use super::*; use serde_json::json; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s @@ -18,7 +18,7 @@ fn effects(s: &Session) -> Vec { #[test] fn stroke_emboss_shades_the_stroke_band_only() { let render = |stroke: bool, bevel: Option<&str>| { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 120, "height": 90, "background": "#d8d8d8"})).unwrap(); s.execute("shape.create", json!({"kind": "rect", "rect": [30, 25, 60, 40], "fill": "#3f6fd8"})).unwrap(); if stroke { @@ -320,7 +320,7 @@ fn clear_one_effect_by_index() { #[test] fn color_overlay_renders() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); s.execute("layer.layerStyle.colorOverlay", json!({"color": "#ff0000"})).unwrap(); let px: Vec = serde_json::from_value(s.execute("document.pixel", json!({"x": 3, "y": 3})).unwrap()).unwrap(); @@ -632,7 +632,7 @@ fn layer_style_defaults_persist_with_presets() { let mut s = session(); s.execute("layer.layerStyle.makeDefault", json!({"kind": "stroke", "params": {"size": 9}})).unwrap(); let blob = s.presets.to_json(&s); - let mut t = Session::new(); + let mut t = crate::session(); t.load_presets_json(blob); let r = t.execute("layer.layerStyle.defaultFor", json!({"kind": "stroke"})).unwrap(); assert_eq!(r["user"], json!(true)); @@ -642,7 +642,7 @@ fn layer_style_defaults_persist_with_presets() { #[test] fn double_stroke_bands_render_and_survive_an_edit() { // The manga/typesetting case (#157): a 7 px white stroke under a 3 px black one. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 48, "height": 48})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 16, "y": 16, "width": 16, "height": 16})).unwrap(); diff --git a/crates/engine/src/lib.rs b/crates/engine-core/src/lib.rs similarity index 100% rename from crates/engine/src/lib.rs rename to crates/engine-core/src/lib.rs diff --git a/crates/engine/src/link_watch.rs b/crates/engine-core/src/link_watch.rs similarity index 99% rename from crates/engine/src/link_watch.rs rename to crates/engine-core/src/link_watch.rs index 7cbb1cff09..e88ab04df7 100644 --- a/crates/engine/src/link_watch.rs +++ b/crates/engine-core/src/link_watch.rs @@ -242,7 +242,7 @@ mod tests { let n = NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed); let d = dir(&format!("png-{}-{n}", color.trim_start_matches('#'))); let path = d.join("x.png").to_string_lossy().into_owned(); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": w, "height": h, "background": color})).unwrap(); s.execute("file.saveACopy", json!({"path": path, "layers": false})).unwrap(); std::fs::read(&path).unwrap() @@ -256,7 +256,7 @@ mod tests { /// A 40×40 white document with the file at `path` placed linked → (session, layer id). fn placed(path: &std::path::Path) -> (Session, u64) { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("file.placeLinked", json!({"path": path.to_string_lossy()})).unwrap(); let id = s.active().unwrap().active_layer.unwrap().0; diff --git a/crates/engine/src/malloc_tuning.rs b/crates/engine-core/src/malloc_tuning.rs similarity index 100% rename from crates/engine/src/malloc_tuning.rs rename to crates/engine-core/src/malloc_tuning.rs diff --git a/crates/engine/src/memory.rs b/crates/engine-core/src/memory.rs similarity index 100% rename from crates/engine/src/memory.rs rename to crates/engine-core/src/memory.rs diff --git a/crates/engine/src/memory_gate.rs b/crates/engine-core/src/memory_gate.rs similarity index 100% rename from crates/engine/src/memory_gate.rs rename to crates/engine-core/src/memory_gate.rs diff --git a/crates/engine/src/mixer_indexed_bitmap_tests.rs b/crates/engine-core/src/mixer_indexed_bitmap_tests.rs similarity index 96% rename from crates/engine/src/mixer_indexed_bitmap_tests.rs rename to crates/engine-core/src/mixer_indexed_bitmap_tests.rs index 8f31a41cd5..eed1281ca8 100644 --- a/crates/engine/src/mixer_indexed_bitmap_tests.rs +++ b/crates/engine-core/src/mixer_indexed_bitmap_tests.rs @@ -20,7 +20,7 @@ fn assert_refused(s: &mut Session, text: &str) { #[test] fn indexed_color_documents_are_refused_with_the_alert() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "background": "white"})).unwrap(); s.execute("image.mode.indexedColor", json!({})).unwrap(); assert_refused(&mut s, INDEXED_REFUSAL); @@ -32,7 +32,7 @@ fn indexed_color_documents_are_refused_with_the_alert() { #[test] fn bitmap_documents_are_refused_with_the_alert() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 32, "background": "white"})).unwrap(); s.execute("image.mode.grayscale", json!({})).unwrap(); s.execute("image.mode.bitmap", json!({})).unwrap(); @@ -45,7 +45,7 @@ fn rgb_cmyk_lab_and_grayscale_documents_still_paint() { let mut painted = 0; for mode in ["rgb", "cmyk", "lab", "grayscale"] { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); // Not every mode has every depth (as in the reference, CMYK and Lab stop at 16 bits). if s.execute("file.new", json!({"width": 64, "height": 32, "mode": mode, "depth": depth, "background": "white"})).is_err() { continue; diff --git a/crates/engine/src/mixer_toggle_commands_tests.rs b/crates/engine-core/src/mixer_toggle_commands_tests.rs similarity index 95% rename from crates/engine/src/mixer_toggle_commands_tests.rs rename to crates/engine-core/src/mixer_toggle_commands_tests.rs index 910b8b6af1..8a18ef114d 100644 --- a/crates/engine/src/mixer_toggle_commands_tests.rs +++ b/crates/engine-core/src/mixer_toggle_commands_tests.rs @@ -19,7 +19,7 @@ fn values(s: &Session) -> [bool; 3] { #[test] fn each_switch_flips_its_setting_or_sets_it_from_on() { - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(values(&s), [true, true, false], "the options bar's defaults"); for (i, (id, _)) in SWITCHES.iter().enumerate() { let before = values(&s); @@ -39,7 +39,7 @@ fn each_switch_flips_its_setting_or_sets_it_from_on() { #[test] fn wrong_types_are_errors_and_change_nothing() { - let mut s = Session::new(); + let mut s = crate::session(); for (id, _) in SWITCHES { let before = values(&s); for bad in [json!({"on": 1}), json!({"on": "yes"}), json!({"on": [true]})] { @@ -51,6 +51,7 @@ fn wrong_types_are_errors_and_change_nothing() { #[test] fn keyboard_shortcuts_list_the_five_without_keys_and_can_assign_one() { + crate::install().unwrap(); assert_eq!(MIXER_BRUSH_COMMANDS, ["brush.mixer.load", "brush.mixer.clean", "brush.mixer.autoLoad", "brush.mixer.autoClean", "brush.mixer.sampleAllLayers"]); let specs = crate::command_specs(); let labels: Vec<&str> = MIXER_BRUSH_COMMANDS.iter().map(|id| specs.iter().find(|c| c.id == *id).unwrap_or_else(|| panic!("{id}")).label).collect(); @@ -58,7 +59,7 @@ fn keyboard_shortcuts_list_the_five_without_keys_and_can_assign_one() { for id in MIXER_BRUSH_COMMANDS { assert_eq!(specs.iter().find(|c| c.id == id).unwrap().shortcut, None, "{id} has no default key"); } - let mut s = Session::new(); + let mut s = crate::session(); let out = s.execute("edit.keyboardShortcuts", json!({"set": {"brush.mixer.autoClean": "F9"}, "list": true})).unwrap(); let row = |id: &str| out["commands"].as_array().unwrap().iter().find(|c| c["id"] == id).cloned().unwrap_or(Value::Null); assert_eq!(row("brush.mixer.autoClean")["shortcut"], "F9"); @@ -72,7 +73,7 @@ fn keyboard_shortcuts_list_the_five_without_keys_and_can_assign_one() { /// the last-brush persistence watches (CodeRabbit review on brush_cmds.rs:825). #[test] fn each_switch_marks_the_brush_changed_so_it_is_saved() { - let mut s = Session::new(); + let mut s = crate::session(); for (id, _) in SWITCHES { let rev = s.tools.brush_rev; s.execute(id, json!({})).unwrap(); diff --git a/crates/engine/src/new_layer.rs b/crates/engine-core/src/new_layer.rs similarity index 99% rename from crates/engine/src/new_layer.rs rename to crates/engine-core/src/new_layer.rs index ed05e24c8e..8704e733b1 100644 --- a/crates/engine/src/new_layer.rs +++ b/crates/engine-core/src/new_layer.rs @@ -113,7 +113,7 @@ mod tests { /// A document with a busy Background: every pixel a different colour. fn busy(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32, "mode": mode, "depth": depth})).unwrap(); s.edit("busy", |doc, active| { let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap(); diff --git a/crates/engine/src/param_check.rs b/crates/engine-core/src/param_check.rs similarity index 98% rename from crates/engine/src/param_check.rs rename to crates/engine-core/src/param_check.rs index a59236d1d1..cfba2cadbb 100644 --- a/crates/engine/src/param_check.rs +++ b/crates/engine-core/src/param_check.rs @@ -115,6 +115,7 @@ mod tests { #[test] fn strict_commands_have_closed_docs() { + crate::install().unwrap(); for id in STRICT { let spec = crate::commands::find(id).expect("strict command exists"); assert!(documented_keys(spec.params).is_some_and(|k| !k.is_empty()), "{id}: params doc must list its keys"); @@ -123,7 +124,7 @@ mod tests { #[test] fn unknown_param_is_an_error_naming_the_key_and_the_accepted_ones() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); let a = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); let visible = |s: &Session| s.active().unwrap().doc.layer(photocraft_doc::LayerId(a)).unwrap().visible; diff --git a/crates/engine/src/pattern_mode_tests.rs b/crates/engine-core/src/pattern_mode_tests.rs similarity index 98% rename from crates/engine/src/pattern_mode_tests.rs rename to crates/engine-core/src/pattern_mode_tests.rs index e917cd9ccf..ccb26f0a73 100644 --- a/crates/engine/src/pattern_mode_tests.rs +++ b/crates/engine-core/src/pattern_mode_tests.rs @@ -52,7 +52,7 @@ fn pattern_mode(s: &Session) -> ColorMode { fn pattern_fills_paint_like_edit_fill_in_every_mode() { for (mode, cm) in [("gray", ColorMode::Grayscale), ("cmyk", ColorMode::Cmyk), ("lab", ColorMode::Lab), ("rgb", ColorMode::Rgb)] { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); let pat = colour_pattern(&mut s); let want = painted(&mut s, mode, depth, &pat); s.execute("file.new", json!({"width": 32, "height": 16, "mode": mode, "depth": depth, "background": "white"})).unwrap(); @@ -74,7 +74,7 @@ fn pattern_fills_paint_like_edit_fill_in_every_mode() { #[test] fn a_grayscale_round_trip_keeps_the_pattern_colours() { for depth in [8, 16] { - let mut s = Session::new(); + let mut s = crate::session(); let pat = colour_pattern(&mut s); s.execute("file.new", json!({"width": 32, "height": 16, "mode": "rgb", "depth": depth, "background": "white"})).unwrap(); s.execute("layer.newFillLayer.pattern", json!({"pattern": pat})).unwrap(); diff --git a/crates/engine/src/pencil_auto_erase_exact_tests.rs b/crates/engine-core/src/pencil_auto_erase_exact_tests.rs similarity index 98% rename from crates/engine/src/pencil_auto_erase_exact_tests.rs rename to crates/engine-core/src/pencil_auto_erase_exact_tests.rs index 7588c0c38a..b740bcec00 100644 --- a/crates/engine/src/pencil_auto_erase_exact_tests.rs +++ b/crates/engine-core/src/pencil_auto_erase_exact_tests.rs @@ -11,7 +11,7 @@ const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0]; /// A document of `depth` bits with a pixel layer filled with `fill`, the background colour white. fn session(depth: u32, fill: [f32; 4]) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 24, "height": 24, "depth": depth, "background": "white"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": fill})).unwrap(); diff --git a/crates/engine/src/pixels.rs b/crates/engine-core/src/pixels.rs similarity index 100% rename from crates/engine/src/pixels.rs rename to crates/engine-core/src/pixels.rs diff --git a/crates/engine/src/pixels/flatten_cmyk_tests.rs b/crates/engine-core/src/pixels/flatten_cmyk_tests.rs similarity index 99% rename from crates/engine/src/pixels/flatten_cmyk_tests.rs rename to crates/engine-core/src/pixels/flatten_cmyk_tests.rs index 6470f7dea4..b4c2d08f99 100644 --- a/crates/engine/src/pixels/flatten_cmyk_tests.rs +++ b/crates/engine-core/src/pixels/flatten_cmyk_tests.rs @@ -54,7 +54,7 @@ fn upper_layer() -> Layer { } fn session(doc: Document) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.add_document(doc, None); s } diff --git a/crates/engine/src/pixels/tests.rs b/crates/engine-core/src/pixels/tests.rs similarity index 99% rename from crates/engine/src/pixels/tests.rs rename to crates/engine-core/src/pixels/tests.rs index 03efb8cb2c..0b3999fa56 100644 --- a/crates/engine/src/pixels/tests.rs +++ b/crates/engine-core/src/pixels/tests.rs @@ -239,7 +239,7 @@ fn clear_leaves_unselected_tiles_shared_and_drops_cleared_ones() { #[ignore = "benchmark; run with --release -- --ignored --nocapture"] fn benchmark_clear_large_selection() { for (background, feather) in [(false, 0), (false, 200), (true, 0), (true, 200)] { - let mut s = crate::Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8000, "height": 6000, "background": "white"})).unwrap(); if !background { s.execute("layer.new.layer", json!({})).unwrap(); diff --git a/crates/engine/src/prefs.rs b/crates/engine-core/src/prefs.rs similarity index 99% rename from crates/engine/src/prefs.rs rename to crates/engine-core/src/prefs.rs index 4bdaf390f3..137ca478b5 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine-core/src/prefs.rs @@ -2147,12 +2147,11 @@ mod tests; #[cfg(test)] mod color_settings_path_tests { - use crate::Session; use serde_json::json; #[test] fn a_path_that_only_starts_with_color_settings_is_not_in_that_section() { - let mut s = Session::new(); + let mut s = crate::session(); let before = s.color.settings.clone(); for path in ["colorSettingsworkingRgb", "colorSettings.", "colorSettings..workingRgb"] { assert!(s.execute("prefs.set", json!({"path": path, "value": "/dev/zero"})).is_err(), "{path}"); diff --git a/crates/engine/src/prefs/cmds.rs b/crates/engine-core/src/prefs/cmds.rs similarity index 100% rename from crates/engine/src/prefs/cmds.rs rename to crates/engine-core/src/prefs/cmds.rs diff --git a/crates/engine/src/prefs/customize.rs b/crates/engine-core/src/prefs/customize.rs similarity index 100% rename from crates/engine/src/prefs/customize.rs rename to crates/engine-core/src/prefs/customize.rs diff --git a/crates/engine/src/prefs/files.rs b/crates/engine-core/src/prefs/files.rs similarity index 100% rename from crates/engine/src/prefs/files.rs rename to crates/engine-core/src/prefs/files.rs diff --git a/crates/engine/src/prefs/menus_hideable_tests.rs b/crates/engine-core/src/prefs/menus_hideable_tests.rs similarity index 94% rename from crates/engine/src/prefs/menus_hideable_tests.rs rename to crates/engine-core/src/prefs/menus_hideable_tests.rs index 8c378053c6..3c9fdadb35 100644 --- a/crates/engine/src/prefs/menus_hideable_tests.rs +++ b/crates/engine-core/src/prefs/menus_hideable_tests.rs @@ -6,7 +6,6 @@ use serde_json::json; use super::MenuCustomization; -use crate::Session; const NOT_HIDEABLE: [&str; 7] = ["file.clearRecent", "file.close", "file.save", "file.saveAs", "file.saveACopy", "file.exit", "edit.menus"]; @@ -18,7 +17,7 @@ const HIDEABLE: [&str; 6] = fn file_close_save_items_and_edit_menus_cannot_be_hidden() { for id in NOT_HIDEABLE { assert!(!MenuCustomization::hideable(id), "{id}"); - let mut s = Session::new(); + let mut s = crate::session(); let err = s.execute("edit.menus", json!({"hide": [id]})).unwrap_err().to_string(); assert!(err.contains("can't be hidden") && err.contains(id), "{id}: {err}"); assert!(s.prefs().menus.hidden.is_empty(), "{id}: nothing stored"); @@ -27,7 +26,7 @@ fn file_close_save_items_and_edit_menus_cannot_be_hidden() { #[test] fn keyboard_shortcuts_preferences_and_help_can_be_hidden() { - let mut s = Session::new(); + let mut s = crate::session(); for id in HIDEABLE { assert!(MenuCustomization::hideable(id), "{id}"); } @@ -41,7 +40,7 @@ fn keyboard_shortcuts_preferences_and_help_can_be_hidden() { #[test] fn an_older_preferences_file_listing_them_leaves_them_shown() { - let mut s = Session::new(); + let mut s = crate::session(); let hidden: Vec<&str> = NOT_HIDEABLE.iter().copied().chain(["edit.fade"]).collect(); s.execute("prefs.set", json!({"values": {"menus": {"hidden": hidden, "colors": {}}}})).unwrap(); for id in NOT_HIDEABLE { @@ -52,7 +51,7 @@ fn an_older_preferences_file_listing_them_leaves_them_shown() { #[test] fn items_that_cannot_be_hidden_can_still_be_coloured() { - let mut s = Session::new(); + let mut s = crate::session(); let colors: serde_json::Map = NOT_HIDEABLE.iter().map(|id| (id.to_string(), json!("blue"))).collect(); s.execute("edit.menus", json!({"color": colors})).unwrap(); for id in NOT_HIDEABLE { diff --git a/crates/engine/src/prefs/shortcuts.rs b/crates/engine-core/src/prefs/shortcuts.rs similarity index 100% rename from crates/engine/src/prefs/shortcuts.rs rename to crates/engine-core/src/prefs/shortcuts.rs diff --git a/crates/engine/src/prefs/store.rs b/crates/engine-core/src/prefs/store.rs similarity index 100% rename from crates/engine/src/prefs/store.rs rename to crates/engine-core/src/prefs/store.rs diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine-core/src/prefs/tests.rs similarity index 97% rename from crates/engine/src/prefs/tests.rs rename to crates/engine-core/src/prefs/tests.rs index 922de41f08..9eada16482 100644 --- a/crates/engine/src/prefs/tests.rs +++ b/crates/engine-core/src/prefs/tests.rs @@ -17,7 +17,7 @@ fn system_title_bar_defaults_to_integrated_and_preserves_saved_choices() { } fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s } @@ -40,11 +40,11 @@ fn defaults_match_photoshop() { #[test] fn intermediate_ui_scale_presets_survive_restart() { - let mut s = Session::new(); + let mut s = crate::session(); assert_eq!(s.execute("prefs.get", json!({"path": "interface.uiScale"})).unwrap(), json!("auto")); for scale in ["100", "105", "110", "115", "120", "125"] { s.execute("prefs.set", json!({"path": "interface.uiScale", "value": scale})).unwrap(); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(restored.execute("prefs.get", json!({"path": "interface.uiScale"})).unwrap(), json!(scale)); } @@ -56,7 +56,7 @@ fn intermediate_ui_scale_presets_survive_restart() { /// #2264: the Studio workspace dot pattern can be hidden without changing themes. #[test] fn canvas_dot_grid_can_be_disabled_persisted_and_reset() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.prefs().interface.show_canvas_dots, "existing Studio appearance stays unchanged by default"); assert_eq!(s.execute("prefs.get", json!({"path": "interface.showCanvasDots"})).unwrap(), json!(true)); @@ -64,12 +64,12 @@ fn canvas_dot_grid_can_be_disabled_persisted_and_reset() { assert!(!s.prefs().interface.show_canvas_dots); assert_eq!(s.execute("prefs.get", json!({"path": "interface.showCanvasDots"})).unwrap(), json!(false)); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&s.prefs_to_json()).unwrap(); assert!(!restored.prefs().interface.show_canvas_dots, "disabling the pattern must survive restart"); // Older preference files without the new key retain the original dotted workspace. - let mut legacy = Session::new(); + let mut legacy = crate::session(); legacy.load_prefs_json(r#"{"interface": {"theme": "studio"}}"#).unwrap(); assert!(legacy.prefs().interface.show_canvas_dots); @@ -83,14 +83,14 @@ fn canvas_dot_grid_can_be_disabled_persisted_and_reset() { /// UI-217-10: the Home screen's recent-files list can be switched off and the choice persists. #[test] fn home_recent_files_preference_defaults_on_persists_and_resets() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.prefs().interface.show_home_recent_files); s.execute("prefs.set", json!({"path": "interface.showHomeRecentFiles", "value": false})).unwrap(); assert!(!s.prefs().interface.show_home_recent_files); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&s.prefs_to_json()).unwrap(); assert!(!restored.prefs().interface.show_home_recent_files); - let mut legacy = Session::new(); + let mut legacy = crate::session(); legacy.load_prefs_json(r#"{"interface": {"theme": "studio"}}"#).unwrap(); assert!(legacy.prefs().interface.show_home_recent_files); assert!(s.execute("prefs.set", json!({"path": "interface.showHomeRecentFiles", "value": 3})).is_err()); @@ -108,7 +108,7 @@ fn appearance_defaults_and_legacy_theme_migrate() { for (theme, mode, dark, light) in [("pro", AppearanceMode::Dark, "craft.pro", "craft.pro"), ("classic", AppearanceMode::Light, "craft.artcraft", "craft.classic")] { - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&json!({"interface": {"theme": theme}}).to_string()).unwrap(); assert_eq!(s.prefs().interface.appearance_mode, mode); assert_eq!(s.prefs().interface.dark_theme, dark); @@ -122,14 +122,14 @@ fn appearance_defaults_and_legacy_theme_migrate() { #[test] fn a_saved_serbian_language_migrates_to_sr_latn() { for saved in ["sr", "SR"] { - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&json!({"interface": {"language": saved}}).to_string()).unwrap(); assert_eq!(s.prefs().interface.language, "sr-latn", "{saved}"); let resaved: Value = serde_json::from_str(&s.prefs_to_json()).unwrap(); assert_eq!(resaved["interface"]["language"], "sr-latn", "saved under the new code"); } for kept in ["sr-latn", "bs", "auto", "en"] { - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&json!({"interface": {"language": kept}}).to_string()).unwrap(); assert_eq!(s.prefs().interface.language, kept); } @@ -142,7 +142,7 @@ fn legacy_theme_migration_preserves_saved_theme_slots() { { let mut interface = json!({"theme": legacy}); interface[slot] = json!(saved); - let mut session = Session::new(); + let mut session = crate::session(); session.load_prefs_json(&json!({"interface": interface}).to_string()).unwrap(); assert_eq!(session.prefs_value()["interface"][slot], id, "explicit {slot} survives migration"); } @@ -150,13 +150,13 @@ fn legacy_theme_migration_preserves_saved_theme_slots() { #[test] fn appearance_choices_validate_and_legacy_theme_still_selects() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("prefs.set", json!({"values": {"interface.appearanceMode": "auto", "interface.darkTheme": "studio", "interface.lightTheme": "classic"}})) .unwrap(); assert_eq!(s.prefs().interface.appearance_mode, AppearanceMode::Auto); assert_eq!(s.prefs().interface.dark_theme, "craft.studio"); assert_eq!(s.prefs().interface.light_theme, "craft.classic"); - let mut restarted = Session::new(); + let mut restarted = crate::session(); restarted.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(restarted.prefs().interface, s.prefs().interface); assert!(s.execute("prefs.set", json!({"path": "interface.darkTheme", "value": ""})).is_err()); @@ -174,7 +174,7 @@ fn appearance_choices_validate_and_legacy_theme_still_selects() { assert_eq!(s.prefs().interface.appearance_mode, AppearanceMode::Light); assert_eq!(s.prefs().interface.light_theme, light); s.execute("prefs.set", json!({"path": "interface.lightTheme", "value": theme})).unwrap(); - let mut migrated = Session::new(); + let mut migrated = crate::session(); migrated.load_prefs_json(&json!({"interface": {"theme": theme}}).to_string()).unwrap(); assert_eq!(migrated.prefs().interface.appearance_mode, AppearanceMode::Light); assert_eq!(migrated.prefs().interface.light_theme, light); @@ -186,7 +186,7 @@ fn appearance_choices_validate_and_legacy_theme_still_selects() { /// shows. #[test] fn pre_id_theme_names_read_as_ids_where_they_were_saved() { - let mut s = Session::new(); + let mut s = crate::session(); let saved = json!({ "interface": {"appearanceMode": "dark", "darkTheme": "Pro (Medium Gray)", "lightTheme": "gnome", "favoriteThemes": ["breezeDark"]}, }); @@ -203,7 +203,7 @@ fn pre_id_theme_names_read_as_ids_where_they_were_saved() { /// under their old ids; other `window.workspace.*` ids read as saved. #[test] fn old_workspace_command_ids_read_as_the_workspace_set_ids() { - let mut s = Session::new(); + let mut s = crate::session(); let saved = json!({ "shortcuts": {"window.workspace.lockWorkspace": "F9", "window.workspace.motion": "F12"}, "alternateShortcuts": {"window.workspace.resetWorkspace": ["F10"]}, @@ -222,7 +222,7 @@ fn old_workspace_command_ids_read_as_the_workspace_set_ids() { #[test] fn writing_back_the_got_interface_keeps_a_slot_edit() { for root in [false, true] { - let mut s = Session::new(); + let mut s = crate::session(); let mut interface = s.execute("prefs.get", json!({"path": "interface"})).unwrap(); interface["darkTheme"] = json!("craft.breeze"); let set = if root { json!({"path": "", "value": {"interface": interface}}) } else { json!({"path": "interface", "value": interface}) }; @@ -233,12 +233,12 @@ fn writing_back_the_got_interface_keeps_a_slot_edit() { #[test] fn favorite_themes_persist_and_reject_invalid_lists() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.prefs().interface.favorite_themes.is_empty()); s.execute("prefs.set", json!({"path": "interface.favoriteThemes", "value": ["classic", "studio"]})).unwrap(); assert_eq!(s.prefs().interface.favorite_themes, vec!["craft.classic", "craft.studio"]); s.execute("prefs.set", json!({"path": "interface.theme", "value": "pro"})).unwrap(); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(restored.prefs().interface.favorite_themes, vec!["craft.classic", "craft.studio"]); for invalid in [json!("classic"), json!(["bad id"]), json!(["classic", "classic"]), json!([23])] { @@ -301,7 +301,7 @@ fn reset_one_keyed_override() { assert_eq!(s.execute("prefs.reset", json!({"path": path})).unwrap(), Value::Null); assert!(s.prefs.rev() > revision); assert!(s.execute("prefs.get", json!({"path": path})).is_err(), "removed override: {path}"); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(restored.prefs(), s.prefs(), "removal survives saving: {path}"); } @@ -399,13 +399,13 @@ fn json_round_trip_tolerates_unknown_and_missing_keys() { .unwrap(); s.execute("edit.colorSettings", json!({"workingRgb": "display-p3", "policyRgb": "convert"})).unwrap(); let text = s.prefs_to_json(); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&text).unwrap(); assert_eq!(t.prefs(), s.prefs()); assert_eq!(t.color.settings.working_rgb, "display-p3"); assert_eq!(t.color.settings.policy_rgb, crate::color_cmds::Policy::Convert); // Older/newer files: unknown keys ignored, missing ones default. - let mut u = Session::new(); + let mut u = crate::session(); u.load_prefs_json(r#"{"general": {"beepWhenDone": true, "futureThing": 1}, "someNewSection": {}}"#).unwrap(); assert!(u.prefs().general.beep_when_done); assert_eq!(u.prefs().performance.history_states, 50); @@ -415,12 +415,12 @@ fn json_round_trip_tolerates_unknown_and_missing_keys() { #[test] fn low_resolution_previews_default_on_and_switch_off() { // A preferences file from before the setting keeps the fast previews. - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(r#"{"performance": {"historyStates": 20}}"#).unwrap(); assert!(s.prefs().performance.low_resolution_previews); s.execute("prefs.set", json!({"path": "performance.lowResolutionPreviews", "value": false})).unwrap(); assert!(!s.prefs().performance.low_resolution_previews); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&s.prefs_to_json()).unwrap(); assert!(!t.prefs().performance.low_resolution_previews); } @@ -526,7 +526,7 @@ fn menus_and_toolbar_customisation_persist() { /// hidden tools. #[test] fn an_old_toolbar_order_key_loads_with_the_default_layout() { - let mut old = Session::new(); + let mut old = crate::session(); let invalid = old.load_prefs_json(&json!({"toolbar": {"hidden": ["Sponge"], "order": ["Move", "Brush"]}}).to_string()).unwrap(); assert!(invalid.is_empty(), "{invalid:?}"); assert_eq!(old.prefs().toolbar.toolbar, None); @@ -550,7 +550,7 @@ fn menus_refuse_to_hide_essential_items() { #[test] fn preference_sections_are_commands() { - let mut s = Session::new(); + let mut s = crate::session(); for (id, title) in SECTIONS { let r = s.execute(&format!("edit.preferences.{id}"), json!({})).unwrap(); assert_eq!(r["section"], id); @@ -635,10 +635,10 @@ fn gpu_adapter_round_trips_and_defaults_to_automatic() { assert_eq!(s.prefs().performance.gpu_adapter, "NVIDIA"); assert!(s.execute("prefs.set", json!({"path": "performance.gpuAdapter", "value": 3})).is_err()); assert_eq!(s.prefs().performance.gpu_adapter, "NVIDIA"); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&s.prefs_to_json()).unwrap(); assert_eq!(t.prefs().performance.gpu_adapter, "NVIDIA"); - let mut u = Session::new(); + let mut u = crate::session(); u.load_prefs_json(r#"{"performance": {"useGpu": true}}"#).unwrap(); assert_eq!(u.prefs().performance.gpu_adapter, ""); } @@ -666,11 +666,11 @@ fn gpu_backend_round_trips_and_validates() { assert_eq!(s.prefs().performance.gpu_backend, GpuBackend::Dx12); // Persisted and restored with the rest of the preferences. let text = s.prefs_to_json(); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&text).unwrap(); assert_eq!(t.prefs().performance.gpu_backend, GpuBackend::Dx12); // Files from before the setting load as `auto`. - let mut u = Session::new(); + let mut u = crate::session(); u.load_prefs_json(r#"{"performance": {"useGpu": true}}"#).unwrap(); assert_eq!(u.prefs().performance.gpu_backend, GpuBackend::Auto); assert_eq!(choices("performance.gpuBackend"), Some(GpuBackend::NAMES)); @@ -687,7 +687,7 @@ fn notification_autohide_preferences() { assert_eq!(p.interface.notification_duration_seconds, 6); assert_eq!(range("interface.notificationDurationSeconds"), Some((1.0, 120.0))); - let mut s = Session::new(); + let mut s = crate::session(); s.execute("prefs.set", json!({"path": "interface.notificationAutoHide", "value": false})).unwrap(); s.execute("prefs.set", json!({"path": "interface.notificationDurationSeconds", "value": 30})).unwrap(); assert!(!s.prefs().interface.notification_auto_hide); @@ -698,12 +698,12 @@ fn notification_autohide_preferences() { } assert_eq!(s.prefs().interface.notification_duration_seconds, 30); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&s.prefs_to_json()).unwrap(); assert!(!t.prefs().interface.notification_auto_hide); assert_eq!(t.prefs().interface.notification_duration_seconds, 30); // Older files without the settings keep the defaults. - let mut u = Session::new(); + let mut u = crate::session(); u.load_prefs_json(r#"{"interface": {"theme": "studio"}}"#).unwrap(); assert!(u.prefs().interface.notification_auto_hide); assert_eq!(u.prefs().interface.notification_duration_seconds, 6); @@ -853,6 +853,7 @@ fn nudge_bundling_preferences() { /// alternates, beside the main key its menu shows. #[test] fn commands_have_photoshops_alternate_keys() { + crate::install().unwrap(); let p = Preferences::default(); let main = |id: &str| crate::commands::find(id).and_then(|c| c.shortcut); assert_eq!(main("edit.cut"), Some("Cmd+X")); @@ -997,18 +998,18 @@ fn old_settings_files_take_the_shift_key_tool_switch_default() { for old in [json!({"tools": {"useShiftKeyForToolSwitch": false}}), json!({"version": 1, "tools": {"useShiftKeyForToolSwitch": false, "showTooltips": false}})] { - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&old.to_string()).unwrap(); assert!(s.prefs().tools.use_shift_key_for_tool_switch, "{old}"); } - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(&json!({"version": 1, "tools": {"showTooltips": false}}).to_string()).unwrap(); assert!(!s.prefs().tools.show_tooltips, "other tool settings are kept"); // Chosen off and saved now: kept on the next start. s.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = false); let saved = s.prefs_to_json(); assert_eq!(serde_json::from_str::(&saved).unwrap()["version"], json!(PREFS_VERSION)); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_prefs_json(&saved).unwrap(); assert!(!restored.prefs().tools.use_shift_key_for_tool_switch); } @@ -1104,7 +1105,7 @@ fn a_stranded_backup_is_named_in_the_error() { #[test] fn a_wrongly_typed_value_resets_only_that_field() { // #6611: one bad value used to reset every preference. - let mut s = Session::new(); + let mut s = crate::session(); let invalid = s .load_prefs_json( r#"{"general": {"beepWhenDone": true}, "fileHandling": {"recentFileCount": "ten", "autosaveMinutes": 5}, @@ -1127,7 +1128,7 @@ fn a_wrongly_typed_value_resets_only_that_field() { fn the_removed_enable_animations_preference_still_loads_and_is_unknown() { // #9479: Interface › Enable animations is gone (Photoshop has no such setting). Files saved // with it still load whole, without a reported bad value, and the key isn't written back. - let mut s = Session::new(); + let mut s = crate::session(); let invalid = s.load_prefs_json(r#"{"version": 2, "interface": {"enableAnimations": false, "showTooltips": false}, "performance": {"historyStates": 20}}"#).unwrap(); assert!(invalid.is_empty(), "{invalid:?}"); @@ -1144,7 +1145,7 @@ fn the_removed_enable_animations_preference_still_loads_and_is_unknown() { #[test] fn a_wrongly_typed_section_or_colour_setting_resets_only_that_part() { - let mut s = Session::new(); + let mut s = crate::session(); let invalid = s .load_prefs_json( r#"{"general": "loud", "performance": {"historyStates": 20}, @@ -1177,7 +1178,7 @@ fn the_history_budget_is_the_stored_memory_usage_on_native() { assert_eq!(p.effective_memory_usage_mb(), mb); assert_eq!(p.history_budget_bytes(), (mb as usize) << 20, "{mb} MB"); } - let mut s = Session::new(); + let mut s = crate::session(); s.load_prefs_json(r#"{"performance": {"memoryUsageMb": 8192}}"#).unwrap(); assert_eq!(s.prefs().performance.memory_usage_mb, 8192); assert_eq!(s.prefs().performance.history_budget_bytes(), 8192 << 20); @@ -1288,7 +1289,7 @@ fn an_effect_cache_above_the_cap_loads_clamped_and_does_not_block_apply() { #[test] fn a_saved_control_port_turns_the_agent_connection_on() { let load = |text: &str| { - let mut session = Session::new(); + let mut session = crate::session(); session.load_prefs_json(text).unwrap(); session.prefs().integrations.clone() }; diff --git a/crates/engine/src/prefs/theme_ids.rs b/crates/engine-core/src/prefs/theme_ids.rs similarity index 100% rename from crates/engine/src/prefs/theme_ids.rs rename to crates/engine-core/src/prefs/theme_ids.rs diff --git a/crates/engine/src/prefs/validate.rs b/crates/engine-core/src/prefs/validate.rs similarity index 100% rename from crates/engine/src/prefs/validate.rs rename to crates/engine-core/src/prefs/validate.rs diff --git a/crates/engine/src/preset_store.rs b/crates/engine-core/src/preset_store.rs similarity index 100% rename from crates/engine/src/preset_store.rs rename to crates/engine-core/src/preset_store.rs diff --git a/crates/engine/src/preset_store/patterns.rs b/crates/engine-core/src/preset_store/patterns.rs similarity index 100% rename from crates/engine/src/preset_store/patterns.rs rename to crates/engine-core/src/preset_store/patterns.rs diff --git a/crates/engine/src/preset_store/tests.rs b/crates/engine-core/src/preset_store/tests.rs similarity index 98% rename from crates/engine/src/preset_store/tests.rs rename to crates/engine-core/src/preset_store/tests.rs index 1fadbcadb2..a51638bfe9 100644 --- a/crates/engine/src/preset_store/tests.rs +++ b/crates/engine-core/src/preset_store/tests.rs @@ -29,7 +29,7 @@ impl Drop for TempDir { /// A session with the store in `dir` attached. fn session(dir: &TempDir) -> (Session, Vec) { - let mut s = Session::new(); + let mut s = crate::session(); let w = s.attach_preset_store(open_dir(&dir.0)); (s, w) } @@ -76,7 +76,7 @@ fn saved_airbrush_group_keeps_legacy_and_explicit_rates_across_reopen() { ]}); mem.write(&group_file_name("Airbrush"), &serde_json::to_vec(&group).unwrap()).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let warnings = s.attach_preset_store(open(Box::new(mem.clone()))); assert!(warnings.is_empty(), "{warnings:?}"); assert_eq!(s.tools.brush.build_up_rate, 10.0); @@ -87,7 +87,7 @@ fn saved_airbrush_group_keeps_legacy_and_explicit_rates_across_reopen() { } s.execute("brush.presets.save", json!({"name": "Resaved Airbrush"})).unwrap(); - let mut reopened = Session::new(); + let mut reopened = crate::session(); assert!(reopened.attach_preset_store(open(Box::new(mem))).is_empty()); reopened.execute("tools.setBrush", json!({"preset": "Resaved Airbrush"})).unwrap(); assert_eq!(reopened.tools.brush.build_up_rate, 20.0); @@ -95,7 +95,7 @@ fn saved_airbrush_group_keeps_legacy_and_explicit_rates_across_reopen() { #[test] fn sessions_have_no_store_by_default() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.preset_store.is_none(), "headless sessions must stay hermetic"); s.execute("brush.presets.save", json!({"name": "Mine"})).unwrap(); assert!(s.preset_store.is_none()); @@ -395,7 +395,7 @@ fn write_failures_are_warnings() { let dir = TempDir::new("readonly"); // The store "directory" is a file: every write fails. std::fs::write(&dir.0, b"not a dir").unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open_dir(&dir.0)); s.tools.brush.tip = TipShape::Sampled(tip8(4, 4, 0)).into(); s.execute("brush.presets.save", json!({"name": "Nope"})).unwrap(); @@ -465,7 +465,7 @@ fn a_store_directory_that_does_not_exist_yet_opens_without_warnings() { /// group), synced; plus the backend to reopen it. fn library(n: u32, side: u32) -> (Session, MemBackend) { let mem = MemBackend::default(); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(mem.clone()))); for i in 0..n { std::sync::Arc::make_mut(&mut *s.tools.presets).push(sampled(&format!("Big {i}"), "Big Set", tip8(side, side, i))); @@ -503,7 +503,7 @@ fn reopening_a_library_decodes_no_tips_and_using_a_brush_decodes_only_its_own() drop(s); // A restart: nothing is decoded at full size. - let mut t = Session::new(); + let mut t = crate::session(); let w = t.attach_preset_store(open(Box::new(mem.clone()))); assert!(w.is_empty(), "{w:?}"); assert_eq!(mem.list().unwrap(), files, "attaching an unchanged store rewrites nothing"); @@ -538,7 +538,7 @@ fn reopening_a_library_decodes_no_tips_and_using_a_brush_decodes_only_its_own() fn the_decoded_tip_cache_stays_within_its_budget() { let (s, mem) = library(6, 256); drop(s); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(open(Box::new(mem))); let one = 256 * 256 * 2; t.preset_store.as_ref().unwrap().set_tip_cache_limit(one * 2 + 1); @@ -567,7 +567,7 @@ fn the_decoded_tip_cache_stays_within_its_budget() { fn a_brush_edit_keeps_a_stored_tip_that_loads_only_now() { let (s, mem) = library(1, 64); drop(s); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(open(Box::new(mem))); t.execute("tools.setBrush", json!({"preset": "Big 0"})).unwrap(); if let TipShape::Stored(r) = &mut *t.tools.brush.tip { @@ -586,7 +586,7 @@ fn a_brush_edit_keeps_a_stored_tip_that_loads_only_now() { fn missing_corrupt_or_unknown_tips_fail_when_used_without_panicking() { let (s, mem) = library(3, 64); drop(s); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(open(Box::new(mem.clone()))); t.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); let key = |t: &Session, name: &str| match &*photocraft_paint::presets::find(&t.tools.presets, name).unwrap().brush.tip { @@ -625,7 +625,7 @@ fn missing_corrupt_or_unknown_tips_fail_when_used_without_panicking() { let stray = json!({"tip": {"stored": {"key": "../../etc/passwd", "width": 4, "height": 4, "preview": {"width": 1, "height": 1, "data": [1.0]}}}}); assert!(t.execute("tools.setBrush", json!({"brush": stray})).is_err()); - let mut headless = Session::new(); + let mut headless = crate::session(); assert!(headless.execute("tools.setBrush", json!({"brush": stray})).is_err()); assert!(headless.execute("brush.presets.list", json!({"full": true})).is_ok()); } @@ -646,7 +646,7 @@ fn a_store_without_previews_makes_them_once_and_then_loads_lazily() { let file = group_file_name("Old"); mem.write(&file, &serde_json::to_vec(&group).unwrap()).unwrap(); - let mut s = Session::new(); + let mut s = crate::session(); let w = s.attach_preset_store(open(Box::new(mem.clone()))); assert!(w.is_empty(), "{w:?}"); let a = photocraft_paint::presets::find(&s.tools.presets, "Old A").unwrap().clone(); @@ -658,7 +658,7 @@ fn a_store_without_previews_makes_them_once_and_then_loads_lazily() { assert_eq!(rewritten["presets"][0]["brush"]["size"], 30.0); // The next start reads previews only and changes nothing. let files = mem.list().unwrap(); - let mut t = Session::new(); + let mut t = crate::session(); assert!(t.attach_preset_store(open(Box::new(mem.clone()))).is_empty()); assert_eq!(mem.list().unwrap(), files); assert_eq!(user(&t), user(&s)); @@ -712,7 +712,7 @@ fn imported_abr_folders_persist_and_old_stores_load_flat() { let file = group_file_name("Old"); mem.write(&file, &serde_json::to_vec(&old).unwrap()).unwrap(); let before = mem.read(&file, MAX_GROUP_BYTES).unwrap(); - let mut o = Session::new(); + let mut o = crate::session(); assert!(o.attach_preset_store(open(Box::new(mem.clone()))).is_empty()); let p = photocraft_paint::presets::find(&o.tools.presets, "Plain").unwrap(); assert!(p.group == "Old" && p.folder.is_empty()); @@ -723,7 +723,7 @@ fn imported_abr_folders_persist_and_old_stores_load_flat() { {"name": "Blank", "brush": {}, "folder": ["", " "]}, ]}); mem.write(&group_file_name("Deep"), &serde_json::to_vec(&deep).unwrap()).unwrap(); - let mut d = Session::new(); + let mut d = crate::session(); d.attach_preset_store(open(Box::new(mem.clone()))); assert_eq!(photocraft_paint::presets::find(&d.tools.presets, "Deep").unwrap().folder.len(), crate::brush_preset_cmds::MAX_FOLDER_DEPTH); assert!(photocraft_paint::presets::find(&d.tools.presets, "Blank").unwrap().folder.is_empty()); @@ -770,7 +770,7 @@ fn a_group_file_that_failed_to_load_is_not_overwritten() { let file = group_file_name(""); let newer = br#"{"format":"photocraft-brush-group","version":2,"group":"","presets":[]}"#.to_vec(); mem.files.lock().unwrap().insert(file.clone(), newer.clone()); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(mem.clone()))); s.tools.brush.tip = TipShape::Sampled(tip8(4, 4, 0)).into(); s.execute("brush.presets.save", json!({"name": "New"})).unwrap(); @@ -784,7 +784,7 @@ fn an_actions_file_that_failed_to_load_is_not_overwritten() { let mem = MemBackend::default(); let newer = br#"{"version":2,"actions":[{"name":"Keep","steps":[]}]}"#.to_vec(); mem.files.lock().unwrap().insert(ACTIONS_FILE.into(), newer.clone()); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(mem.clone()))); s.execute("actions.record", json!({"name": "New"})).unwrap(); s.execute("actions.stop", json!({})).unwrap(); @@ -807,7 +807,7 @@ fn stored_action_ids_move_to_names_on_load() { {{"name":"Caller","steps":[["actions.play",{{"action":"Same","actionId":"{id}"}}]]}}]}}"# ); mem.files.lock().unwrap().insert(ACTIONS_FILE.into(), file.into_bytes()); - let mut s = Session::new(); + let mut s = crate::session(); s.edit_prefs(|prefs| { prefs.shortcuts.insert(format!("actions.playById:{id}"), "F6".into()); }); @@ -949,7 +949,7 @@ fn user_patterns(s: &Session) -> Vec<(String, u32)> { #[test] fn user_patterns_survive_a_restart() { let dir = TempDir::new("patterns"); - let builtin = Session::new().patterns.items.len(); + let builtin = crate::session().patterns.items.len(); let (mut s, w) = session(&dir); assert!(w.is_empty(), "{w:?}"); s.execute("file.new", json!({"width": 12, "height": 10})).unwrap(); @@ -993,7 +993,7 @@ fn a_patterns_file_that_failed_to_load_is_not_overwritten() { let mem = MemBackend::default(); let unreadable = b"not a pattern file".to_vec(); mem.files.lock().unwrap().insert(PATTERNS_FILE.into(), unreadable.clone()); - let mut s = Session::new(); + let mut s = crate::session(); let w = s.attach_preset_store(open(Box::new(mem.clone()))); assert!(w.iter().any(|w| w.contains(PATTERNS_FILE)), "{w:?}"); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); @@ -1019,14 +1019,14 @@ fn pat_bytes(id: &str, rgba: [f32; 4]) -> String { #[test] fn a_same_id_pattern_replacement_survives_a_restart() { let mem = MemBackend::default(); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(mem.clone()))); let id = "6f1c2c1e-0000-4000-8000-000000009318"; s.execute("pattern.import", json!({"data": pat_bytes(id, [1.0, 0.0, 0.0, 1.0])})).unwrap(); s.sync_preset_store(); s.execute("pattern.import", json!({"data": pat_bytes(id, [0.0, 0.0, 1.0, 1.0])})).unwrap(); s.sync_preset_store(); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(open(Box::new(mem.clone()))); let back = t.patterns.items.iter().find(|p| p.id == id).expect("the pattern is back"); let want = s.patterns.items.iter().find(|p| p.id == id).unwrap(); @@ -1063,7 +1063,7 @@ impl PresetBackend for FlakyRemove { #[test] fn a_failed_patterns_removal_is_retried() { let backend = FlakyRemove::default(); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(backend.clone()))); s.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); let id = s.execute("edit.definePattern", json!({"name": "Gone"})).unwrap()["pattern"].as_str().unwrap().to_string(); @@ -1090,7 +1090,7 @@ fn a_failed_patterns_removal_is_retried() { #[test] fn an_imported_builtin_replacement_survives_a_restart() { let mem = MemBackend::default(); - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(mem.clone()))); let builtin = s.patterns.items[0].id.clone(); s.execute("pattern.import", json!({"data": pat_bytes(&builtin, [0.9, 0.1, 0.4, 1.0])})).unwrap(); @@ -1103,7 +1103,7 @@ fn an_imported_builtin_replacement_survives_a_restart() { .map(|e| photocraft_io::pattern_map::read_pat(mem.files.lock().unwrap().get(e["file"].as_str().unwrap()).unwrap()).unwrap().remove(0)) .collect(); assert_eq!(saved.iter().map(|p| p.id.as_str()).collect::>(), [builtin.as_str()], "only the replaced built-in"); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(open(Box::new(mem.clone()))); let back: Vec<_> = t.patterns.items.iter().filter(|p| p.id == builtin).collect(); assert_eq!(back.len(), 1, "once"); @@ -1117,17 +1117,17 @@ fn an_imported_builtin_replacement_survives_a_restart() { fn an_early_same_id_import_wins_and_is_saved() { let mem = MemBackend::default(); let id = "6f1c2c1e-0000-4000-8000-00000000e4a1"; - let mut s = Session::new(); + let mut s = crate::session(); s.attach_preset_store(open(Box::new(mem.clone()))); s.execute("pattern.import", json!({"data": pat_bytes(id, [1.0, 0.0, 0.0, 1.0])})).unwrap(); s.sync_preset_store(); // Next start: the same pattern with other pixels arrives before the store is attached. - let mut t = Session::new(); + let mut t = crate::session(); t.execute("pattern.import", json!({"data": pat_bytes(id, [0.0, 1.0, 0.0, 1.0])})).unwrap(); let early = t.patterns.items.iter().find(|p| p.id == id).unwrap().surface.clone(); t.attach_preset_store(open(Box::new(mem.clone()))); t.sync_preset_store(); - let mut u = Session::new(); + let mut u = crate::session(); u.attach_preset_store(open(Box::new(mem.clone()))); assert_eq!(u.patterns.items.iter().find(|p| p.id == id).unwrap().surface, early, "the early import's pixels were saved"); } @@ -1160,19 +1160,19 @@ fn legacy_store() -> (MemBackend, Vec, String) { #[test] fn legacy_migration_commits_last_and_never_resurrects_renames_or_deletions() { let (mem, old, id) = legacy_store(); - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.attach_preset_store(open(Box::new(mem.clone()))).is_empty()); assert!(mem.read(PATTERNS_FILE, 1 << 20).is_ok()); assert_eq!(mem.read(LEGACY_PATTERNS_FILE, MAX_PATTERNS_BYTES).unwrap(), old); s.execute("pattern.rename", json!({"pattern":id,"name":"Migrated"})).unwrap(); s.sync_preset_store(); - let mut t = Session::new(); + let mut t = crate::session(); t.attach_preset_store(open(Box::new(mem.clone()))); assert_eq!(t.patterns.items.iter().find(|p| p.id == id).unwrap().name, "Migrated"); t.execute("pattern.delete", json!({"pattern":id})).unwrap(); t.sync_preset_store(); for _ in 0..2 { - let mut u = Session::new(); + let mut u = crate::session(); u.attach_preset_store(open(Box::new(mem.clone()))); assert!(!u.patterns.items.iter().any(|p| p.id == id)); } diff --git a/crates/engine/src/presets.rs b/crates/engine-core/src/presets.rs similarity index 100% rename from crates/engine/src/presets.rs rename to crates/engine-core/src/presets.rs diff --git a/crates/engine/src/presets/clone_source.rs b/crates/engine-core/src/presets/clone_source.rs similarity index 99% rename from crates/engine/src/presets/clone_source.rs rename to crates/engine-core/src/presets/clone_source.rs index 2ba36df475..cbf690ab6b 100644 --- a/crates/engine/src/presets/clone_source.rs +++ b/crates/engine-core/src/presets/clone_source.rs @@ -614,7 +614,7 @@ mod tests { #[test] fn linked_width_and_height_keep_their_ratio() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("cloneSource.set", json!({"width": 50, "height": 200})).unwrap(); s.execute("cloneSource.set", json!({"width": 100})).unwrap(); assert_eq!(s.presets.clone.active().scale, [100.0, 200.0], "unlinked: H stays"); diff --git a/crates/engine/src/presets/custom_shape_layer_name_tests.rs b/crates/engine-core/src/presets/custom_shape_layer_name_tests.rs similarity index 98% rename from crates/engine/src/presets/custom_shape_layer_name_tests.rs rename to crates/engine-core/src/presets/custom_shape_layer_name_tests.rs index a0b43b7c58..bb6fb6a68f 100644 --- a/crates/engine/src/presets/custom_shape_layer_name_tests.rs +++ b/crates/engine-core/src/presets/custom_shape_layer_name_tests.rs @@ -7,7 +7,7 @@ use crate::Session; use photocraft_doc::LayerId; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 640, "height": 480})).unwrap(); s } diff --git a/crates/engine/src/presets/gradients.rs b/crates/engine-core/src/presets/gradients.rs similarity index 100% rename from crates/engine/src/presets/gradients.rs rename to crates/engine-core/src/presets/gradients.rs diff --git a/crates/engine/src/presets/patterns.rs b/crates/engine-core/src/presets/patterns.rs similarity index 100% rename from crates/engine/src/presets/patterns.rs rename to crates/engine-core/src/presets/patterns.rs diff --git a/crates/engine/src/presets/shapes.rs b/crates/engine-core/src/presets/shapes.rs similarity index 100% rename from crates/engine/src/presets/shapes.rs rename to crates/engine-core/src/presets/shapes.rs diff --git a/crates/engine/src/presets/shapes/csh.rs b/crates/engine-core/src/presets/shapes/csh.rs similarity index 100% rename from crates/engine/src/presets/shapes/csh.rs rename to crates/engine-core/src/presets/shapes/csh.rs diff --git a/crates/engine/src/presets/styles.rs b/crates/engine-core/src/presets/styles.rs similarity index 100% rename from crates/engine/src/presets/styles.rs rename to crates/engine-core/src/presets/styles.rs diff --git a/crates/engine/src/presets/swatches.rs b/crates/engine-core/src/presets/swatches.rs similarity index 99% rename from crates/engine/src/presets/swatches.rs rename to crates/engine-core/src/presets/swatches.rs index a2f606fe86..279c6ff481 100644 --- a/crates/engine/src/presets/swatches.rs +++ b/crates/engine-core/src/presets/swatches.rs @@ -302,7 +302,7 @@ mod tests { #[test] fn a_wide_gamut_working_space_changes_cmyk_but_not_rgb() { - let mut s = Session::new(); + let mut s = crate::session(); s.color.settings.working_rgb = "display-p3".into(); let p3 = SwatchConv::new(&s); let srgb = SwatchConv::builtin(); @@ -344,7 +344,7 @@ mod tests { {"name": "b", "color": {"model": "lab", "values": [50.0, -1.5, 2.25]}, "kind": "spot"}, {"name": "c", "color": {"model": "book", "values": {"space": 3, "values": [1, 2, 3, 4]}}}, ]}]}); - let mut s = Session::new(); + let mut s = crate::session(); s.load_presets_json(saved); let groups = &s.presets.swatches; assert_eq!(groups.len(), 1); @@ -353,7 +353,7 @@ mod tests { assert_eq!((e[0].color, e[0].kind), (SwatchColor::Gray(0.5), SwatchKind::Process)); assert_eq!((e[1].color, e[1].kind), (SwatchColor::Lab([50.0, -1.5, 2.25]), SwatchKind::Spot)); assert_eq!(e[2].color, SwatchColor::Book { space: 3, values: [1, 2, 3, 4] }); - let mut t = Session::new(); + let mut t = crate::session(); t.load_presets_json(s.presets.to_json(&s)); assert_eq!(t.presets.swatches, s.presets.swatches); } diff --git a/crates/engine/src/presets/tests.rs b/crates/engine-core/src/presets/tests.rs similarity index 97% rename from crates/engine/src/presets/tests.rs rename to crates/engine-core/src/presets/tests.rs index 19c32059da..e3be3ea930 100644 --- a/crates/engine/src/presets/tests.rs +++ b/crates/engine-core/src/presets/tests.rs @@ -4,7 +4,7 @@ use crate::Session; use photocraft_doc::{Fill, LayerContent, LayerId}; fn session(depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); s } @@ -22,7 +22,7 @@ fn layer_px(s: &Session, x: i32, y: i32) -> Vec { #[test] fn style_preset_new_from_an_explicit_effect_list() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); // The Layer Style dialog's "New Style…" saves its pending state, not the layer. @@ -50,7 +50,7 @@ fn style_preset_new_from_an_explicit_effect_list() { #[test] fn gradient_builtins_and_listing() { - let mut s = Session::new(); + let mut s = crate::session(); let v = s.execute("gradient.presets.list", json!({})).unwrap(); let groups = v["groups"].as_array().unwrap(); let names: Vec<&str> = groups.iter().map(|g| g["name"].as_str().unwrap()).collect(); @@ -274,7 +274,7 @@ fn paint_gradient_honours_explicit_transparency_stops() { json!({"stops": [[0, "#07111d"], [1, "#07111d"]]}), json!({}), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "depth": depth, "background": "transparent"})).unwrap(); // Pixel 15 is sampled at 14.5 (#12018), so a drag to 14 ends on it. let mut p = json!({"from": [0, 0], "to": [0, 14], "transparency": transparency}); @@ -288,7 +288,7 @@ fn paint_gradient_honours_explicit_transparency_stops() { } } // `colors` keeps its colour; a malformed stop list is an error, not a silent opaque fill. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "background": "transparent"})).unwrap(); s.execute("paint.gradient", json!({"from": [0, 0], "to": [0, 15], "colors": ["#07111d", "#07111d"], "transparency": transparency})).unwrap(); let top = layer_px(&s, 8, 0); @@ -320,7 +320,7 @@ fn gradient_apply_creates_fill_layer_and_select_recolours_it() { #[test] fn gradient_new_rename_move_delete_groups() { - let mut s = Session::new(); + let mut s = crate::session(); let rev = s.prefs.rev(); s.execute("gradient.presets.select", json!({"stops": [[0, "#112233"], [0.5, "foreground"], [1, "#ffffff"]], "transparency": [[0, 100], [1, 50]]})).unwrap(); let r = s.execute("gradient.presets.new", json!({"name": "Mine", "group": "My Gradients"})).unwrap(); @@ -350,7 +350,7 @@ fn gradient_new_rename_move_delete_groups() { #[test] fn gradient_rename_group_refuses_a_name_another_group_has() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("gradient.presets.edit", json!({"action": "newGroup", "name": "Pastels"})).unwrap(); let names = |s: &mut Session| -> Vec { s.execute("gradient.presets.list", json!({})).unwrap()["groups"].as_array().unwrap().iter().map(|g| g["name"].clone()).collect() @@ -367,13 +367,13 @@ fn gradient_rename_group_refuses_a_name_another_group_has() { #[test] fn presets_persist_through_preferences_json() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("gradient.presets.new", json!({"name": "Saved", "stops": [[0, "#ff0000"], [1, "#0000ff"]]})).unwrap(); s.execute("tool.presets.new", json!({"name": "Big Brush", "tool": "brush", "options": {"brush": {"size": 300.0}}})).unwrap(); s.execute("shape.presets.new", json!({"name": "Tri", "path": "M 0 0 L 10 0 L 5 10 Z"})).unwrap(); s.execute("style.presets.edit", json!({"action": "deleteGroup", "group": "Buttons"})).unwrap(); let text = s.prefs_to_json(); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&text).unwrap(); let names = |t: &mut Session, cmd: &str, key: &str| -> Vec { let v = t.execute(cmd, json!({})).unwrap(); @@ -391,9 +391,9 @@ fn presets_persist_through_preferences_json() { let tp = t.execute("tool.presets.list", json!({"tool": "Brush Tool"})).unwrap(); assert!(tp["presets"].as_array().unwrap().iter().any(|p| p["name"] == "Big Brush")); // Older preference files without presets keep the defaults. - let mut u = Session::new(); + let mut u = crate::session(); u.load_prefs_json("{}").unwrap(); - assert_eq!(names(&mut u, "gradient.presets.list", "presets").len(), Session::new().presets.gradients.iter().map(|g| g.items.len()).sum::()); + assert_eq!(names(&mut u, "gradient.presets.list", "presets").len(), crate::session().presets.gradients.iter().map(|g| g.items.len()).sum::()); } // ------------------------------------------------------------------ patterns @@ -639,7 +639,7 @@ fn custom_shapes_join_the_shapes_panel() { #[test] fn tool_presets_save_filter_select() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setBrush", json!({"size": 77.0})).unwrap(); s.execute("tool.presets.new", json!({"name": "Seventy Seven", "tool": "brush", "includeColor": true, "options": {"toolOptions": {"x": 1}}})).unwrap(); s.execute("tools.setBrush", json!({"size": 5.0})).unwrap(); @@ -687,7 +687,7 @@ fn tool_presets_reject_invalid_colors_before_applying_the_brush() { } } for values in invalid { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setColors", json!({"foreground": [0.2, 0.4, 0.6, 0.8]})).unwrap(); let color = s.tools.foreground; let brush = (*s.tools.brush).clone(); @@ -708,7 +708,7 @@ fn tool_presets_reject_invalid_colors_before_applying_the_brush() { #[test] fn tool_presets_keep_finite_hdr_colors_and_leave_absent_colors_unchanged() { - let mut s = Session::new(); + let mut s = crate::session(); for (options, expected) in [ (json!({"foreground": [1.5, -0.1, 0.6, 0.8]}), [1.5, -0.1, 0.6, 0.8]), (json!({"foreground": [0.2, 0.4, 0.6]}), [0.2, 0.4, 0.6, 1.0]), @@ -723,7 +723,7 @@ fn tool_presets_keep_finite_hdr_colors_and_leave_absent_colors_unchanged() { /// An Art History Brush preset captures the brush's opacity and selecting it restores it. #[test] fn art_history_brush_preset_carries_the_opacity() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("tools.setBrush", json!({"brush": {"opacity": 0.4}})).unwrap(); s.execute("tool.presets.new", json!({"name": "Faint History", "tool": "artHistoryBrush"})).unwrap(); s.execute("tools.setBrush", json!({"brush": {"opacity": 1.0}})).unwrap(); @@ -735,13 +735,13 @@ fn art_history_brush_preset_carries_the_opacity() { /// Crop presets are `crop` tool presets: saved, listed, persisted and deleted like the others. #[test] fn crop_presets_are_tool_presets_that_persist() { - let mut s = Session::new(); + let mut s = crate::session(); let opts = json!({"toolOptions": {"crop_ratio": "whr", "crop_width": "4 in", "crop_height": "5 in", "crop_resolution": "300", "crop_resolution_unit": "px/in"}}); s.execute("tool.presets.new", json!({"name": "4 x 5 in 300 ppi", "tool": "crop", "options": opts})).unwrap(); let r = s.execute("tool.presets.new", json!({"name": "4 x 5 in 300 ppi", "tool": "crop", "options": opts})).unwrap(); assert_eq!(r["name"], "4 x 5 in 300 ppi 2", "a taken name gets a number"); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&s.prefs_to_json()).unwrap(); let v = t.execute("tool.presets.list", json!({"tool": "crop"})).unwrap(); assert_eq!(v["presets"].as_array().unwrap().len(), 2); @@ -757,7 +757,7 @@ fn crop_presets_are_tool_presets_that_persist() { #[test] fn tool_preset_names_and_params_are_checked() { - let mut s = Session::new(); + let mut s = crate::session(); let n = s.presets.tool_presets.len(); let long = "x".repeat(crate::brush_preset_cmds::MAX_NAME + 1); for bad in [ @@ -790,7 +790,7 @@ fn tool_preset_names_and_params_are_checked() { /// A damaged entry in the saved tool presets is skipped; the other presets (and preferences) load. #[test] fn damaged_tool_presets_skip_only_the_bad_entries() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("gradient.presets.new", json!({"name": "Kept", "stops": [[0, "#ff0000"], [1, "#0000ff"]]})).unwrap(); let mut prefs: Value = serde_json::from_str(&s.prefs_to_json()).unwrap(); prefs["presets"]["tool_presets"] = json!([ @@ -805,7 +805,7 @@ fn damaged_tool_presets_skip_only_the_bad_entries() { {"name": "Good", "tool": "brush"}, {"name": "Odd options", "tool": "crop", "options": 12}, ]); - let mut t = Session::new(); + let mut t = crate::session(); t.load_prefs_json(&prefs.to_string()).unwrap(); let names: Vec<&str> = t.presets.tool_presets.iter().map(|p| p.name.as_str()).collect(); assert_eq!(names, ["Good", "Odd options"]); @@ -813,7 +813,7 @@ fn damaged_tool_presets_skip_only_the_bad_entries() { assert!(t.presets.gradients.iter().any(|g| g.items.iter().any(|p| p.name == "Kept")), "other presets still load"); // Not an array at all: no tool presets, still no crash. prefs["presets"]["tool_presets"] = json!({"a": 1}); - let mut u = Session::new(); + let mut u = crate::session(); u.load_prefs_json(&prefs.to_string()).unwrap(); assert!(u.presets.tool_presets.is_empty()); } @@ -953,7 +953,7 @@ fn gradient_preset_click_on_a_locked_shape_changes_nothing() { /// Document presets (or any other set) at the next launch. #[test] fn a_damaged_preset_set_keeps_the_other_sets() { - let mut s = Session::new(); + let mut s = crate::session(); let settings = json!({"width": 1600, "height": 900, "resolution": 144}); s.execute("document.presets.save", json!({"name": "Banner", "settings": settings})).unwrap(); let export = json!({ @@ -967,33 +967,33 @@ fn a_damaged_preset_set_keeps_the_other_sets() { { let mut blob = saved.clone(); blob[key] = json!("not a preset set"); - let mut next = Session::new(); + let mut next = crate::session(); next.load_presets_json(blob); assert_eq!(next.presets.documents, s.presets.documents, "damaged `{key}`"); - assert_eq!(next.presets.tool_presets.len(), Session::new().presets.tool_presets.len(), "damaged `{key}`"); + assert_eq!(next.presets.tool_presets.len(), crate::session().presets.tool_presets.len(), "damaged `{key}`"); if key != "export_presets" { assert_eq!(next.presets.export_presets, s.presets.export_presets, "damaged `{key}`"); } } let mut blob = saved.clone(); blob["export_presets"] = json!("not a preset set"); - let mut next = Session::new(); + let mut next = crate::session(); next.load_presets_json(blob); assert!(next.presets.export_presets.is_empty()); assert_eq!(next.presets.documents, s.presets.documents); let mut blob = saved.clone(); blob["documents"] = json!("not a preset set"); - let mut next = Session::new(); + let mut next = crate::session(); next.load_presets_json(blob); assert!(next.presets.documents.is_empty()); assert_eq!(next.presets.export_presets, s.presets.export_presets); // Null sets keep their defaults, as before. - let mut next = Session::new(); + let mut next = crate::session(); next.load_presets_json( json!({"tool_presets": null, "gradients": null, "documents": saved["documents"].clone(), "export_presets": saved["export_presets"].clone()}), ); - assert_eq!(next.presets.tool_presets.len(), Session::new().presets.tool_presets.len()); - assert_eq!(next.presets.gradients.len(), Session::new().presets.gradients.len()); + assert_eq!(next.presets.tool_presets.len(), crate::session().presets.tool_presets.len()); + assert_eq!(next.presets.gradients.len(), crate::session().presets.gradients.len()); assert_eq!(next.presets.documents, s.presets.documents); assert_eq!(next.presets.export_presets, s.presets.export_presets); } @@ -1003,7 +1003,7 @@ fn restoring_duplicate_gradient_names_preserves_addressable_presets() { use crate::presets::Group; use crate::presets::gradients::GradientPreset; - let mut s = Session::new(); + let mut s = crate::session(); let presets = vec![ Group::new("First", vec![GradientPreset::new("Foo", &["#ff0000", "#000000"]), GradientPreset::new("Foo", &["#00ff00", "#000000"])]), Group::new("Second", vec![GradientPreset::new("Foo 2", &["#0000ff", "#000000"]), GradientPreset::new("FOO", &["#ffff00", "#000000"])]), @@ -1011,7 +1011,7 @@ fn restoring_duplicate_gradient_names_preserves_addressable_presets() { s.presets.gradient = presets[0].items[1].clone(); s.presets.gradients = presets; let saved = s.presets.to_json(&s); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_presets_json(saved.clone()); let names: Vec = restored.presets.gradients.iter().flat_map(|g| g.items.iter().map(|p| p.name.clone())).collect(); assert_eq!(names, ["Foo", "Foo 3", "Foo 2", "FOO"]); @@ -1033,14 +1033,14 @@ fn restoring_duplicate_gradient_names_preserves_addressable_presets() { #[test] fn export_presets_survive_a_presets_json_round_trip() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.export.presets.save", json!({"name": "Web", "settings": {"format": "jpg", "quality": 70}})).unwrap(); assert_eq!(s.presets.export_presets.len(), 1); let saved = s.presets.to_json(&s); assert_eq!(saved["export_presets"].as_array().map(Vec::len), Some(1)); - let mut restored = Session::new(); + let mut restored = crate::session(); restored.load_presets_json(saved); assert_eq!(restored.presets.export_presets.len(), 1); assert_eq!(restored.presets.export_presets[0].name, "Web"); diff --git a/crates/engine/src/presets/tools.rs b/crates/engine-core/src/presets/tools.rs similarity index 100% rename from crates/engine/src/presets/tools.rs rename to crates/engine-core/src/presets/tools.rs diff --git a/crates/engine/src/proof_sim.rs b/crates/engine-core/src/proof_sim.rs similarity index 99% rename from crates/engine/src/proof_sim.rs rename to crates/engine-core/src/proof_sim.rs index fcee1d76ee..32fcdc48c9 100644 --- a/crates/engine/src/proof_sim.rs +++ b/crates/engine-core/src/proof_sim.rs @@ -335,7 +335,7 @@ mod tests { } fn session(mode: &str, depth: u32) -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 8, "height": 8, "mode": mode, "depth": depth})).unwrap(); s } diff --git a/crates/engine/src/registry.rs b/crates/engine-core/src/registry.rs similarity index 100% rename from crates/engine/src/registry.rs rename to crates/engine-core/src/registry.rs diff --git a/crates/engine/src/scratch.rs b/crates/engine-core/src/scratch.rs similarity index 100% rename from crates/engine/src/scratch.rs rename to crates/engine-core/src/scratch.rs diff --git a/crates/engine/src/second_keys_zoom_actions_tests.rs b/crates/engine-core/src/second_keys_zoom_actions_tests.rs similarity index 99% rename from crates/engine/src/second_keys_zoom_actions_tests.rs rename to crates/engine-core/src/second_keys_zoom_actions_tests.rs index 92d3b820cf..032b77afe2 100644 --- a/crates/engine/src/second_keys_zoom_actions_tests.rs +++ b/crates/engine-core/src/second_keys_zoom_actions_tests.rs @@ -19,7 +19,7 @@ const ACTIONS_MAIN: &str = "Alt+F9"; const ACTUAL_PIXELS_ALT: &str = "Cmd+Alt+0"; fn session() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); s } diff --git a/crates/engine/src/select_mask_edits.rs b/crates/engine-core/src/select_mask_edits.rs similarity index 100% rename from crates/engine/src/select_mask_edits.rs rename to crates/engine-core/src/select_mask_edits.rs diff --git a/crates/engine/src/session.rs b/crates/engine-core/src/session.rs similarity index 100% rename from crates/engine/src/session.rs rename to crates/engine-core/src/session.rs diff --git a/crates/engine/src/session/documents.rs b/crates/engine-core/src/session/documents.rs similarity index 99% rename from crates/engine/src/session/documents.rs rename to crates/engine-core/src/session/documents.rs index d0cc41985a..36b4449268 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine-core/src/session/documents.rs @@ -301,14 +301,13 @@ pub(super) fn fix_active(st: &mut DocState) { #[cfg(test)] mod document_generation_tests { - use super::Session; use photocraft_color::SampleType; use photocraft_doc::{ColorMode, Document}; use photocraft_geom::Size; #[test] fn document_generation_tracks_open_and_close_but_not_selection() { - let mut session = Session::new(); + let mut session = crate::session(); let before = session.documents_generation(); session.add_document(Document::new("test", Size::new(2, 2), ColorMode::Rgb, SampleType::U8), None); let opened = session.documents_generation(); @@ -325,7 +324,7 @@ mod document_generation_tests { /// entries open other documents now (#16252). #[test] fn document_generation_moves_when_documents_are_reordered() { - let mut session = Session::new(); + let mut session = crate::session(); for _ in 0..3 { session.add_document(Document::new("test", Size::new(2, 2), ColorMode::Rgb, SampleType::U8), None); } diff --git a/crates/engine/src/session/execute.rs b/crates/engine-core/src/session/execute.rs similarity index 99% rename from crates/engine/src/session/execute.rs rename to crates/engine-core/src/session/execute.rs index 219d2a0d65..eb318a0d7c 100644 --- a/crates/engine/src/session/execute.rs +++ b/crates/engine-core/src/session/execute.rs @@ -420,13 +420,11 @@ fn bitmap_mode_refusal(s: &Session, id: &str, params: &Value) -> Option<&'static mod bitmap_mode_tests { use serde_json::json; - use crate::Session; - /// #10484: Photoshop 2025 on a Bitmap document refuses Gaussian Blur, Add Noise, Levels and /// Brightness/Contrast, and runs Invert. They all ran. #[test] fn bitmap_documents_refuse_filters_and_adjustments_but_invert() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "mode": "grayscale"})).unwrap(); s.edit("mode", |doc, _| { doc.mode = photocraft_color::ColorMode::Bitmap; @@ -454,7 +452,7 @@ mod bitmap_mode_tests { /// HDR Toning ignored it and edited the Bitmap document. #[test] fn bitmap_documents_refuse_a_list_param_on_commands_without_a_catalogue() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16, "mode": "grayscale", "background": "white"})).unwrap(); s.execute("image.mode.bitmap", json!({"method": "threshold"})).unwrap(); let steps = s.active().unwrap().history.past_len(); diff --git a/crates/engine/src/session/history.rs b/crates/engine-core/src/session/history.rs similarity index 100% rename from crates/engine/src/session/history.rs rename to crates/engine-core/src/session/history.rs diff --git a/crates/engine/src/session/layers.rs b/crates/engine-core/src/session/layers.rs similarity index 100% rename from crates/engine/src/session/layers.rs rename to crates/engine-core/src/session/layers.rs diff --git a/crates/engine/src/shell_commands.rs b/crates/engine-core/src/shell_commands.rs similarity index 100% rename from crates/engine/src/shell_commands.rs rename to crates/engine-core/src/shell_commands.rs diff --git a/crates/engine/src/shortcut_sets.rs b/crates/engine-core/src/shortcut_sets.rs similarity index 99% rename from crates/engine/src/shortcut_sets.rs rename to crates/engine-core/src/shortcut_sets.rs index 46a802abb3..54a38d80ba 100644 --- a/crates/engine/src/shortcut_sets.rs +++ b/crates/engine-core/src/shortcut_sets.rs @@ -428,6 +428,7 @@ mod tests { #[test] fn bound_lists_main_keys_then_alternates() { + crate::install().unwrap(); let p = prefs(); let b = bound(&p); let copy = b.iter().find(|x| x.id == "edit.copy").expect("Copy has keys"); diff --git a/crates/engine/src/snap.rs b/crates/engine-core/src/snap.rs similarity index 100% rename from crates/engine/src/snap.rs rename to crates/engine-core/src/snap.rs diff --git a/crates/engine/src/tests.rs b/crates/engine-core/src/tests.rs similarity index 98% rename from crates/engine/src/tests.rs rename to crates/engine-core/src/tests.rs index ec268fab39..362c0525ba 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine-core/src/tests.rs @@ -2,7 +2,7 @@ use super::*; use serde_json::json; fn session_with_doc() -> Session { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); s } @@ -10,7 +10,7 @@ fn session_with_doc() -> Session { #[test] fn successful_save_identity_is_not_undone_or_redone() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "depth": depth, "name": "Untitled-1"})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let original = s.active().unwrap().doc.clone(); @@ -56,7 +56,7 @@ fn document_pixel_at_the_coordinate_limits() { fn file_new_at_the_size_limit_does_not_fill_every_tile() { // A 300000² white background used to fill ~360 GB of tiles before returning (#705). for background in ["white", "black", "backgroundColor", "#336699"] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 300_000, "height": 300_000, "background": background})).unwrap(); assert_eq!(px(&mut s, 299_999, 299_999)[3], 1.0, "{background}"); assert_eq!(px(&mut s, 0, 0)[3], 1.0, "{background}"); @@ -65,6 +65,7 @@ fn file_new_at_the_size_limit_does_not_fill_every_tile() { #[test] fn command_ids_are_unique_and_documented() { + crate::install().unwrap(); let mut seen = std::collections::HashSet::new(); for c in command_specs() { assert!(seen.insert(c.id), "duplicate command id {}", c.id); @@ -76,7 +77,7 @@ fn command_ids_are_unique_and_documented() { #[test] fn unknown_and_disabled_commands_error() { - let mut s = Session::new(); + let mut s = crate::session(); assert!(matches!(s.execute("nope.nothing", json!({})), Err(EngineError::UnknownCommand(_)))); assert!(matches!(s.execute("layer.new.layer", json!({})), Err(EngineError::Disabled(..)))); assert!(!s.is_enabled("edit.undo")); @@ -85,7 +86,7 @@ fn unknown_and_disabled_commands_error() { #[test] fn file_new_takes_whole_floats_and_survives_odd_sizes() { // #254: the New dialog sent `512.0`; it must not fall back to 1920 x 1080. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 512.0, "height": 511.6})).unwrap(); let d = &s.active().unwrap().doc; assert_eq!((d.size.width, d.size.height), (512, 512)); @@ -141,14 +142,14 @@ fn invalid_file_new_leaves_a_floating_selection_uncommitted() { #[test] fn file_new_keeps_defaults_and_supported_modes_and_depths() { for params in [json!({}), Value::Null] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", params).unwrap(); let d = &s.active().unwrap().doc; assert_eq!((d.size.width, d.size.height, d.resolution_dpi), (1920, 1080, 72.0)); } for mode in ["rgb", "gray", "grayscale", "cmyk", "lab"] { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4.0, "height": 3, "mode": mode, "depth": depth, "resolution": 300})).unwrap(); let d = &s.active().unwrap().doc; assert_eq!(Some(d.mode), crate::document_preset_cmds::color_mode(mode)); @@ -165,7 +166,7 @@ fn file_new_tags_the_document_with_the_chosen_profile() { let bytes = s.active().unwrap().doc.icc_profile.clone(); bytes.map(|b| craft_cms::Profile::parse(&b).unwrap().description) }; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 4, "height": 4, "profile": "adobe-rgb-compat"})).unwrap(); assert_eq!(desc(&s).as_deref(), Some(craft_cms::Builtin::AdobeRgbCompat.description())); s.execute("file.new", json!({"width": 4, "height": 4, "mode": "cmyk", "profile": "coated-cmyk"})).unwrap(); @@ -187,7 +188,7 @@ fn file_new_tags_the_document_with_the_chosen_profile() { #[test] fn file_new_variants() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 10, "height": 5, "background": "transparent"})).unwrap(); assert_eq!(s.active().unwrap().doc.layers[0].name, "Layer 1"); s.execute("file.new", json!({"width": 10, "height": 5, "mode": "cmyk", "depth": 16})).unwrap(); @@ -256,7 +257,7 @@ fn new_adjustment_and_fill_layers_are_masked_by_the_selection() { ("layer.newFillLayer.gradient", json!({"from": "#000000", "to": "#000000"}), true), ("layer.newFillLayer.pattern", json!({"pattern": "Checkerboard"}), false), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 8, "y": 8, "width": 16, "height": 16})).unwrap(); let layer = LayerId(s.execute(id, params).unwrap()["layer"].as_u64().unwrap()); @@ -286,7 +287,7 @@ fn an_edit_after_a_new_fill_layer_on_a_selection_reaches_the_whole_layer() { // #8801: the selection that masked a new fill or adjustment layer is gone, so the next // pixel edit on another layer is not limited to it. for (id, params) in [("layer.newFillLayer.solidColor", json!({"color": "#000000"})), ("layer.newAdjustmentLayer.invert", json!({}))] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 20})).unwrap(); s.execute("edit.fill", json!({"contents": "color", "color": "#3366cc"})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap(); @@ -311,7 +312,7 @@ fn new_adjustment_and_fill_layers_have_white_masks_without_a_selection() { ("layer.newFillLayer.gradient", json!({})), ("layer.newFillLayer.pattern", json!({"pattern": "Checkerboard"})), ] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); let history = s.active().unwrap().history.entries().len(); let layer = LayerId(s.execute(id, params).unwrap()["layer"].as_u64().unwrap()); @@ -334,7 +335,7 @@ fn new_adjustment_and_fill_layers_have_white_masks_without_a_selection() { #[test] fn a_new_adjustment_mask_can_be_painted_immediately() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); assert_eq!(px(&mut s, 20, 20), vec![0.0, 0.0, 0.0, 1.0]); @@ -361,7 +362,7 @@ fn new_fill_and_adjustment_layers_take_the_active_path_as_their_vector_mask() { ("layer.newAdjustmentLayer.invert", json!({}), true), ] { for (path_name, setup) in [("work", "work"), ("Saved", "Saved")] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); s.execute("path.set", json!({"name": setup, "path": square})).unwrap(); // A selection elsewhere: the path wins, as in Photoshop. @@ -409,6 +410,7 @@ fn new_fill_layer_with_a_missing_path_fails_without_a_layer() { #[test] fn every_adjustment_command_runs() { + crate::install().unwrap(); let mut s = session_with_doc(); let ids: Vec<&str> = command_specs().iter().map(|c| c.id).filter(|id| id.starts_with("layer.newAdjustmentLayer.") || id.starts_with("image.adjustments.")).collect(); @@ -562,7 +564,7 @@ fn undo_and_redo_restore_the_targeted_layers() { #[test] fn selection_inverse_preserves_coverage_history_and_empty_selection() { for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 530, "height": 270, "depth": depth})).unwrap(); s.execute("select.rect", json!({"x": 250, "y": 10, "width": 30, "height": 30, "ellipse": true})).unwrap(); let before = s.active().unwrap().doc.clone(); @@ -590,7 +592,7 @@ fn selection_inverse_preserves_coverage_history_and_empty_selection() { s.execute("select.inverse", json!({})).unwrap(); assert_eq!(s.active().unwrap().doc.selection.as_ref().unwrap().content_bounds(), area); } - let mut s = Session::new(); + let mut s = crate::session(); assert!(s.execute("select.inverse", json!({})).is_err()); } @@ -693,7 +695,7 @@ fn arrange_and_group() { #[test] fn canvas_flips_and_rotation() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 10, "height": 4})).unwrap(); s.execute("select.rect", json!({"x": 0, "y": 0, "width": 2, "height": 1})).unwrap(); s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); @@ -715,7 +717,7 @@ fn canvas_flips_and_rotation() { #[test] fn image_rotation_rotates_every_layer_not_just_the_active_one() { // Issue #1: Image Rotation must rotate the whole canvas, not only the selected layer. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 10, "background": "white"})).unwrap(); // A second (lower) layer with a red dot at the top-left; keep a third layer active. s.execute("layer.new.layer", json!({})).unwrap(); @@ -783,7 +785,7 @@ fn gradient_fill_layer_angles_are_finite_and_normalised() { #[test] fn default_colors_with_mask_targeted_resets_to_mask_colors() { - let mut s = Session::new(); + let mut s = crate::session(); s.tools.foreground = [0.2, 0.4, 0.6, 1.0]; s.tools.background = [0.8, 0.6, 0.4, 1.0]; s.tools.target_mask(true); @@ -804,7 +806,7 @@ fn fill_layer_pixel_rewrites_refresh_the_effect_maps() { // A pixel-only rewrite of a fill layer's cache (what Image › Transform and friends do) // leaves the Fill spec alone; the CPU effect maps must follow the cache surface, or the // composite keeps the pre-rewrite drop shadow. Warm render vs. purged render must agree. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); s.execute("layer.newFillLayer.gradient", json!({"from": "#000000", "to": "#ffffff", "angle": 0})).unwrap(); s.edit("shadow", |doc, active| { @@ -858,7 +860,7 @@ fn growing_the_canvas_re_renders_a_cached_fill_layer() { ("image.crop", json!({"x": 0, "y": 0, "width": 100, "height": 48, "deleteCroppedPixels": false})), ]; for (cmd, params) in grow { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "background": "transparent"})).unwrap(); s.execute("layer.newFillLayer.solidColor", json!({"color": "#ff0000"})).unwrap(); s.edit("cache", |doc, active| { @@ -884,7 +886,7 @@ fn growing_the_canvas_re_renders_a_cached_fill_layer() { fn group_effect_maps_follow_child_visibility_and_opacity() { // A styled group's maps come from its children's composite: hiding a child or changing its // opacity must refresh the group's shadow. Warm render vs. purged render must agree. - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "background": "transparent"})).unwrap(); let a = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap(); s.execute("paint.pencil", json!({"points": [[20, 24]], "size": 12, "color": "#ff0000"})).unwrap(); @@ -929,7 +931,7 @@ fn journal_records_mutations_only() { let ids: Vec<&str> = s.journal.iter().map(|(id, _)| id.as_str()).collect(); assert_eq!(ids, ["file.new", "layer.new.layer"]); // replaying the journal reproduces the document - let mut replay = Session::new(); + let mut replay = crate::session(); for (id, p) in s.journal.clone() { replay.execute(&id, p).unwrap(); } @@ -938,7 +940,7 @@ fn journal_records_mutations_only() { #[test] fn command_list_reports_enablement() { - let mut s = Session::new(); + let mut s = crate::session(); let list = s.execute("command.list", json!({})).unwrap(); let find = |id: &str| list.as_array().unwrap().iter().find(|c| c["id"] == id).unwrap().clone(); assert_eq!(find("file.new")["enabled"], true); @@ -949,7 +951,7 @@ fn command_list_reports_enablement() { /// for "ellipse" or "marquee" finds it through its keywords (#5060). #[test] fn command_list_filter_finds_the_marquees_by_keyword() { - let mut s = Session::new(); + let mut s = crate::session(); let list = s.execute("command.list", json!({})).unwrap(); let rows = list.as_array().unwrap(); let found = |needle: &str| -> Vec { @@ -970,7 +972,7 @@ fn command_list_filter_finds_the_marquees_by_keyword() { /// Photoshop's "Camera Raw" name, which their keywords carry (#12403). #[test] fn command_list_filter_finds_the_raw_commands_by_their_photoshop_name() { - let mut s = Session::new(); + let mut s = crate::session(); let list = s.execute("command.list", json!({})).unwrap(); let rows = list.as_array().unwrap(); let found = |needle: &str| -> Vec { @@ -990,6 +992,7 @@ fn command_list_filter_finds_the_raw_commands_by_their_photoshop_name() { /// Every keyword entry names a real command, so a renamed id can't leave one behind. #[test] fn search_keywords_name_real_commands() { + crate::install().unwrap(); for (id, words) in crate::registry::SEARCH_KEYWORDS { assert!(crate::commands::find(id).is_some(), "keywords for unknown command {id}"); assert!(!words.trim().is_empty(), "{id}"); @@ -1001,7 +1004,7 @@ fn search_keywords_name_real_commands() { /// With no document open, a document command says so instead of only `enabled: false` (#3664). #[test] fn command_list_tells_no_document_from_other_preconditions() { - let mut s = Session::new(); + let mut s = crate::session(); let list = s.execute("command.list", json!({})).unwrap(); let find = |list: &Value, id: &str| list.as_array().unwrap().iter().find(|c| c["id"] == id).unwrap().clone(); for id in ["paint.stroke", "layer.new.layer", "filter.blur.gaussianBlur"] { @@ -1334,7 +1337,7 @@ fn selection_tools_do_not_dirty_the_document() { // #6865: marquee, lasso, Select All / Inverse / Deselect and their undo and redo are // history steps, but not edits, so a clean document stays clean. for depth in [8, 16, 32] { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 64, "height": 48, "depth": depth})).unwrap(); let past = s.active().unwrap().history.past_len(); s.execute("select.rect", json!({"x": 2, "y": 2, "width": 20, "height": 10})).unwrap(); @@ -1380,7 +1383,7 @@ fn selections_keep_a_document_with_a_video_layer_clean() { #[test] fn coalesced_edits_share_one_history_step() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let steps = |s: &Session| s.active().unwrap().history.entries().len(); @@ -1408,7 +1411,7 @@ fn coalesced_edits_share_one_history_step() { /// one step an agent can drive too, and one Undo takes the whole run back. #[test] fn translate_and_transform_selection_coalesce_into_one_step() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 60, "height": 60})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("select.rect", json!({"x": 10, "y": 10, "width": 10, "height": 10})).unwrap(); @@ -1447,7 +1450,7 @@ fn translate_and_transform_selection_coalesce_into_one_step() { #[test] fn type_edit_rerenders_cache_to_new_text() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 800, "height": 400})).unwrap(); let r = s.execute("type.create", json!({"x": 50, "y": 200, "text": "Lorem Ipsum", "size": 48, "coalesce": "k"})).unwrap(); let id = r["layer"].as_u64().unwrap(); @@ -1478,7 +1481,7 @@ fn levels_and_curves_params_cover_output_and_channels() { #[test] fn painting_can_target_the_layer_mask() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 40, "height": 40})).unwrap(); s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); @@ -1503,7 +1506,7 @@ fn painting_can_target_the_layer_mask() { #[test] fn layer_locks_are_set_and_enforced() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); s.execute("layer.setProps", json!({"locks": {"pixels": true}})).unwrap(); @@ -1519,7 +1522,7 @@ fn layer_locks_are_set_and_enforced() { #[test] fn all_lock_blocks_painting_a_mask_but_pixels_lock_does_not() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 20, "height": 20})).unwrap(); s.execute("layer.new.layer", json!({})).unwrap(); let id = s.active().unwrap().active_layer.unwrap(); @@ -1589,7 +1592,7 @@ fn marquee_feather_and_anti_aliased_ellipse() { #[test] fn file_new_resolution_and_background_color() { - let mut s = Session::new(); + let mut s = crate::session(); s.tools.background = [1.0, 0.0, 0.0, 1.0]; s.execute("file.new", json!({"width": 8, "height": 8, "resolution": 300, "background": "backgroundColor"})).unwrap(); assert_eq!(s.active().unwrap().doc.resolution_dpi, 300.0); @@ -1623,7 +1626,7 @@ fn advanced_blending_channels() { #[test] fn move_document_reorders_tabs_and_keeps_the_active_one() { - let mut s = Session::new(); + let mut s = crate::session(); for name in ["a", "b", "c"] { s.execute("file.new", json!({"width": 4, "height": 4, "name": name})).unwrap(); } @@ -1673,7 +1676,7 @@ fn adjustment_layer_disabled_diagnostics_use_grammatical_article() { #[test] fn document_inspect_and_activate_invalid_index() { - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 2, "height": 2, "name": "first"})).unwrap(); s.execute("file.new", json!({"width": 2, "height": 2, "name": "second"})).unwrap(); @@ -1691,7 +1694,7 @@ fn document_inspect_and_activate_invalid_index() { /// from the active document, wrapping at both ends. Bad params preserve the active document. #[test] fn document_activate_by_offset_walks_opening_order() { - let mut s = Session::new(); + let mut s = crate::session(); for name in ["a", "b", "c"] { s.execute("file.new", json!({"width": 2, "height": 2, "name": name})).unwrap(); } @@ -1746,7 +1749,7 @@ fn document_activate_by_offset_walks_opening_order() { #[test] fn document_activate_opening_order_survives_close_and_reopen_with_persisted_ids() { - let mut s = Session::new(); + let mut s = crate::session(); // Persisted IDs can be non-monotonic or duplicated: opening order cannot be sorted by ID. for (name, id) in [("a", 300), ("b", 100), ("c", 300)] { let mut doc = Document::new(name, photocraft_geom::Size::new(2, 2), photocraft_doc::ColorMode::Rgb, photocraft_color::SampleType::U8); @@ -1949,7 +1952,7 @@ fn restore_layer_selection_puts_back_what_still_exists() { s.restore_layer_selection(None, &[a], Some(a)).unwrap(); let st = s.active().unwrap(); assert_eq!((st.active_layer, st.selected_layers().to_vec(), st.layer_anchor), (None, vec![], None), "no layer selected"); - assert!(Session::new().restore_layer_selection(None, &[], None).is_err(), "no document"); + assert!(crate::session().restore_layer_selection(None, &[], None).is_err(), "no document"); } /// #4535: every edit snapshots the document into history. The large payloads it carries (the @@ -1958,7 +1961,7 @@ fn restore_layer_selection_puts_back_what_still_exists() { #[test] fn history_states_share_large_document_payloads() { use photocraft_doc::{Adjustment, Duotone, DuotoneInk, Layer, LayerContent}; - let mut s = Session::new(); + let mut s = crate::session(); s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); let raw_id = { let st = s.active_mut().unwrap(); @@ -2066,8 +2069,8 @@ fn the_active_layer_marker_advances_for_a_new_document_and_not_for_a_same_layer_ #[test] fn sessions_share_builtin_brushes_until_edited() { - let mut first = Session::new(); - let second = Session::new(); + let mut first = crate::session(); + let second = crate::session(); assert!(std::sync::Arc::ptr_eq(&first.tools.presets, &second.tools.presets)); let count = second.tools.presets.len(); first.execute("brush.presets.save", serde_json::json!({"name": "Session-only test brush"})).unwrap(); diff --git a/scripts/engine_split/crate_shell.py b/scripts/engine_split/crate_shell.py new file mode 100644 index 0000000000..5db374ba85 --- /dev/null +++ b/scripts/engine_split/crate_shell.py @@ -0,0 +1,379 @@ +#!/usr/bin/env python3 +"""Engine split, step 3: `crates/engine/src` becomes the `photocraft-engine-core` crate. + +The engine's sources live in `crates/engine-core/src`. `crates/engine` keeps the package name +`photocraft-engine`: a thin top crate (`src/facade.rs`) that re-exports core, installs every +engine command and holds `tests/` and `examples/`. Core's `Session::new()` installs nothing, so +core's own tests create sessions with `crate::session()`, and a test that reads the registry +without a session installs first with `crate::install()`. + + python3 scripts/engine_split/crate_shell.py split + On a tree whose `crates/engine/src/lib.rs` is still the whole engine: `git mv` the sources + to `crates/engine-core/src` and the manifest to `crates/engine-core/Cargo.toml`, then + rewrite core's tests (below). The hand-written part of the + step (the top crate, the Cargo files, tooling) is its own commit. + + python3 scripts/engine_split/crate_shell.py branch --base --head + On a branch rebased onto the split. `--head` is the branch commit from before the rebase + (`ORIG_HEAD` right after it). It + - moves every file the branch left under `crates/engine/src` (git follows renames of + files and of directories that disappeared, not new files at the old `src/` root) + into `crates/engine-core/src`, except the top crate's `facade.rs`; + - rewrites core's tests, which covers the branch's new tests; + - applies the branch's added and removed entries of `crates/engine/Cargo.toml`, per + section, to the manifests: dependencies live in `crates/engine-core/Cargo.toml`, and + dev-dependencies go to the manifest whose tests or examples the branch touches (both + when it touches both or neither). Resolve a conflict in `crates/engine/Cargo.toml` by + taking main's version first. Entries are copied whole (multi-line values, comments + above them, `[dependencies.x]` tables). + +Core's tests, in test code only (`#[cfg(test)]` modules and items, bare `#[test]` functions): + `Session::new()` -> `crate::session()`; + a `#[test]` function that calls a registry reader (`commands::find`, `command_specs`, and the + readers in READERS) and creates no session gets `crate::install().unwrap();` as its first line. + `Session` leaves a `use crate::...`/`use super::...` line that the rewrite left it unused in. +Running either mode twice gives the same result. Run `cargo fmt --all` after it: dropping an unused +`Session` import can leave the others out of rustfmt's order. What it cannot do is printed at the end of every run. +""" +import argparse, os, re, sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from rust_source import block_end, git, git_show, in_test, item_ranges, mask, test_fns, test_regions # noqa: E402 + +OLD_SRC = "crates/engine/src" +CORE_SRC = "crates/engine-core/src" +TOP_OWN = {"facade.rs"} +OLD_CARGO = "crates/engine/Cargo.toml" +CORE_CARGO = "crates/engine-core/Cargo.toml" + +# `Session::new()` and `Session::default()` behind any lowercase module path (`crate::`, `super::`, +# `session::`): the whole match becomes `crate::session()`. +SESSION_NEW = re.compile(r"(? crate::session(), {counts['install']} install lines, {counts['files']} files") + + +USE_SESSION = re.compile(r"^[ \t]*use (?:crate|super)::(?:Session|\{([^}]*)\});[ \t]*\n", re.M) + + +HELPER_FN = re.compile(r"\bfn\s+([a-z_][a-z0-9_]*)\s*(?:<[^>{]*>)?\s*\(") + + +def file_readers(m, ranges): + """READERS plus the file's test helpers that call one (`fn label(id) { find(id)... }`).""" + names = [] + for h in HELPER_FN.finditer(m): + if not in_test(ranges, h.start()): + continue + open_brace = m.find("{", h.end()) + if open_brace < 0: + continue + if READERS.search(m[open_brace : block_end(m, open_brace)]): + names.append(h.group(1)) + if not names: + return READERS + return re.compile(READERS.pattern + r"|\b(?:" + "|".join(sorted(set(names))) + r")\s*\(") + + +def drop_unused_session_imports(src, ranges): + """Removes `Session` from test code's `use crate::...`/`use super::...` lines where the + `Session::new()` rewrite left it unused (in the test file, or in the test item holding the line).""" + regions = test_regions_of(src, ranges) + for start, end in sorted(regions, reverse=True): + m = mask(src[start:end]) + for u in reversed(list(USE_SESSION.finditer(m))): + names = [n.strip() for n in u.group(1).split(",")] if u.group(1) is not None else ["Session"] + if "Session" not in names: + continue + others = len(re.findall(r"\bSession\b", m)) - 1 + if others > 0: + continue + rest = [n for n in names if n and n != "Session"] + a, b = start + u.start(), start + u.end() + line = src[a:b] + indent = re.match(r"[ \t]*", line).group(0) + root = "crate" if "use crate::" in line else "super" + text = "" if not rest else f"{indent}use {root}::{rest[0]};\n" if len(rest) == 1 else f"{indent}use {root}::{{{', '.join(rest)}}};\n" + src = src[:a] + text + src[b:] + m = mask(src[start:end]) + return src + + +def test_regions_of(src, ranges): + """The test code of the edited file: all of it for a test file, else its test items.""" + if ranges is None: + return [(0, len(src))] + return item_ranges(mask(src)) + + +def split(): + if os.path.isdir(CORE_SRC): + print(f"{CORE_SRC} exists; moving nothing") + else: + if not os.path.isfile(os.path.join(OLD_SRC, "lib.rs")): + sys.exit(f"{OLD_SRC}/lib.rs is missing: not a tree from before the split") + os.makedirs(os.path.dirname(CORE_SRC), exist_ok=True) + git("mv", OLD_SRC, CORE_SRC) + print(f"moved {OLD_SRC} -> {CORE_SRC}") + if not os.path.isfile(CORE_CARGO): + # Core keeps the engine's manifest (its history, its dependencies); the top crate's is new. + git("mv", OLD_CARGO, CORE_CARGO) + print(f"moved {OLD_CARGO} -> {CORE_CARGO}") + rewrite_tests(CORE_SRC) + + +def stray_files(): + left = [] + for d, _, names in os.walk(OLD_SRC): + for n in names: + rel = os.path.relpath(os.path.join(d, n), OLD_SRC) + if rel not in TOP_OWN: + left.append(rel) + problems = [] + for rel in sorted(left): + dest = os.path.join(CORE_SRC, rel) + if os.path.exists(dest): + problems.append(f"{OLD_SRC}/{rel}: {dest} exists; merge the two by hand") + continue + os.makedirs(os.path.dirname(dest), exist_ok=True) + if git("ls-files", "--error-unmatch", os.path.join(OLD_SRC, rel), check=False): + git("mv", os.path.join(OLD_SRC, rel), dest) + else: + os.rename(os.path.join(OLD_SRC, rel), dest) + print(f"moved {OLD_SRC}/{rel} -> {dest}") + return problems + + +def sections(text): + """[(header, [lines])]; the lines before the first header have header ''.""" + out = [("", [])] + for line in text.split("\n"): + if re.match(r"^\[.*\]\s*$", line): + out.append((line.strip(), [])) + else: + out[-1][1].append(line) + return out + + +DEP_TABLE = re.compile(r"^\[(?:target\..*\.)?(?:dev-|build-)?dependencies\.[^\]]+\]$") +KEY = re.compile(r"^\s*([A-Za-z0-9_.\"-]+)\s*=") + + +def depth(line): + """Net opened brackets of a TOML line, ignoring strings and comments.""" + line = re.sub(r'"(?:[^"\\]|\\.)*"|\'[^\']*\'', "", line) + line = line.split("#")[0] + return sum(line.count(c) for c in "{[") - sum(line.count(c) for c in "}]") + + +def entries(lines): + """[(name, first, end, body)] of a section's `key = value` entries. `first` includes the comment + lines right above the key; a value that spans lines runs to its closing bracket.""" + out, i, comment_from = [], 0, None + while i < len(lines): + line = lines[i] + if line.lstrip().startswith("#"): + comment_from = i if comment_from is None else comment_from + i += 1 + continue + m = KEY.match(line) + if not m: + comment_from = None + i += 1 + continue + end, d = i + 1, depth(line) + while d > 0 and end < len(lines): + d += depth(lines[end]) + end += 1 + out.append((m.group(1), i if comment_from is None else comment_from, end, lines[i:end])) + comment_from = None + i = end + return out + + +def cargo_edits(base, head): + """The branch's Cargo.toml edits: [(op, header, name, text_lines, body)] with op add/remove/table_add/table_remove/table_change.""" + b, h = git_show(base, OLD_CARGO), git_show(head, OLD_CARGO) + if b is None or h is None: + return [] + bs, hs = dict(sections(b)), dict(sections(h)) + ops = [] + for sec in sorted(set(bs) | set(hs)): + if DEP_TABLE.match(sec): + if sec not in bs: + ops.append(("table_add", sec, "", hs[sec], hs[sec])) + elif sec not in hs: + ops.append(("table_remove", sec, "", bs[sec], bs[sec])) + elif bs[sec] != hs[sec]: + ops.append(("table_change", sec, "", hs[sec], hs[sec])) + continue + be = {n: (f, e, body) for n, f, e, body in entries(bs.get(sec, []))} + he = {n: (f, e, body) for n, f, e, body in entries(hs.get(sec, []))} + for n, (f, e, body) in he.items(): + if n not in be or be[n][2] != body: + ops.append(("add", sec, n, hs[sec][f:e], body)) + for n, (f, e, body) in be.items(): + if n not in he: + ops.append(("remove", sec, n, bs[sec][f:e], body)) + return ops + + +def trim_end(lines): + end = len(lines) + while end and not lines[end - 1].strip(): + end -= 1 + return end + + +def apply_cargo(path, ops): + """Applies `ops` to the manifest at `path`; returns what it could not do.""" + problems = [] + secs = sections(open(path).read()) + for op, sec, name, text, body in ops: + where = f"{path} {sec}" + found = next((lines for header, lines in secs if header == sec), None) + if op.startswith("table_"): + if op == "table_remove": + secs[:] = [(h, l) for h, l in secs if h != sec] + elif found is None: + secs.append((sec, text)) + elif trim_end(found) and [x for x in found if x.strip()] != [x for x in text if x.strip()]: + problems.append(f"{where}: the table is there already in another form; the branch has {len(text)} lines for it") + continue + if found is None: + if op == "remove": + continue + secs.append((sec, [])) + found = secs[-1][1] + have = next((e for e in entries(found) if e[0] == name), None) + if op == "remove": + if have is None: + continue + if have[3] != body: + problems.append(f"{where}: `{name}` changed on main since the branch's base; the branch removes it, remove it by hand") + continue + del found[have[1] : have[2]] + elif have is not None: + if have[3] != body: + problems.append(f"{where}: `{name}` is there already in another form; the branch has `{body[0].strip()}`") + else: + at = trim_end(found) + found[at:at] = text + text = "\n".join(([] if not secs[0][1] else ["\n".join(secs[0][1])]) + [h + "\n" + "\n".join(lines) for h, lines in secs[1:]]) + open(path, "w").write(text if text.endswith("\n") else text + "\n") + return problems + + +def route_cargo(base, head, ops): + """{manifest: ops}. Dev-dependencies go to the manifest whose tests or examples the branch touches, + both when it touches both or neither; everything else to core. A normal dependency the branch adds + while it touches the top's tests or examples is also a dev-dependency of the top. An added feature + is not forwarded by the top: reported.""" + files = git("diff", "--name-only", base, head).split() + core = any(f.startswith(OLD_SRC + "/") for f in files) + top = any(f.startswith(("crates/engine/tests/", "crates/engine/examples/")) for f in files) + both = core == top + out = {CORE_CARGO: [], OLD_CARGO: []} + notes = [] + for op in ops: + kind, sec, name, text, body = op + if "dev-dependencies" in sec: + if both or core: + out[CORE_CARGO].append(op) + if both or top: + out[OLD_CARGO].append(op) + continue + out[CORE_CARGO].append(op) + if sec == "[dependencies]" and kind == "add" and top: + out[OLD_CARGO].append((kind, "[dev-dependencies]", name, text, body)) + if sec == "[features]" and kind == "add": + notes.append(f"{OLD_CARGO} [features]: the branch adds `{name}`; the top crate forwards features, so add `{name} = [\"photocraft-engine-core/{name}\"]` there") + return out, notes + + +def branch(base, head): + if not os.path.isdir(CORE_SRC): + sys.exit(f"{CORE_SRC} is missing: rebase onto the split first") + problems = stray_files() + rewrite_tests(CORE_SRC) + routed, notes = route_cargo(base, head, cargo_edits(base, head)) + problems += notes + for path, ops in routed.items(): + if ops: + problems += apply_cargo(path, ops) + print(f"{path}: {len(ops)} edits") + return problems + + +CANNOT_DO = """ +What this script cannot do: + - Registry readers reached through another function. A test that calls `bindable_items`, a `menu_item_*` + function, `command_hints` or the like before it creates a session gets an install line only when the + reader or a helper in its own file is in READERS; CI's per-process runs find the rest ("NotInstalled"). + - Cargo edits the top crate needs beyond the routing above: features it must forward (listed as NOT DONE), + and a dependency used by both `tests/` and core's tests when the branch's changes don't show it. + - Conflicted files: an unmerged path stops `git mv` part-way; resolve conflicts, then run it again. + - Non-test code: a new production `Session::new()` is left alone on purpose. +""" + + +def main(): + p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + sub = p.add_subparsers(dest="mode", required=True) + sub.add_parser("split") + b = sub.add_parser("branch") + b.add_argument("--base", required=True) + b.add_argument("--head", required=True) + a = p.parse_args() + top = git("rev-parse", "--show-toplevel").strip() + os.chdir(top) + problems = split() if a.mode == "split" else branch(a.base, a.head) + for line in problems or []: + print("NOT DONE " + line) + print(CANNOT_DO) + + +if __name__ == "__main__": + main() diff --git a/scripts/engine_split/rust_source.py b/scripts/engine_split/rust_source.py new file mode 100644 index 0000000000..bd708bebab --- /dev/null +++ b/scripts/engine_split/rust_source.py @@ -0,0 +1,157 @@ +"""Shared helpers for the engine split scripts: Rust source scanning and git. + +`mask` blanks comments, strings and char literals so a regex over the result sees only code, at +the same offsets. `test_regions` finds a crate's test code: whole files reached through a +`#[cfg(test)]` (or `#[cfg(all(test, ...))]`) `mod x;`, and the `#[cfg(test)]` items and bare `#[test]` +functions of other files (the test harness compiles `#[test]` functions only in test builds). +`#[cfg(any(test, ...))]` items are not test code: other builds compile them too. +""" +import os, re, subprocess + +CFG_TEST = re.compile(r"#\[cfg\((?:test|all\(test\b[^\]]*\))\)\]") +MOD_DECL = re.compile(r"((?:#\[[^\]]*\]\s*)*)(?:pub(?:\([a-z]+\))?\s+)?mod\s+([a-z0-9_]+)\s*;") +PATH_ATTR = re.compile(r'#\[path\s*=\s*"([^"]+)"\]') +TEST_ATTR = re.compile(r"#\[test\]") +TEST_FN = re.compile(r"#\[test\]\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([a-z]+\))?\s+)?(?:async\s+)?fn\s+([a-z0-9_]+)") +IDENT_BEFORE = re.compile(r"[A-Za-z0-9_]") + + +def mask(src): + """`src` with comments, strings and char literals blanked; same length, newlines kept.""" + out = list(src) + i, n = 0, len(src) + + def blank(a, b): + for k in range(a, min(b, n)): + if out[k] != "\n": + out[k] = " " + + while i < n: + c = src[i] + ident_before = i > 0 and IDENT_BEFORE.match(src[i - 1]) + if src.startswith("//", i): + j = src.find("\n", i) + j = n if j < 0 else j + blank(i, j) + i = j + elif src.startswith("/*", i): + depth, j = 1, i + 2 + while j < n and depth: + if src.startswith("/*", j): + depth, j = depth + 1, j + 2 + elif src.startswith("*/", j): + depth, j = depth - 1, j + 2 + else: + j += 1 + blank(i, j) + i = j + elif c in "rb" and not ident_before and re.match(r'(?:br|r)#*"', src[i : i + 12]): + m = re.match(r'(?:br|r)(#*)"', src[i:]) + end = '"' + m.group(1) + j = src.find(end, i + len(m.group(0))) + j = n if j < 0 else j + len(end) + blank(i, j) + i = j + elif c == '"': + j = i + 1 + while j < n and src[j] != '"': + j += 2 if src[j] == "\\" else 1 + blank(i, j + 1) + i = j + 1 + elif c == "'": + m = re.match(r"'(?:\\(?:x[0-9a-fA-F]{2}|u\{[0-9a-fA-F]+\}|.)|[^\\'\n])'", src[i:]) + if m: + blank(i, i + len(m.group(0))) + i += len(m.group(0)) + else: + i += 1 # a lifetime or label + else: + i += 1 + return "".join(out) + + +def block_end(masked, start): + """The index after the item that starts at `start`: its brace block, or its `;`.""" + i, nest = start, 0 + while i < len(masked) and (nest or masked[i] not in "{;"): + # A `;` inside brackets (`[f32; 4]` in a signature) doesn't end the item. + nest += {"(": 1, "[": 1, ")": -1, "]": -1}.get(masked[i], 0) + i += 1 + if i >= len(masked) or masked[i] == ";": + return i + 1 + depth = 0 + while i < len(masked): + if masked[i] == "{": + depth += 1 + elif masked[i] == "}": + depth -= 1 + if depth == 0: + return i + 1 + i += 1 + return i + + +def module_file(parent, name, attrs): + """The file of `mod name;` declared in `parent` with attributes `attrs`, or None.""" + d = os.path.dirname(parent) + p = PATH_ATTR.search(attrs) + if p: + f = os.path.normpath(os.path.join(d, p.group(1))) + return f if os.path.isfile(f) else None + base = d if os.path.basename(parent) in ("lib.rs", "mod.rs", "main.rs") else os.path.join(d, os.path.basename(parent)[:-3]) + for f in (os.path.join(base, name + ".rs"), os.path.join(base, name, "mod.rs")): + if os.path.isfile(f): + return f + return None + + +def test_regions(root_file): + """{file: None} for a test file, {file: [(start, end)]} with its test items' ranges otherwise.""" + regions, todo = {}, [(root_file, False)] + while todo: + f, is_test = todo.pop() + if f in regions: + continue + src = open(f).read() + m = mask(src) + regions[f] = None if is_test else [] + for d in MOD_DECL.finditer(m): + attrs = src[d.start(1) : d.end(1)] + child = module_file(f, d.group(2), attrs) + if child: + todo.append((child, is_test or bool(CFG_TEST.search(attrs)))) + if not is_test: + regions[f] = item_ranges(m) + return regions + + +def item_ranges(masked): + """The ranges of a non-test file's test items: `#[cfg(test)]` items and bare `#[test]` functions.""" + return [(a.start(), block_end(masked, a.end())) for a in (*CFG_TEST.finditer(masked), *TEST_ATTR.finditer(masked))] + + +def in_test(ranges, pos): + return ranges is None or any(a <= pos < b for a, b in ranges) + + +def test_fns(masked): + """[(name, body_start, body_end)] of the `#[test]` functions in `masked`; body_start is after `{`.""" + out = [] + for t in TEST_FN.finditer(masked): + open_brace = masked.find("{", t.end()) + if open_brace < 0: + continue + out.append((t.group(1), open_brace + 1, block_end(masked, open_brace) - 1)) + return out + + +def git(*args, check=True): + r = subprocess.run(["git", *args], capture_output=True, text=True) + if check and r.returncode != 0: + raise SystemExit(f"git {' '.join(args)}: {r.stderr.strip()}") + return r.stdout + + +def git_show(ref, path): + r = subprocess.run(["git", "show", f"{ref}:{path}"], capture_output=True, text=True) + return r.stdout if r.returncode == 0 else None