Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tests/eval_model_layout.rs

3.5 KiB, 7 runs

created by r1870400018:63608, 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//! Model elements and block bodies laid out against the `typst` 0.15.1 oracle at level 4 (U6b-S2): every
2//! line's text, baseline and start, through the whole pipeline (the fixpoint, so an outline's page numbers,
3//! a footnote's number, a reference's target and what a block, a list item or a cell holds when it is laid out
4//! again are the converged ones).
5//!
6//! The fixtures live in the areas below, one theme to an area (`book` holds the idioms a book's template and
7//! front matter use: show rules selected by field, running heads, counters, outlines, quotes, notes). Each must pass level 4 in full: a fixture that
8//! is not yet right is not kept here, it is an `unsupported` warning in the sweep (`eval_model_sweep`) until it
9//! is. A fixture marked `oracle: rejects` must fail with Typst's first error, message and position. The suite
10//! fails when fewer than `MIN_COMPARED` fixtures were compared or `MIN_REJECTED` rejected, so a harness that
11//! stops finding them cannot pass for nothing.
12
13#![allow(dead_code)]
14
15#[path = "eval_oracle/mod.rs"]
16mod harness;
17
18use harness::corpus::{
19 self,
20 Expect,
21 Filter,
22};
23use harness::oracle::Oracle;
24use harness::Verdict;
25
26use oxedyne_fe2o3_core::prelude::*;
27
28const AREAS: &[&str] = &["bodies", "lists", "notes", "refs", "locate", "tables", "maths", "placing", "book"];
29const VALUE_AREAS: &[&str] = &["book"]; // areas whose level-1 values are held as well as the layout
30const MIN_COMPARED: usize = 125;
31const MIN_REJECTED: usize = 5;
32
33#[test]
34fn model_layout_matches_the_typst_oracle_at_level_4() -> Outcome<()> {
35 let oracle = match res!(Oracle::find()) {
36 Some(o) => o,
37 None => return Ok(()),
38 };
39 let limit = harness::timeout();
40 let only = std::env::var("EVAL_ORACLE_FIXTURE").ok().filter(|s| !s.trim().is_empty());
41 let (mut compared, mut rejected, mut failures) = (0usize, 0usize, Vec::new());
42 for area in AREAS {
43 for fx in res!(corpus::discover(&Filter::only(area))) {
44 if let Some(o) = &only {
45 if !fx.id().contains(o.as_str()) {
46 continue;
47 }
48 }
49 let rep = res!(harness::check(&fx, &oracle, limit));
50 if let Some(f) = &rep.fault {
51 failures.push(fmt!("{}: {}", rep.id, f));
52 continue;
53 }
54 if fx.expect == Expect::Rejects {
55 match &rep.rejection {
56 Verdict::Pass => rejected += 1,
57 other => failures.push(fmt!("{}: the first error differs from Typst's ({:?})", rep.id, other)),
58 }
59 continue;
60 }
61 if VALUE_AREAS.contains(area) && fx.wants(1) {
62 match &rep.levels[0] {
63 Verdict::Pass => (),
64 Verdict::Fail(d) => failures.push(fmt!("{}: L1: {}", rep.id, d.iter().take(4).cloned().collect::<Vec<_>>().join(" | "))),
65 Verdict::NotApplicable(_) | Verdict::NotRequested => (),
66 }
67 }
68 match &rep.levels[3] {
69 Verdict::Pass => compared += 1,
70 Verdict::Fail(d) => {
71 compared += 1;
72 failures.push(fmt!("{}: L4: {}", rep.id, d.iter().take(4).cloned().collect::<Vec<_>>().join(" | ")));
73 },
74 other => failures.push(fmt!("{}: L4 was not compared ({:?})", rep.id, other)),
75 }
76 }
77 }
78 println!("[model-layout] {} fixture(s) compared at level 4, {} rejected as Typst rejects them, {} failure(s)",
79 compared, rejected, failures.len());
80 assert!(failures.is_empty(), "{} failure(s):\n{}", failures.len(), failures.join("\n"));
81 if only.is_none() {
82 assert!(compared >= MIN_COMPARED, "only {} fixture(s) compared; {} are expected", compared, MIN_COMPARED);
83 assert!(rejected >= MIN_REJECTED, "only {} fixture(s) rejected; {} are expected", rejected, MIN_REJECTED);
84 }
85 Ok(())
86}