From 2f8820eda34a5b83af2912098201564e390c24bb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 13:57:45 -0500 Subject: [PATCH] test(xfa): verify cached layers consume the same writer budget --- crates/xfa/src/proto/tests.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/xfa/src/proto/tests.rs b/crates/xfa/src/proto/tests.rs index 636886bb62..efbec768a0 100644 --- a/crates/xfa/src/proto/tests.rs +++ b/crates/xfa/src/proto/tests.rs @@ -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("").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"))); +}