oxedyne/fe2o3/fe2o3_austenite/tests/footnote_split.rs
2.4 KiB, 1 run
created by r1870400018:75648, 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 | //! A footnote whose entry splits across a page break is set once: its first part at the foot of the page |
| 2 | //! its marker was offered on, the rest at the top of the next page's foot area, as Typst sets it. |
| 3 | //! |
| 4 | //! The marker sits in a nested list item, a breakable block. The note's reservation pushes the marker's |
| 5 | //! line to the next page, so the block's next fragment carries the marker again; the flow must still know |
| 6 | //! the note as placed there, or it sets the whole entry a second time below its continuation (the |
| 7 | //! OxedynePreSeed fault of 2026-10-29, where page 5 repeated footnote 2 in full). |
| 8 | |
| 9 | use oxedyne_fe2o3_austenite::driver::Recorder; |
| 10 | use oxedyne_fe2o3_austenite::eval::content::{ |
| 11 | Content, |
| 12 | ElemKind, |
| 13 | }; |
| 14 | use oxedyne_fe2o3_austenite::eval::styles::StyleChain; |
| 15 | use oxedyne_fe2o3_austenite::eval::{ |
| 16 | eval_source, |
| 17 | Engine, |
| 18 | World, |
| 19 | }; |
| 20 | use oxedyne_fe2o3_austenite::flow; |
| 21 | use oxedyne_fe2o3_austenite::ledger::Position; |
| 22 | |
| 23 | use oxedyne_fe2o3_core::prelude::*; |
| 24 | |
| 25 | use std::path::PathBuf; |
| 26 | |
| 27 | const SOURCE: &str = "\ |
| 28 | #set page(width: 200pt, height: 200pt, margin: 20pt) |
| 29 | #set text(size: 10pt) |
| 30 | #lorem(9) |
| 31 | |
| 32 | - *Outer* item: |
| 33 | - #lorem(3) they pay#footnote[Zyx #lorem(80)] and #lorem(20) |
| 34 | - #lorem(10) |
| 35 | - Second outer item. |
| 36 | "; |
| 37 | |
| 38 | /// The pages each footnote entry's start was placed on. |
| 39 | #[derive(Default)] |
| 40 | struct Entries { |
| 41 | pages: Vec<u32>, |
| 42 | } |
| 43 | |
| 44 | impl Recorder for Entries { |
| 45 | fn record(&mut self, elem: &Content, pos: Position, _parent: Option<u64>) { |
| 46 | if elem.is(ElemKind::FootnoteEntry) { |
| 47 | self.pages.push(pos.page); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | fn mark(&mut self, _id: u64) {} |
| 52 | } |
| 53 | |
| 54 | #[test] |
| 55 | fn a_footnote_split_across_pages_is_set_once() -> Outcome<()> { |
| 56 | let root = PathBuf::from(env!("CARGO_TARGET_TMPDIR")); |
| 57 | let mut world = World::new(root.clone()); |
| 58 | let id = res!(world.add_source(root.join("footnote_split.typ"), SOURCE.to_string())); |
| 59 | let mut engine = Engine::new(world); |
| 60 | let module = res!(eval_source(&mut engine, id)); |
| 61 | let mut paginator = flow::paginate(&module.content, &StyleChain::root()); |
| 62 | let mut entries = Entries::default(); |
| 63 | let mut pages = 0; |
| 64 | while res!(paginator.next_placed(&mut engine, &mut entries)).is_some() { |
| 65 | pages += 1; |
| 66 | } |
| 67 | if pages < 2 { |
| 68 | return Err(err!("The fixture must break its footnote across pages, but it laid {} page(s).", pages; Test)); |
| 69 | } |
| 70 | if entries.pages != vec![1] { |
| 71 | return Err(err!( |
| 72 | "The split footnote's entry was started on pages {:?}; it must start once, on page 1, its \ |
| 73 | continuation alone following on page 2.", entries.pages; Test)); |
| 74 | } |
| 75 | Ok(()) |
| 76 | } |