Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tests/eval_furniture.rs

4.7 KiB, 3 runs

created by r1870400018:63584, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Page furniture against the `typst` 0.15.1 oracle at level 4 (INT-1): page count, page sizes, and every
2//! line's text, baseline and start, for documents whose pages carry a number, a running header, a footer,
3//! a background or a foreground.
4//!
5//! Austenite's side runs the whole pipeline's fixpoint, so a header that reads the introspector (a `context`
6//! query, the page counter) settles over its passes as it does in a compile; the final pass's pages are read.
7//! The fixtures are `tests/fixtures/eval/furniture/*.typ`: numbered pages, a pattern with a total, a numbering
8//! function, a running header from a query, roman then arabic numbering after a counter reset, an odd/even
9//! header on two-sided margins, the `none` and `auto` slots, a background and a foreground, the order the
10//! furniture's located elements take, and a parity blank page.
11//!
12//! The test fails when a fixture differs from typst, or when fewer than `MIN_FIXTURES` were compared.
13
14#![allow(dead_code)]
15
16#[path = "eval_oracle/mod.rs"]
17mod harness;
18
19use harness::austenite::{
20 pages,
21 plain,
22 Keep,
23};
24use harness::corpus::{
25 self,
26 Filter,
27};
28use harness::layout::compare;
29use harness::oracle::Oracle;
30use harness::pdf::{
31 pdf_differences,
32 work_dir,
33};
34
35use oxedyne_fe2o3_austenite::eval::fixpoint;
36use oxedyne_fe2o3_austenite::eval::{
37 eval_source,
38 Engine,
39 World,
40};
41
42use oxedyne_fe2o3_core::prelude::*;
43
44const MIN_FIXTURES: usize = 16;
45
46#[test]
47fn page_furniture_matches_the_typst_oracle() -> Outcome<()> {
48 let oracle = match res!(Oracle::find()) {
49 Some(o) => o,
50 None => return Ok(()),
51 };
52 let only = std::env::var("EVAL_FURNITURE_FIXTURE").ok();
53 let (mut compared, mut failures) = (0usize, Vec::new());
54 for fx in res!(corpus::discover(&Filter::only("furniture"))) {
55 if let Some(o) = &only {
56 if !fx.name.contains(o.as_str()) {
57 continue;
58 }
59 }
60 let want = match res!(oracle.layout(&fx)) {
61 Ok(w) => w,
62 Err(e) => {
63 failures.push(fmt!("{}: typst: {}", fx.id(), e));
64 continue;
65 },
66 };
67 let mut world = World::new(fx.root.clone());
68 let id = match world.load(&fx.path) {
69 Ok(id) => id,
70 Err(e) => {
71 failures.push(fmt!("{}: load: {}", fx.id(), plain(&e)));
72 continue;
73 },
74 };
75 let mut engine = Engine::new(world);
76 let module = match eval_source(&mut engine, id) {
77 Ok(m) => m,
78 Err(e) => {
79 failures.push(fmt!("{}: eval: {}", fx.id(), plain(&e)));
80 continue;
81 },
82 };
83 let mut kept = Keep::default();
84 if let Err(e) = fixpoint::run(&mut engine, &module, &mut kept) {
85 failures.push(fmt!("{}: layout: {}", fx.id(), plain(&e)));
86 continue;
87 }
88 let got = pages(&kept.pages);
89 let mut diffs = Vec::new();
90 compare(&want, &got, &mut diffs);
91 if diffs.is_empty() {
92 compared += 1;
93 println!("ok {} ({} pages)", fx.id(), want.len());
94 } else {
95 failures.push(fmt!("{}:\n {}", fx.id(), diffs.join("\n ")));
96 if std::env::var("EVAL_FURNITURE_DUMP").is_ok() {
97 for (i, p) in want.iter().enumerate() {
98 for l in &p.lines {
99 println!("typst p{} x {:7.2} base {:7.2} {:?}", i + 1, l.x0, l.base, l.text);
100 }
101 }
102 for (i, p) in got.iter().enumerate() {
103 for r in &p.runs {
104 println!("austenite p{} x {:7.2} base {:7.2} {:?}", i + 1, r.x0, r.base, r.text);
105 }
106 }
107 }
108 }
109 }
110 for f in &failures {
111 println!("FAIL {}", f);
112 }
113 println!("{} furniture fixtures compared at level 4; {} failing", compared, failures.len());
114 assert!(failures.is_empty(), "{} fixture(s) differ from typst", failures.len());
115 if only.is_none() {
116 assert!(compared >= MIN_FIXTURES, "only {} furniture fixtures were compared, {} expected", compared, MIN_FIXTURES);
117 }
118 Ok(())
119}
120
121/// The file Austenite writes carries the furniture too: each fixture is compiled through the streaming
122/// `PdfSink`, and the PDF's text and its lines' boxes are read back by the `pdftotext` that reads Typst's.
123#[test]
124fn page_furniture_reaches_austenites_own_pdf() -> Outcome<()> {
125 if res!(Oracle::find()).is_none() {
126 return Ok(());
127 }
128 let (mut compared, mut failures) = (0usize, Vec::new());
129 let root = res!(work_dir("eval-furniture"));
130 for fx in res!(corpus::discover(&Filter::only("furniture"))) {
131 let diffs = res!(pdf_differences(&fx.path, &root.join(&fx.name)));
132 if diffs.is_empty() {
133 compared += 1;
134 println!("ok {} (pdf)", fx.id());
135 } else {
136 failures.push(fmt!("{}:\n {}", fx.id(), diffs.join("\n ")));
137 }
138 }
139 for f in &failures {
140 println!("FAIL {}", f);
141 }
142 println!("{} furniture fixtures compared on austenite's own PDF; {} failing", compared, failures.len());
143 assert!(failures.is_empty(), "{} fixture(s) differ from typst on the PDF", failures.len());
144 assert!(compared >= MIN_FIXTURES, "only {} PDFs were compared, {} expected", compared, MIN_FIXTURES);
145 Ok(())
146}