mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 22:34:09 +00:00
Retype: an explicit null for fonts or tolerance is an invalid parameter
This commit is contained in:
@@ -648,14 +648,14 @@ fn lookup_keys<'a>(
|
||||
fn retype(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "type.retype";
|
||||
let fonts: Vec<String> = match p.get("fonts") {
|
||||
None | Some(Value::Null) => vec![],
|
||||
None => vec![],
|
||||
Some(Value::Array(a)) => {
|
||||
a.iter().map(|v| v.as_str().map(str::to_owned).ok_or_else(|| bad(C, "fonts must be a list of family names"))).collect::<Result<_>>()?
|
||||
}
|
||||
Some(_) => return Err(bad(C, "fonts must be a list of family names")),
|
||||
};
|
||||
let tolerance = match p.get("tolerance") {
|
||||
None | Some(Value::Null) => 0.0,
|
||||
None => 0.0,
|
||||
Some(v) => match v.as_f64() {
|
||||
Some(t) if (0.0..=vectorcraft_text::retype::MAX_TOLERANCE).contains(&t) => t,
|
||||
_ => return Err(bad(C, "tolerance must be a number from 0 to 0.05")),
|
||||
|
||||
@@ -90,7 +90,7 @@ fn a_drawn_shape_is_reported_and_left_alone() {
|
||||
let g = outlined(&mut s, json!({"x": 40, "y": 200, "text": "AB", "size": 40}));
|
||||
s.execute("select.set", &json!({"ids": [g]})).unwrap();
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
for bad in [json!("Source Sans 3"), json!([1]), json!({"family": "x"})] {
|
||||
for bad in [json!("Source Sans 3"), json!([1]), json!({"family": "x"}), json!(null)] {
|
||||
let e = s.execute("type.retype", &json!({"fonts": bad})).unwrap_err().to_string();
|
||||
assert!(e.contains("fonts must be a list of family names"), "{e}");
|
||||
}
|
||||
@@ -596,7 +596,7 @@ fn simplified_outlines_retype_only_with_a_tolerance_and_report_their_score() {
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let e = s.execute("type.retype", &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("no selected shape matches"), "no exact match: {e}");
|
||||
for bad in [json!(-0.01), json!(0.06), json!("0.02"), json!(true)] {
|
||||
for bad in [json!(-0.01), json!(0.06), json!("0.02"), json!(true), json!(null)] {
|
||||
let e = s.execute("type.retype", &json!({"tolerance": bad})).unwrap_err().to_string();
|
||||
assert!(e.contains("tolerance must be a number from 0 to 0.05"), "{e}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user