PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Keep As Is when reusing variable definitions (#2655)
Benziza0b4fe4b17ffd
diff --git a/crates/engine/src/variables_cmds.rs b/crates/engine/src/variables_cmds.rsindex 3180e8e96..3da65c166 100644--- a/crates/engine/src/variables_cmds.rs+++ b/crates/engine/src/variables_cmds.rs@@ -62,7 +62,7 @@ fn kind_json(k: &VarKind) -> Value {let align = a[..1].to_lowercase() + &a[1..];json!({"type": "pixelReplacement",- "method": format!("{method:?}").to_lowercase(),+ "method": method,"align": align,"clip": clip,})diff --git a/crates/engine/src/variables_cmds/tests.rs b/crates/engine/src/variables_cmds/tests.rsindex 37fbad93f..68fcc9d6a 100644--- a/crates/engine/src/variables_cmds/tests.rs+++ b/crates/engine/src/variables_cmds/tests.rs@@ -83,6 +83,25 @@ fn define_apply_visibility_and_text() {assert_eq!(text_of(&s, title), "Old");}+#[test]+fn listed_pixel_methods_can_be_used_to_redefine_variables() {+ for method in ["fit", "fill", "asIs", "conform"] {+ let (mut s, photo, _badge, _title) = session();+ let defined = s+ .execute(+ "image.variables.define",+ json!({"defs": [{"name": "photo", "layer": photo.0, "type": "pixelReplacement", "method": method, "align": "bottomRight", "clip": true}]}),+ )+ .unwrap();+ let expected = doc(&s).variables.defs.clone();+ let listed = s.execute("variables.list", json!({})).unwrap();+ s.execute("image.variables.define", json!({"defs": listed["defs"]})).unwrap();+ assert_eq!(doc(&s).variables.defs, expected, "{method}");+ assert_eq!(defined["defs"][0]["method"], method);+ assert_eq!(listed["defs"][0]["method"], method);+ }+}+#[test]fn bad_params_are_errors() {let (mut s, _p, badge, _t) = session();