mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-18 18:15:34 +00:00
test(xfa): verify cached layers consume the same writer budget
This commit is contained in:
1 parent
c8d0f17b25
commit
2f8820eda3
1 file changed
+35
@@ -424,3 +424,38 @@ fn child_count_memoization_has_a_fixed_entry_limit() {
|
||||
}
|
||||
assert_eq!(cache.len(), 4_096);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cached_layers_still_subtract_work_and_stop_at_the_budget() {
|
||||
let doc = crate::xml::Document::parse("<root><a/><b/><c/></root>").unwrap();
|
||||
let node = doc.root_element();
|
||||
let mut writer = super::Writer {
|
||||
template: node,
|
||||
out: String::new(),
|
||||
limit: super::MAX_OUTPUT,
|
||||
failed: None,
|
||||
ids: None,
|
||||
refs: std::collections::HashMap::new(),
|
||||
soms: std::collections::HashMap::new(),
|
||||
search: super::MAX_SEARCH,
|
||||
work: 100,
|
||||
child_counts: std::collections::HashMap::new(),
|
||||
active: std::collections::HashMap::new(),
|
||||
missing: false,
|
||||
external: false,
|
||||
looped: false,
|
||||
layers_cut: false,
|
||||
};
|
||||
writer.element(&[node], &super::Scope::new(), 0);
|
||||
assert!(writer.failed.is_none());
|
||||
let first_cost = 100 - writer.work;
|
||||
assert!(first_cost > 0);
|
||||
assert!(!writer.child_counts.is_empty());
|
||||
let before = writer.work;
|
||||
writer.element(&[node], &super::Scope::new(), 0);
|
||||
assert!(writer.failed.is_none());
|
||||
assert_eq!(before - writer.work, first_cost, "cached layers pay the same work charge");
|
||||
writer.work = 0;
|
||||
writer.element(&[node], &super::Scope::new(), 0);
|
||||
assert!(writer.failed.as_ref().is_some_and(|why| why.contains("children, attributes and namespaces")));
|
||||
}
|
||||
Reference in new issue
Block a user