Tests: cover the .ai reading limits for text data, meshes and variable libraries

- The text engine reader reads dictionaries and lists nested 65 levels
  deep and stops at a 66th, both balanced, so only the depth limit can
  end the parse.
- A row of 256 mesh patches is stitched into one mesh, and a row of 257
  is not.
- A variable library whose variableSets node writes its attributes and
  children before its name is still read when reading stops before the
  library: one variable and one data set with its text value.
This commit is contained in:
dotCooCoo committed 2026-12-02 20:33:58 -08:00
1 parent 15cc3b048f
commit 0ded72192b
3 files changed
+54

No files matched your search

+11
View File
@@ -785,6 +785,17 @@ mod tests {
}
}
/// A row of patches with as many columns as a mesh keeps is stitched into one mesh; one more
/// column is not.
#[test]
fn a_mesh_with_more_lines_than_are_kept_is_not_stitched() {
for (n, kept) in [(MAX_LINES, true), (MAX_LINES + 1, false)] {
let r = Grid::new(n, 1).read([n as f64, 1.0]);
let at: Vec<(usize, usize)> = (0..n).map(|i| (0, i)).collect();
assert_eq!(stitch(&r.cells, &at, 1, n).is_some(), kept, "{n} columns");
}
}
/// A 2 × 2 mesh comes in as one mesh of 9 shared points, each where the patches put it, with
/// the colours the separate patches had at every place.
#[test]
+37
View File
@@ -2799,6 +2799,43 @@ fn ai_variable_library_without_the_layers() {
assert_eq!(variables(stream(&square).as_bytes()), read::VariableRead::default());
}
/// A library whose `variableSets` node writes its children and attributes before its name is
/// still found on its own when reading stops before it.
#[test]
fn a_variable_library_named_after_its_children_is_read_when_reading_stops_early() {
use vectorcraft_doc::DataValue;
use vectorcraft_testkit::ai::{XmlValue, variable_library_data, xml_element, xml_text};
let square = layer(&format!("{RED}{}f\n", rect_path(0.0, 0.0, 10.0, 10.0)));
let value = xml_element("Team", &[], &[xml_element("p", &[], &[xml_text(XmlValue::Unicode("Home Team"))])]);
let set = xml_element(
"variableSet",
&[("locked", "none"), ("varSetName", "binding1")],
&[
xml_element("variables", &[], &[xml_element("variable", &[("trait", "textcontent"), ("varName", "Team")], &[])]),
xml_element(
"v:sampleDataSets",
&[("xmlns", "&ns_custom;"), ("xmlns:v", "&ns_vars;")],
&[xml_element("v:sampleDataSet", &[("dataSetName", "Home")], &[value])],
),
],
);
let named_first = xml_element("variableSets", &[("xmlns", "&ns_vars;")], &[set]);
// Move the name line from the top of the node to just before the line that closes it.
let name = "%_(variableSets) /String (xmlnode-nodename) ,\n";
let body = named_first.strip_prefix(&format!("%_/XMLNode :\n{name}")).and_then(|b| b.strip_suffix("%_;\n")).unwrap_or_default();
assert!(!body.is_empty(), "{named_first}");
let named_last = format!("%_/XMLNode :\n{body}{name}%_;\n");
let early = stream(&format!("LB\n{}{square}", variable_library_data(&named_last)));
assert!(read(early.as_bytes()).is_err());
let found = variables(early.as_bytes(), &mut Names::default());
assert!(found.present);
let names: Vec<&str> = found.variables.variables.iter().map(|v| v.name.as_str()).collect();
assert_eq!(names, ["Team"]);
assert_eq!(found.variables.datasets.len(), 1);
assert_eq!(found.variables.datasets[0].name, "Home");
assert_eq!(found.variables.datasets[0].values.get("Team"), Some(&DataValue::Text("Home Team".into())));
}
#[test]
fn a_drawn_look_stands_for_its_object() {
// The look (a group, with a part on `%_` lines for newer readers), then the object on `%_`
+6
View File
@@ -2361,6 +2361,12 @@ mod tests {
}
let deep = format!("/0 {}", "[".repeat(200));
assert!(read(deep.as_bytes()).is_none());
// Balanced nesting: 65 levels are read, and a 66th ends the parse.
let nest = |open: &str, close: &str, n: usize| format!("/0 {}1{}", open.repeat(n), close.repeat(n));
for (open, close) in [("<< /0 ", " >>"), ("[ ", " ]")] {
assert!(read(nest(open, close, MAX_DEPTH + 1).as_bytes()).is_some(), "{open}nested {} levels", MAX_DEPTH + 1);
assert!(read(nest(open, close, MAX_DEPTH + 2).as_bytes()).is_none(), "{open}nested {} levels", MAX_DEPTH + 2);
}
}
/// A text document's frame on a path of `segments` (each `x0 y0 x1 y1 x2 y2 x3 y3`) with the