diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-06-09 15:23:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-09 13:23:56 +0000 |
| commit | f91cad7d7829556e24d219e55db7da56a966523f (patch) | |
| tree | adce387eb0008198852dd243693512237d3b5f2a /tests/suite/layout | |
| parent | cc3e9c86022c5ae5a82938b0b65e3d2dca93b1ed (diff) | |
Pure location assignment (#4352)
Diffstat (limited to 'tests/suite/layout')
| -rw-r--r-- | tests/suite/layout/measure.typ | 72 | ||||
| -rw-r--r-- | tests/suite/layout/table.typ | 49 |
2 files changed, 121 insertions, 0 deletions
diff --git a/tests/suite/layout/measure.typ b/tests/suite/layout/measure.typ index 10c3c818..71a6b32a 100644 --- a/tests/suite/layout/measure.typ +++ b/tests/suite/layout/measure.typ @@ -20,3 +20,75 @@ assert(d2.width < 400pt) assert(d2.height > 50pt) } + +--- measure-counter-width --- +// Measure a counter. Tests that the introspector-assisted location assignment +// is able to take `here()` from the context into account to find the closest +// matching element instaed of any single one. Crucially, we need to reuse +// the same `context c.display()` to get the same span, hence `it`. +#let f(it) = context [ + Is #measure(it).width wide: #it \ +] + +#let c = counter("c") +#let it = context c.display() + +#c.update(10000) +#f(it) +#c.update(100) +#f(it) +#c.update(1) +#f(it) + +--- measure-citation-in-flow --- +// Try measuring a citation that appears inline with other stuff. The +// introspection-assisted location assignment will ensure that the citation +// in the measurement is matched up with the real one. +#context { + let it = [@netwok] + let size = measure(it) + place(line(length: size.width)) + v(1mm) + it + [ is cited] +} + +#show bibliography: none +#bibliography("/assets/bib/works.bib") + +--- measure-citation-in-flow-different-span --- +// When the citation has a different span, it stops working. +#context { + // Error: 22-29 cannot format citation in isolation + // Hint: 22-29 check whether this citation is measured without being inserted into the document + let size = measure[@netwok] + place(line(length: size.width)) + v(1mm) + [@netwok is cited] +} + +#show bibliography: none +#bibliography("/assets/bib/works.bib") + +--- measure-citation-deeply-nested --- +// Nested the citation deeply to test that introspector-assisted measurement +// is able to deal with memoization boundaries. +#context { + let it = box(pad(x: 5pt, grid(stack[@netwok]))) + [#measure(it).width] + it +} + +#show bibliography: none +#bibliography("/assets/bib/works.bib") + +--- measure-counter-multiple-times --- +// When the thing we measure appears multiple times, we measure as if it was +// the first one. +#context { + let c = counter("c") + let u(n) = c.update(n) + let it = context c.get().first() * h(1pt) + let size = measure(it) + table(columns: 5, u(17), it, u(1), it, u(5)) + [#size.width] // 17pt +} diff --git a/tests/suite/layout/table.typ b/tests/suite/layout/table.typ index 4090ef95..fe138f60 100644 --- a/tests/suite/layout/table.typ +++ b/tests/suite/layout/table.typ @@ -139,6 +139,55 @@ [G], [H] ) +--- table-contextual-measurement --- +// Test that table cells with varying contextual results are properly +// measured. +#let c = counter("c") +#let k = context square(width: c.get().first() * 5pt) +#let u(n) = [#n] + c.update(n) +#table( + columns: 3, + u(1), k, u(2), + k, u(4), k, + k, k, k, +) + +--- table-header-citation --- +#set page(height: 60pt) +#table( + table.header[@netwok], + [A], + [A], +) + +#show bibliography: none +#bibliography("/assets/bib/works.bib") + +--- table-header-counter --- +#set page(height: 60pt) +#let c = counter("c") +#table( + table.header(c.step() + context c.display()), + [A], + [A], +) + +--- table-header-footer-madness --- +#set page(height: 100pt) +#let c = counter("c") +#let it = context c.get().first() * v(10pt) +#table( + table.header(c.step()), + [A], + [A], + [A], + [A], + [A], + [A], + [A], + table.footer(it), +) + --- table-cell-override --- // Cell override #table( |
