mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-23 10:53:35 +01:00
EPS/.ai editing data: test an empty variable library's value and type cases and its caps
The valued case now differs from the empty skeleton only by its value, a type alone keeps the note too, and an empty library past the node or depth cap is taken to hold values. The library's doc comment is back above read_variable_sets.
This commit is contained in:
1 parent
295644fc96
commit
91c0e030c7
2 files changed
+36
-6
No files matched your search
@@ -1626,7 +1626,6 @@ impl LibraryWalk {
|
||||
}
|
||||
}
|
||||
|
||||
/// The library of the `variableSets` element `sets` (see [`variable_library`]).
|
||||
/// Whether an XML node in `o` or the dictionaries it holds has a value or a type
|
||||
/// (`xmlnode-nodevalue`, `xmlnode-nodetype`). `seen` counts the dictionaries looked at; past
|
||||
/// [`MAX_LIBRARY_NODES`] of them, or deeper than [`MAX_DEPTH`], the library is taken to hold some.
|
||||
@@ -1641,6 +1640,7 @@ fn holds_values(o: &Obj, seen: &mut usize, depth: usize) -> bool {
|
||||
o.items().any(|c| holds_values(c, seen, depth + 1))
|
||||
}
|
||||
|
||||
/// The library of the `variableSets` element `sets` (see [`variable_library`]).
|
||||
fn read_variable_sets(sets: &Obj) -> VariableRead {
|
||||
let mut walk = LibraryWalk::default();
|
||||
let mut vars = Variables::default();
|
||||
@@ -1666,3 +1666,27 @@ fn read_variable_sets(sets: &Obj) -> VariableRead {
|
||||
}
|
||||
VariableRead { variables: vars, bindings: walk.bindings, bindings_skipped: walk.bindings_skipped, skipped: walk.skipped, present: true }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// An XML node holding `child` (when given) and nothing else: no value, no type.
|
||||
fn node(child: Option<Obj>) -> Obj {
|
||||
let children = Obj { ty: "Array".into(), content: child.map(|c| V::Obj(Rc::new(c))).into_iter().collect(), ..Obj::default() };
|
||||
Obj { ty: "XMLNode".into(), entries: vec![(Some("xmlnode-children".into()), vec![V::Obj(Rc::new(children))])], ..Obj::default() }
|
||||
}
|
||||
|
||||
/// An empty library is taken to hold values past the caps on what is looked at: nested deeper
|
||||
/// than [`MAX_DEPTH`], or once [`MAX_LIBRARY_NODES`] dictionaries have been looked at.
|
||||
#[test]
|
||||
fn an_empty_library_past_the_caps_is_taken_to_hold_values() {
|
||||
let shallow = node(Some(node(None)));
|
||||
assert!(!holds_values(&shallow, &mut 0, 0));
|
||||
let deep = (0..MAX_DEPTH).fold(node(None), |inner, _| node(Some(inner)));
|
||||
assert!(holds_values(&deep, &mut 0, 0));
|
||||
let mut seen = MAX_LIBRARY_NODES;
|
||||
assert!(holds_values(&shallow, &mut seen, 0));
|
||||
}
|
||||
}
|
||||
@@ -2355,7 +2355,7 @@ fn ai_variable_library_edge_cases() {
|
||||
|
||||
/// The empty library a file can keep, its nodes named and nothing else (no value, no type, empty
|
||||
/// attributes), has nothing to list: it comes in without a note. A node that has a value or a type
|
||||
/// isn't empty, so the same skeleton with a value still gets the note.
|
||||
/// isn't empty, so the same skeleton with a value, or with a type, still gets the note.
|
||||
#[test]
|
||||
fn an_empty_variable_library_gives_no_note() {
|
||||
// A node with a name and nothing else: its children, then its attributes, as `%_` lines.
|
||||
@@ -2372,10 +2372,16 @@ fn an_empty_variable_library_gives_no_note() {
|
||||
let (vars, notes) = read_library(&skeleton);
|
||||
assert_eq!(vars, vectorcraft_doc::Variables::default());
|
||||
assert!(notes.is_empty(), "{notes:?}");
|
||||
// A node with a value isn't empty.
|
||||
let valued = data_sets.replace("(xmlnode-nodename) ,\n", "(xmlnode-nodename) ,\n%_(x) /String (xmlnode-nodevalue) ,\n");
|
||||
let (_, notes) = read_library(&bare("variableSets", &[], &[bare("variableSet", &[], &[valued])]));
|
||||
assert_eq!(notes, ["the file's variable library couldn't be read: the Variables panel doesn't list it"]);
|
||||
let unread = ["the file's variable library couldn't be read: the Variables panel doesn't list it"];
|
||||
// The same skeleton but for one entry of the data sets node: a value, then a type.
|
||||
let with = |entry: &str| {
|
||||
let data_sets = data_sets.replace("(xmlnode-nodename) ,\n", &format!("(xmlnode-nodename) ,\n{entry}"));
|
||||
bare("variableSets", &[], &[bare("variableSet", &["varSetName"], &[data_sets])])
|
||||
};
|
||||
for entry in ["%_(x) /String (xmlnode-nodevalue) ,\n", "%_1 /Int (xmlnode-nodetype) ,\n"] {
|
||||
let (_, notes) = read_library(&with(entry));
|
||||
assert_eq!(notes, unread, "{entry}");
|
||||
}
|
||||
}
|
||||
|
||||
/// When the layers can't be read, or reading stops before the library, [`variables`] still reads
|
||||
|
||||
Reference in new issue
Block a user