From 3ab64de0ff63af8c363f2aaa7ddadf5037ca56d8 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 23 Nov 2026 20:54:27 +0000 Subject: [PATCH] Move the batch's paint-dependent core tests to the engine crate --- .../cmd/image_cmds/canvas_size_gray_tests.rs | 20 --------- crates/engine/tests/it/paint_in_image_cmds.rs | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/crates/engine-core/src/cmd/image_cmds/canvas_size_gray_tests.rs b/crates/engine-core/src/cmd/image_cmds/canvas_size_gray_tests.rs index 1edddf41c0..3d1cc97309 100644 --- a/crates/engine-core/src/cmd/image_cmds/canvas_size_gray_tests.rs +++ b/crates/engine-core/src/cmd/image_cmds/canvas_size_gray_tests.rs @@ -49,26 +49,6 @@ fn background_value(s: &Session, x: i32, y: i32) -> [f32; 4] { s.active().unwrap().doc.background().unwrap().surface().unwrap().rgba(x, y) } -/// A 32-bit document holds linear light: its Gray is the value an 8-bit grey 128 becomes when the -/// document is converted to 32 bits (0.2159), not 128/255. -#[test] -fn gray_in_a_32_bit_document_is_linear_grey_128() { - let mut converted = crate::session(); - converted.execute("file.new", json!({"width": 4, "height": 4, "depth": 8, "background": "white"})).unwrap(); - converted.execute("edit.fill", json!({"color": "#808080"})).unwrap(); - converted.execute("image.mode.bits32", json!({})).unwrap(); - let want = background_value(&converted, 1, 1); - assert!((want[0] - 0.2159).abs() < 0.002, "converted grey 128: {want:?}"); - let mut s = doc(32); - s.execute("image.canvasSize", GROW("gray")).unwrap(); - let got = background_value(&s, 450, 350); - for i in 0..3 { - assert!((got[i] - want[i]).abs() < 1e-4, "channel {i}: {got:?} vs {want:?}"); - } - assert_eq!(got[3], 1.0); - assert_eq!(background_value(&s, 10, 10)[..3], [1.0, 1.0, 1.0], "the old Background keeps its pixels"); -} - /// An Indexed Color document was not measured and keeps today's behaviour: Gray takes the /// background colour there, as an unknown value does. #[test] diff --git a/crates/engine/tests/it/paint_in_image_cmds.rs b/crates/engine/tests/it/paint_in_image_cmds.rs index 592e99d08b..b8868f8c2d 100644 --- a/crates/engine/tests/it/paint_in_image_cmds.rs +++ b/crates/engine/tests/it/paint_in_image_cmds.rs @@ -1,4 +1,4 @@ -//! Tests that run paint commands, moved from the engine-core `image_cmds` tests: 12 test(s). +//! Tests that run paint commands, moved from the engine-core `image_cmds` tests: 13 test(s). mod canvas_size_center_offset_tests { use serde_json::{Value, json}; @@ -341,3 +341,44 @@ mod tests { } } } + +mod canvas_size_gray_tests { + use serde_json::{Value, json}; + + use photocraft_engine::Session; + + /// A 400 x 300 document at `depth` with a white Background and an empty layer "Top" above it. + fn doc(depth: u32) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 400, "height": 300, "depth": depth, "background": "white"})).unwrap(); + s.execute("layer.new.layer", json!({"name": "Top"})).unwrap(); + s + } + + /// The Background's stored colour at pixel (x, y). + fn background_value(s: &Session, x: i32, y: i32) -> [f32; 4] { + s.active().unwrap().doc.background().unwrap().surface().unwrap().rgba(x, y) + } + + const GROW: fn(&str) -> Value = |color| json!({"width": 500, "height": 400, "anchor": "topLeft", "extensionColor": color}); + + /// A 32-bit document holds linear light: its Gray is the value an 8-bit grey 128 becomes when the + /// document is converted to 32 bits (0.2159), not 128/255. + #[test] + fn gray_in_a_32_bit_document_is_linear_grey_128() { + let mut converted = Session::new(); + converted.execute("file.new", json!({"width": 4, "height": 4, "depth": 8, "background": "white"})).unwrap(); + converted.execute("edit.fill", json!({"color": "#808080"})).unwrap(); + converted.execute("image.mode.bits32", json!({})).unwrap(); + let want = background_value(&converted, 1, 1); + assert!((want[0] - 0.2159).abs() < 0.002, "converted grey 128: {want:?}"); + let mut s = doc(32); + s.execute("image.canvasSize", GROW("gray")).unwrap(); + let got = background_value(&s, 450, 350); + for i in 0..3 { + assert!((got[i] - want[i]).abs() < 1e-4, "channel {i}: {got:?} vs {want:?}"); + } + assert_eq!(got[3], 1.0); + assert_eq!(background_value(&s, 10, 10)[..3], [1.0, 1.0, 1.0], "the old Background keeps its pixels"); + } +}