Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tests/oracle/dump.typ

2.9 KiB, 7 runs

created by r1870400018:38845, 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// The Typst side of the oracle harness: includes a corpus root verbatim, then queries the compiled
2// document for every heading's and figure's resolved page.
3//
4// `__ROOT__` is a placeholder, not a real Typst path: `tests/oracle/mod.rs` copies this file to a
5// temporary sibling of the real corpus root, substituting the root's own file name, so a relative
6// `#include` and a root-absolute `/assets/...` path resolve exactly as they do for a normal compile
7// (Typst's default root is the input file's own directory, which the copy shares with the original).
8//
9// The result rides out through `#metadata`, keyed `<oracle-dump>`, as a plain array of records --
10// `(kind, label, title, page)` -- rather than a `json.encode`d string: `typst query ... --field value`
11// already serialises the metadata value as JSON on its own, so encoding it a second time here would
12// only hand the driver a JSON string to decode before it could decode the JSON inside it. `title` is
13// the heading's or the figure caption's own text, read where it is plain, and falls back to the empty
14// string where it is not (an inline maths span or a glossary call) -- it is a debugging aid for a
15// mismatch report, not a comparison key, since Austenite's own anchor keys are synthesised from a
16// running count and a slug, not from the document's Typst labels.
17#include "__ROOT__"
18
19#context {
20 let text-of(body) = {
21 if type(body) == str { body }
22 else if body.has("text") { body.text }
23 else if body.has("body") { text-of(body.body) }
24 else if body.has("children") { body.children.map(text-of).join("") }
25 else { "" }
26 }
27 let heads = query(heading)
28 let figs = query(figure)
29 // In-float placement probes (`<fp>`): a float's TRUE floated (page, y), read from a `#context
30 // here().position()` marker laid out inside the floated box. Present only in a fixture that embeds them
31 // (the float fixture); every other root queries none. `query(figure).location()` gives the float's
32 // ANCHOR position, not where it lands, so this is what a float-placement parity check must read.
33 let fps = query(<fp>)
34 let entries = heads.map(h => (
35 kind: "heading",
36 label: if h.has("label") { str(h.label) } else { "" },
37 title: text-of(h.body),
38 page: h.location().page(),
39 y: int(calc.round(h.location().position().y / 1pt)),
40 )) + figs.map(f => (
41 kind: "figure",
42 label: if f.has("label") { str(f.label) } else { "" },
43 title: if f.has("caption") and f.caption != none { text-of(f.caption.body) } else { "" },
44 page: f.location().page(),
45 // The figure's ANCHOR y (its in-flow declaration point), for the lenient count/page cross-check --
46 // NOT where a float lands; the `<fp>` probe rows below carry the true floated position.
47 y: int(calc.round(f.location().position().y / 1pt)),
48 )) + fps.map(m => (
49 kind: "floatpos",
50 label: "",
51 title: "",
52 page: m.value.page,
53 y: m.value.y,
54 ))
55 [#metadata(entries) <oracle-dump>]
56}