From 027b2cdd3cd72562c6fa25d0e8d0fa0a296eaec4 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 1 Nov 2026 11:43:45 -0800 Subject: [PATCH] Cover normal Paste followed by Paste As after an internal copy --- .../tests/image_size_scale_styles_atn.rs | 3 +++ crates/ui-egui/tests/it/clipboard_svg.rs | 21 +++++++++++++++++++ crates/ui-egui/tests/it/main.rs | 1 + 3 files changed, 25 insertions(+) create mode 100644 crates/ui-egui/tests/it/clipboard_svg.rs diff --git a/crates/engine/tests/image_size_scale_styles_atn.rs b/crates/engine/tests/image_size_scale_styles_atn.rs index bdac446c76..a177202a98 100644 --- a/crates/engine/tests/image_size_scale_styles_atn.rs +++ b/crates/engine/tests/image_size_scale_styles_atn.rs @@ -67,6 +67,7 @@ fn assert_size_and_style(s: &Session, id: LayerId, scale: bool) { assert_eq!(stroke.size, if scale { 10.0 } else { 20.0 }); } +/// Recorded true, false and omitted flags retain their meaning through save and playback. #[test] fn imported_style_scaling_survives_saved_bytes_and_playback() { for event in ["ImgS", "imageSize"] { @@ -95,6 +96,7 @@ fn imported_style_scaling_survives_saved_bytes_and_playback() { } } +/// Saving native calls writes their effective default instead of changing style scaling. #[test] fn native_default_is_written_explicitly_and_keeps_its_behavior() { for option in [None, Some(json!(false)), Some(json!(true)), Some(Value::Null), Some(json!(1)), Some(json!("false"))] { @@ -121,6 +123,7 @@ fn native_default_is_written_explicitly_and_keeps_its_behavior() { } } +/// Unsupported flags and empty steps remain complete descriptors instead of becoming resizes. #[test] fn malformed_or_empty_steps_are_kept_without_becoming_resizes() { for event in ["ImgS", "imageSize"] { diff --git a/crates/ui-egui/tests/it/clipboard_svg.rs b/crates/ui-egui/tests/it/clipboard_svg.rs new file mode 100644 index 0000000000..d1325cbe87 --- /dev/null +++ b/crates/ui-egui/tests/it/clipboard_svg.rs @@ -0,0 +1,21 @@ +use photocraft_engine::Session; +use photocraft_ui_egui::{PhotocraftApp, Services}; +use serde_json::json; + +/// A normal paste must not make an unchanged external SVG replace a newer internal copy. +#[test] +fn normal_paste_preserves_newer_internal_copy_for_later_paste_as() { + const SVG: &[u8] = br##""##; + let services = + Services { clipboard_get_svg: Some(Box::new(|| Ok(Some(SVG.to_vec())))), clipboard_get_image: Some(Box::new(|| Ok(None))), ..Default::default() }; + let mut app = PhotocraftApp::new(Session::new(), services); + app.run("file.new", json!({"width": 8, "height": 6})).unwrap(); + app.run("edit.paste", json!({"as": "pixels"})).unwrap(); + app.session.edit_prefs(|prefs| prefs.general.export_clipboard = false); + app.run("file.new", json!({"width": 8, "height": 6})).unwrap(); + app.run("edit.fill", json!({"color": "#0000ff"})).unwrap(); + app.run("edit.copy", json!({})).unwrap(); + app.run("edit.paste", json!({})).unwrap(); + app.run("edit.paste", json!({"as": "pixels"})).unwrap(); + assert_eq!(app.run("document.pixel", json!({"x": 4, "y": 3})).unwrap(), json!([0.0, 0.0, 1.0, 1.0])); +} diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index e8d8b334ba..22a28c8477 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -9,6 +9,7 @@ mod camera_raw_scope; mod camera_raw_zoom; mod canvas_16f; mod checker_canvas; +mod clipboard_svg; mod color_managed_canvas; mod crop_beyond_canvas; mod crop_default_mode;