mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 20:23:53 +00:00
Merge main into fix/plugin-grant-app-approval
This commit is contained in:
@@ -177,6 +177,208 @@ fn export_options_pass_every_listed_key() {
|
||||
}
|
||||
}
|
||||
|
||||
const SAVES: [&str; 4] = ["document.save", "file.saveAs", "file.saveCopy", "file.saveAsTemplate"];
|
||||
|
||||
/// A save refuses a key no save format reads, beside the path, in `options` and in the PDF and
|
||||
/// SVG objects of either, under each save command.
|
||||
#[test]
|
||||
fn save_options_refuse_a_key_no_save_format_reads() {
|
||||
let why = "no save format takes it (see file.formatOptions)";
|
||||
for id in SAVES {
|
||||
assert_eq!(refusal(id, json!({"path": "a.pdf", "noSuchOption": true})), format!("unknown parameter `noSuchOption`; {why}"));
|
||||
assert_eq!(
|
||||
refusal(id, json!({"path": "a.pdf", "options": {"noSuchOption": true}})),
|
||||
format!("unknown parameter `options.noSuchOption`; {why}")
|
||||
);
|
||||
assert_eq!(refusal(id, json!({"compres": true})), "unknown parameter `compres`; did you mean `compress`?");
|
||||
assert_eq!(refusal(id, json!({"options": {"compres": true}})), "unknown parameter `options.compres`; did you mean `options.compress`?");
|
||||
// An export's own key is not a save's.
|
||||
assert_eq!(refusal(id, json!({"path": "a.png", "quality": 80})), format!("unknown parameter `quality`; {why}"));
|
||||
for (given, message) in [
|
||||
(json!({"path": "a.pdf", "marks": {"useDocumentBleed": true}}), "unknown parameter `marks.useDocumentBleed`; `marks` takes:"),
|
||||
(json!({"path": "a.pdf", "options": {"marks": {"x": 1}}}), "unknown parameter `options.marks.x`; `options.marks` takes:"),
|
||||
(json!({"path": "a.ai", "bleed": {"useDocumen": true}}), "unknown parameter `bleed.useDocumen`; did you mean `bleed.useDocument`?"),
|
||||
// The `svg` object is checked when the save writes no SVG too.
|
||||
(json!({"path": "a.pdf", "svg": {"noSuchOption": true}}), "unknown parameter `svg.noSuchOption`; `svg` takes:"),
|
||||
(
|
||||
json!({"path": "a.pdf", "options": {"svg": {"minfy": true}}}),
|
||||
"unknown parameter `options.svg.minfy`; did you mean `options.svg.minify`?",
|
||||
),
|
||||
] {
|
||||
let got = refusal(id, given.clone());
|
||||
assert!(got.starts_with(message), "{id} {given}: {got}");
|
||||
}
|
||||
// A key that another format a save writes reads still passes: the save leaves it out.
|
||||
for given in [
|
||||
json!({"path": "a.svg", "compress": true}),
|
||||
json!({"path": "a.pdf", "options": {"preview": true, "styling": "style"}}),
|
||||
json!({"path": "a.vectorcraft", "standard": "pdfX4", "marks": {"trim": true}}),
|
||||
json!({"path": "a.ai", "acknowledgeLoss": true, "modified": null, "svg": {"minify": true}}),
|
||||
json!({"path": "a.svg", "svg": {"styling": "css", "artboard": 0, "useArtboards": true}}),
|
||||
] {
|
||||
check_params(id, &given).unwrap_or_else(|e| panic!("{id} {given}: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A save passes each option of each format it writes, beside the path and in `options`, and
|
||||
/// each key its description names.
|
||||
#[test]
|
||||
fn save_options_pass_every_listed_key() {
|
||||
use crate::cmd::fileio::{FORMATS, SAVE_FORMATS, TEMPLATE_FORMATS};
|
||||
for f in FORMATS.iter().filter(|f| SAVE_FORMATS.contains(&f.id) || TEMPLATE_FORMATS.contains(&f.id)) {
|
||||
for o in f.options {
|
||||
for params in [json!({"format": f.id, o.name: null}), json!({"format": f.id, "options": {o.name: null}})] {
|
||||
for id in SAVES {
|
||||
check_params(id, ¶ms).unwrap_or_else(|e| panic!("{id} {params}: {e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for id in SAVES {
|
||||
let keys = doc_keys(find_command(id).unwrap().params).unwrap().keys;
|
||||
let refused: Vec<&str> = keys.into_iter().filter(|key| check_params(id, &json!({*key: null})).is_err()).collect();
|
||||
assert_eq!(refused, Vec::<&str>::new(), "{id} names and refuses these");
|
||||
}
|
||||
}
|
||||
|
||||
/// Export for Screens refuses a key it doesn't take, and in its rows and settings a key no format
|
||||
/// reads, by the row's path; `document.exportPresets.save` checks the rows of its settings.
|
||||
#[test]
|
||||
fn export_for_screens_refuses_a_key_no_format_reads() {
|
||||
let id = "document.exportForScreens";
|
||||
assert!(
|
||||
refusal(id, json!({"folder": "out", "noSuchOption": true})).starts_with("unknown parameter `noSuchOption`; the command takes: artboard, ")
|
||||
);
|
||||
assert_eq!(refusal(id, json!({"subfolder": true})), "unknown parameter `subfolder`; did you mean `subfolders`?");
|
||||
let no_format = "no format takes it (see document.formats)";
|
||||
for (given, message) in [
|
||||
(json!({"formats": [{"format": "png", "noSuchOption": 1}]}), format!("unknown parameter `formats[0].noSuchOption`; {no_format}")),
|
||||
(
|
||||
json!({"formats": [{"format": "png"}, {"format": "pdf", "marks": {"useDocumentBleed": true}}]}),
|
||||
"unknown parameter `formats[1].marks.useDocumentBleed`; `formats[1].marks` takes:".into(),
|
||||
),
|
||||
(
|
||||
json!({"formats": [{"format": "pdf", "security": {"openPasswrd": "x"}}]}),
|
||||
"unknown parameter `formats[0].security.openPasswrd`; did you mean `formats[0].security.openPassword`?".into(),
|
||||
),
|
||||
(
|
||||
json!({"formats": [{"format": "eps", "flattener": {"balanse": 50}}]}),
|
||||
"unknown parameter `formats[0].flattener.balanse`; did you mean `formats[0].flattener.balance`?".into(),
|
||||
),
|
||||
(json!({"formats": [{"format": "jpg", "sufix": "@2x"}]}), "unknown parameter `formats[0].sufix`; did you mean `formats[0].suffix`?".into()),
|
||||
(json!({"settings": {"pnj": {}}}), "unknown parameter `settings.pnj`; did you mean `settings.png`?".into()),
|
||||
(json!({"settings": {"dxf": {}}}), "unknown parameter `settings.dxf`; `settings` takes: ".into()),
|
||||
(
|
||||
json!({"settings": {"png": {"bckground": "white"}}}),
|
||||
"unknown parameter `settings.png.bckground`; did you mean `settings.png.background`?".into(),
|
||||
),
|
||||
(json!({"settings": {"pdf": {"bleed": {"top": 9, "inner": 1}}}}), "unknown parameter `settings.pdf.bleed.inner`;".into()),
|
||||
] {
|
||||
let got = refusal(id, given.clone());
|
||||
assert!(got.starts_with(&message), "{given}: {got}");
|
||||
}
|
||||
let save = "document.exportPresets.save";
|
||||
assert_eq!(
|
||||
refusal(save, json!({"name": "a", "settings": {"formats": [{"format": "png", "noSuchOption": 1}]}})),
|
||||
format!("unknown parameter `settings.formats[0].noSuchOption`; {no_format}")
|
||||
);
|
||||
assert!(
|
||||
refusal(save, json!({"name": "a", "settings": {"settings": {"pdf": {"marks": {"x": 1}}}}}))
|
||||
.starts_with("unknown parameter `settings.settings.pdf.marks.x`;")
|
||||
);
|
||||
assert_eq!(
|
||||
refusal(save, json!({"name": "a", "settings": {"formtas": [{"format": "png"}]}})),
|
||||
"unknown parameter `settings.formtas`; did you mean `settings.formats`?"
|
||||
);
|
||||
assert!(
|
||||
refusal(save, json!({"name": "a", "settings": {"noSuchOption": true}}))
|
||||
.starts_with("unknown parameter `settings.noSuchOption`; `settings` takes: artboard, ")
|
||||
);
|
||||
// Export Assets takes the same rows and settings, and stores them.
|
||||
for asset in ["assets.export", "assets.settings.set"] {
|
||||
assert_eq!(
|
||||
refusal(asset, json!({"formats": [{"format": "png", "noSuchOption": 1}]})),
|
||||
format!("unknown parameter `formats[0].noSuchOption`; {no_format}")
|
||||
);
|
||||
assert!(refusal(asset, json!({"settings": {"pdf": {"marks": {"x": 1}}}})).starts_with("unknown parameter `settings.pdf.marks.x`;"));
|
||||
check_params(asset, &json!({"formats": [{"format": "jpg", "scale": "2x", "quality": 80}]})).unwrap();
|
||||
}
|
||||
// An exporter plug-in's `params` in a row (its format is a plug-in's: tests/plugin_export.rs).
|
||||
check_params(id, &json!({"formats": [{"format": "png", "params": {}}]})).unwrap();
|
||||
// Keys the preset leaves out are still Export for Screens params.
|
||||
check_params(save, &json!({"name": "a", "settings": {"zip": true, "formats": [{"format": "jpg", "quality": 80}]}})).unwrap();
|
||||
// The encoders read Include Artboard Fill and Appearance of Black from a row or a format's
|
||||
// settings.
|
||||
for given in [
|
||||
json!({"formats": [{"format": "png", "includeArtboardFill": false, "richBlack": true}]}),
|
||||
json!({"settings": {"png": {"includeArtboardFill": false, "richBlack": true}}}),
|
||||
] {
|
||||
check_params(id, &given).unwrap_or_else(|e| panic!("{given}: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Export for Screens passes each key its description names, each option of a format in a row or
|
||||
/// in settings, and the built-in presets; `settings` takes the formats a row can write.
|
||||
#[test]
|
||||
fn export_for_screens_passes_every_listed_key() {
|
||||
use crate::cmd::fileio::{FORMATS, check_screen_settings, screen_export_builtin_presets};
|
||||
let id = "document.exportForScreens";
|
||||
let keys = doc_keys(find_command(id).unwrap().params).unwrap().keys;
|
||||
assert!(keys.len() > 20, "{keys:?}");
|
||||
// The keys the check takes are the ones the description names.
|
||||
let (mut named, mut taken) = (keys.clone(), crate::cmd::fileio::SCREEN_PARAM_KEYS.to_vec());
|
||||
named.sort_unstable();
|
||||
taken.sort_unstable();
|
||||
assert_eq!(named, taken);
|
||||
let refused: Vec<&str> = keys.into_iter().filter(|key| check_params(id, &json!({*key: null})).is_err()).collect();
|
||||
assert_eq!(refused, Vec::<&str>::new(), "{id} names and refuses these");
|
||||
check_params(id, &json!({"artboard": 0, "openLocation": true})).unwrap();
|
||||
let s = Session::new();
|
||||
for f in FORMATS.iter().filter(|f| f.write) {
|
||||
for o in f.options {
|
||||
let row = json!({"formats": [{"format": "png", "scale": 2, "suffix": "", "folder": "x", o.name: null}]});
|
||||
check_params(id, &row).unwrap_or_else(|e| panic!("{row}: {e}"));
|
||||
}
|
||||
let written = check_screen_settings(&s, &json!({"formats": [{"format": f.id}]})).is_ok();
|
||||
let settings = json!({"settings": {f.id: {}}});
|
||||
assert_eq!(check_params(id, &settings).is_ok(), written, "{settings}");
|
||||
}
|
||||
for preset in screen_export_builtin_presets() {
|
||||
let settings = serde_json::Value::Object(preset.settings);
|
||||
check_params(id, &settings).unwrap_or_else(|e| panic!("{}: {e}", preset.name));
|
||||
check_params("document.exportPresets.save", &json!({"name": "a", "settings": settings})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A saved row loses the keys Export for Screens refuses in it, inside its object options too, and
|
||||
/// keeps the others.
|
||||
#[test]
|
||||
fn a_saved_row_drops_the_keys_no_format_reads() {
|
||||
use crate::cmd::params::drop_unread_row_options;
|
||||
let serde_json::Value::Object(mut row) = json!({
|
||||
"format": "pdf", "scale": "1x", "noSuchOption": 1, "params": {"x": 1},
|
||||
"marks": {"useDocumentBleed": true, "trim": true}, "preset": "High Quality Print",
|
||||
"security": {"passwordRequired": true, "noSuchLock": 1}
|
||||
}) else {
|
||||
panic!("an object")
|
||||
};
|
||||
drop_unread_row_options(&mut row);
|
||||
assert_eq!(
|
||||
serde_json::Value::Object(row.clone()),
|
||||
json!({
|
||||
"format": "pdf", "scale": "1x", "params": {"x": 1}, "marks": {"trim": true}, "preset": "High Quality Print",
|
||||
"security": {"passwordRequired": true}
|
||||
})
|
||||
);
|
||||
check_params("document.exportForScreens", &json!({"formats": [row]})).unwrap();
|
||||
// Remembered security whose passwords were left out, with one given again.
|
||||
let security = json!({"passwordRequired": true, "openPassword": "x"});
|
||||
for id in ["document.exportForScreens", "assets.export", "assets.settings.set"] {
|
||||
check_params(id, &json!({"formats": [{"format": "pdf", "security": security}], "settings": {"pdf": {"security": security}}})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// `stroke.set` names every key it reads (its own, `item`, and `ids`/`id`/`target`), so a
|
||||
/// misnamed one is refused instead of answering `objects: 1` with nothing changed.
|
||||
#[test]
|
||||
|
||||
@@ -447,6 +447,42 @@ fn a_painted_effect_on_a_fill_and_refused_results() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A result refused for a swatch the document doesn't have stays cached: once the document has the
|
||||
/// swatch, the next check of that result clears the error.
|
||||
#[test]
|
||||
fn a_refused_swatch_s_error_clears_once_the_document_has_the_swatch() {
|
||||
let mut s = session();
|
||||
let id = rect(&mut s, 10.0, "#ff0000");
|
||||
let mut later = solid("#00ff00");
|
||||
later["swatch"] = json!("Later");
|
||||
let output = json!({"objects": [{"path": square_at(40.0), "fills": [later]}]}).to_string();
|
||||
install_wat(&mut s, &tpl::returning(&painting("test.engine.laterswatch", true), &output));
|
||||
run(&mut s, "effect.apply", json!({"ids": [id.0], "effect": "plugin.test.engine.laterswatch"}));
|
||||
drawn(&s);
|
||||
assert!(run(&mut s, "plugin.info", json!({"id": "test.engine.laterswatch"}))["lastError"].is_string());
|
||||
run(&mut s, "swatch.new", json!({"name": "Later", "color": "#00ff00", "global": true}));
|
||||
drawn(&s);
|
||||
assert_eq!(run(&mut s, "plugin.info", json!({"id": "test.engine.laterswatch"}))["lastError"], Value::Null);
|
||||
}
|
||||
|
||||
/// An effect that paints nothing has no references to check, so replacing a refused painted effect
|
||||
/// with one clears the refusal's error once it runs.
|
||||
#[test]
|
||||
fn a_replacement_that_paints_nothing_clears_a_refused_swatch_s_error() {
|
||||
let mut s = session();
|
||||
let id = rect(&mut s, 10.0, "#ff0000");
|
||||
let mut gone = solid("#00ff00");
|
||||
gone["swatch"] = json!("Absent");
|
||||
let output = json!({"objects": [{"path": square_at(40.0), "fills": [gone]}]}).to_string();
|
||||
install_wat(&mut s, &tpl::returning(&painting("test.engine.replaced", true), &output));
|
||||
run(&mut s, "effect.apply", json!({"ids": [id.0], "effect": "plugin.test.engine.replaced"}));
|
||||
drawn(&s);
|
||||
assert!(run(&mut s, "plugin.info", json!({"id": "test.engine.replaced"}))["lastError"].is_string());
|
||||
install_wat(&mut s, &tpl::returning(&painting("test.engine.replaced", false), &output));
|
||||
drawn(&s);
|
||||
assert_eq!(run(&mut s, "plugin.info", json!({"id": "test.engine.replaced"}))["lastError"], Value::Null);
|
||||
}
|
||||
|
||||
/// A painted effect on a group may link its pieces to the document's swatches.
|
||||
#[test]
|
||||
fn a_painted_group_effect_links_to_the_document_s_swatches() {
|
||||
|
||||
@@ -72,7 +72,7 @@ fn save_as_takes_on_path_format_and_options() {
|
||||
let d = dir("saveas");
|
||||
let mut s = session();
|
||||
let pdf = path(&d, "doc.pdf");
|
||||
s.execute("file.saveAs", &json!({"path": pdf, "options": {"range": "1", "bogus": 1}})).unwrap();
|
||||
s.execute("file.saveAs", &json!({"path": pdf, "options": {"range": "1", "preview": true}})).unwrap();
|
||||
let st = s.doc().unwrap();
|
||||
assert_eq!((st.format, st.title()), ("pdf", "doc.pdf".to_string()));
|
||||
assert_eq!(Value::Object(st.save_options.clone()), json!({"range": "1"}), "only the format's own options are kept");
|
||||
|
||||
Reference in New Issue
Block a user