mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 02:42:47 +00:00
Merge remote-tracking branch 'origin/main' into fix/import-document-title
This commit is contained in:
@@ -303,6 +303,48 @@ fn pasted_art_takes_no_name_the_documents_effects_use() {
|
||||
assert_eq!(names, ["Shift 2", "Shift 3"]);
|
||||
}
|
||||
|
||||
/// A pasted filter is not renamed to a name an effect in a brush's art gives either.
|
||||
#[test]
|
||||
fn pasted_art_takes_no_name_the_documents_brushes_use() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 10.0);
|
||||
run(&mut s, "svgFilter.define", json!({"xml": r#"<filter id="Shift 2"><feOffset dx="1" dy="1"/></filter>"#}));
|
||||
run(&mut s, "svgFilter.apply", json!({"name": "Shift 2", "ids": [a.0]}));
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
run(&mut s, "brush.new", json!({"type": "art", "name": "Fx"}));
|
||||
run(&mut s, "edit.clear", json!({"ids": [a.0]}));
|
||||
run(&mut s, "svgFilter.delete", json!({"name": "Shift 2"}));
|
||||
run(&mut s, "svgFilter.define", json!({"xml": SHIFT}));
|
||||
let svg = format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><defs>{SHIFT_MORE}</defs><rect width="30" height="30" filter="url(#Shift)"/></svg>"#
|
||||
);
|
||||
run(&mut s, "clipboard.importSvg", json!({"svg": svg}));
|
||||
run(&mut s, "edit.pasteInPlace", json!({}));
|
||||
let names: Vec<String> = filter_effects(&s).into_iter().map(|(n, _)| n).collect();
|
||||
assert_eq!(names, ["Shift 3"]);
|
||||
}
|
||||
|
||||
/// A pasted filter at the size limit with a one-letter name, when every free name it could take is
|
||||
/// in use, is refused rather than pasted under the name of the document's filter.
|
||||
#[test]
|
||||
fn a_paste_with_no_free_name_for_its_filter_is_refused() {
|
||||
let mut s = session();
|
||||
for n in ('a'..='z').chain('0'..='9') {
|
||||
run(&mut s, "svgFilter.define", json!({"xml": format!(r#"<filter id="{n}"><feOffset dx="1" dy="1"/></filter>"#)}));
|
||||
}
|
||||
run(&mut s, "svgFilter.define", json!({"xml": r#"<filter id="S"><feOffset dx="3" dy="3"/></filter>"#}));
|
||||
let (open, close) = (r#"<filter id="S"><feOffset dx="9" dy="9" result=""#, r#""/></filter>"#);
|
||||
let big = format!("{open}{}{close}", "a".repeat(vectorcraft_doc::SvgFilter::MAX_XML - open.len() - close.len()));
|
||||
let svg = format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><defs>{big}</defs><rect width="30" height="30" filter="url(#S)"/></svg>"#
|
||||
);
|
||||
run(&mut s, "clipboard.importSvg", json!({"svg": svg}));
|
||||
let before = steps(&s);
|
||||
assert!(err(&mut s, "edit.pasteInPlace", json!({})).contains("no free name"));
|
||||
assert!(filter_effects(&s).is_empty(), "nothing pasted");
|
||||
assert_eq!(steps(&s), before);
|
||||
}
|
||||
|
||||
/// A pasted filter whose name holds a tab, a line feed or a carriage return keeps those characters
|
||||
/// in its id under its new name.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user