mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Conflicts: crates/engine/src/atn_cmds/tests.rs: appended tests, kept both
This commit is contained in:
commit
79ff67c3f2
2 files changed
+34
No files matched your search
@@ -1509,6 +1509,10 @@ fn set_to(id: &str, p: &Value) -> Option<Descriptor> {
|
||||
.with("T ", D::Descriptor(color_desc(hex)?))
|
||||
}
|
||||
"select.rect" => {
|
||||
match jstr(p, "mode") {
|
||||
None | Some("replace") => {}
|
||||
Some(_) => return None,
|
||||
}
|
||||
let (x, y, w, h) = (jnum(p, "x")?, jnum(p, "y")?, jnum(p, "width")?, jnum(p, "height")?);
|
||||
let cls = if jbool(p, "ellipse") == Some(true) { "Elps" } else { "Rctn" };
|
||||
sel(D::Descriptor(desc(cls).with("Top ", px(y)).with("Left", px(x)).with("Btom", px(y + h)).with("Rght", px(x + w))))
|
||||
|
||||
@@ -2053,3 +2053,33 @@ fn recorded_layer_select_exports_to_atn() {
|
||||
let err = export("Set", &[&bad_action], &[], false);
|
||||
assert!(err.is_err(), "occurrence without representation must fail strict export");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select_rect_mode_strict_export_rejects_unrepresentable_modes() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 8, "height": 8})).unwrap();
|
||||
|
||||
// Default or "replace" mode succeeds
|
||||
s.actions.list.push(Action::new("ReplaceAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "replace"}))]));
|
||||
let saved = s.execute("actions.save", json!({"action": "ReplaceAct"})).unwrap();
|
||||
assert_eq!(saved["steps"], 1);
|
||||
|
||||
// "add" mode cannot be silently converted to replace (set) in strict export
|
||||
s.actions.list.push(Action::new("AddAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "add"}))]));
|
||||
let before_actions = s.actions.list.clone();
|
||||
let err = s.execute("actions.save", json!({"action": "AddAct"}));
|
||||
assert!(err.is_err(), "strict export must reject select.rect with add mode rather than converting to replace");
|
||||
assert_eq!(s.actions.list, before_actions, "actions list must remain unchanged after rejected save");
|
||||
|
||||
// "subtract" mode cannot be silently converted to replace either
|
||||
s.actions.list.push(Action::new("SubtractAct", vec![("select.rect".into(), json!({"x": 4, "y": 4, "width": 2, "height": 2, "mode": "subtract"}))]));
|
||||
let before_actions_sub = s.actions.list.clone();
|
||||
let err_subtract = s.execute("actions.save", json!({"action": "SubtractAct"}));
|
||||
assert!(err_subtract.is_err(), "strict export must reject select.rect with subtract mode rather than converting to replace");
|
||||
assert_eq!(s.actions.list, before_actions_sub, "actions list must remain unchanged after rejected save");
|
||||
|
||||
// With skipUnsupported: true, unrepresentable modes are reported in skipped
|
||||
let skipped = s.execute("actions.save", json!({"action": "AddAct", "skipUnsupported": true})).unwrap();
|
||||
assert_eq!(skipped["steps"], 0);
|
||||
assert_eq!(skipped["skipped"][0]["id"], "select.rect");
|
||||
}
|
||||
Reference in new issue
Block a user