pub fn load_document_set(docs: Vec<Arc<Document>>) -> InlineSetExpand description
Load an inline document set. Documents are the XHTML files of one report.
Examples found in repository?
examples/ixtime.rs (line 31)
8fn main() {
9 let list = std::env::args().nth(1).expect("list file");
10 let files: Vec<String> = std::fs::read_to_string(list)
11 .unwrap()
12 .lines()
13 .map(|s| s.to_string())
14 .collect();
15 let (mut parse_t, mut load_t, mut worst) = (0.0, 0.0, (0.0, String::new()));
16 let mut facts = 0usize;
17 let mut diags = 0usize;
18 for f in &files {
19 let Ok(bytes) = std::fs::read(f) else {
20 continue;
21 };
22 let t0 = Instant::now();
23 let Ok(doc) = crossfoot_core::xml::parse(
24 &crossfoot_core::resolve::path_to_uri(std::path::Path::new(f)),
25 &bytes,
26 &Default::default(),
27 ) else {
28 continue;
29 };
30 let t1 = Instant::now();
31 let set = crossfoot_inline::load_document_set(vec![Arc::new(doc)]);
32 let t2 = Instant::now();
33 facts += set.instances.iter().map(|i| i.facts.len()).sum::<usize>();
34 diags += set.diags.len();
35 for d in &set.diags {
36 if std::env::var("IXTIME_DIAGS").is_ok() {
37 println!("{}\t{}", f.rsplit('/').next().unwrap_or(""), d);
38 }
39 }
40 parse_t += (t1 - t0).as_secs_f64();
41 let l = (t2 - t1).as_secs_f64();
42 load_t += l;
43 if l > worst.0 {
44 worst = (l, f.clone());
45 }
46 }
47 let n = files.len().max(1) as f64;
48 println!("{} files, {} facts, {} diags; mean parse {:.4}s, mean inline load {:.4}s, worst load {:.4}s {}", files.len(), facts, diags, parse_t / n, load_t / n, worst.0, worst.1);
49}More examples
examples/ixtargets.rs (line 69)
23fn main() {
24 let dir = std::env::args().nth(1).expect("tests dir");
25 let mut checked = 0;
26 let mut failed = 0;
27 let mut cases: Vec<_> = Vec::new();
28 for area in std::fs::read_dir(&dir).unwrap().flatten() {
29 if !area.path().is_dir() {
30 continue;
31 }
32 for f in std::fs::read_dir(area.path()).unwrap().flatten() {
33 let p = f.path();
34 let name = p.file_name().unwrap().to_string_lossy().to_string();
35 if name.ends_with(".xml") && !name.contains("predictedOutput") && name != "index.xml" {
36 cases.push(p);
37 }
38 }
39 }
40 cases.sort();
41 let dts = Dts::empty();
42 for tc in cases {
43 let Some(doc) = parse(&tc) else { continue };
44 let root = doc.document_element().unwrap();
45 let tdir = tc.parent().unwrap();
46 for v in root.elements().filter(|e| e.local() == "variation") {
47 let Some(result) = v.elements().find(|e| e.local() == "result") else {
48 continue;
49 };
50 let exp: Vec<(Option<String>, String)> = result
51 .elements()
52 .filter(|e| e.local() == "instance")
53 .map(|e| {
54 (
55 e.att("target").map(|s| s.to_string()),
56 e.string_value().trim().to_string(),
57 )
58 })
59 .collect();
60 if exp.len() < 2 && exp.iter().all(|(t, _)| t.is_none()) {
61 continue;
62 }
63 let data = v.elements().find(|e| e.local() == "data").unwrap();
64 let docs: Vec<Arc<xml::Document>> = data
65 .elements()
66 .filter(|e| e.local() == "instance")
67 .filter_map(|e| parse(&tdir.join(e.string_value().trim())))
68 .collect();
69 let set = crossfoot_inline::load_document_set(docs);
70 for (target, file) in &exp {
71 checked += 1;
72 let Some(edoc) = parse(&tdir.join(file)) else {
73 continue;
74 };
75 let (einst, _) = crossfoot_instance::load_instance(edoc, &dts);
76 let want = canonical::dump(&dts, &einst);
77 let got = set
78 .instances
79 .iter()
80 .find(|i| matches!(&i.source, crossfoot_core::InstanceSource::Inline { target: t, .. } if t.as_deref() == target.as_deref()))
81 .map(|i| canonical::dump(&dts, i))
82 .unwrap_or_default();
83 if want != got {
84 failed += 1;
85 println!("DIFF {} target={:?}", tc.display(), target);
86 for f in want.iter().filter(|f| !got.contains(f)) {
87 println!(" - {:?}", f);
88 }
89 for f in got.iter().filter(|f| !want.contains(f)) {
90 println!(" + {:?}", f);
91 }
92 }
93 }
94 }
95 }
96 println!("{} target outputs checked, {} differ", checked, failed);
97}