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 | |
| parent | cc3e9c86022c5ae5a82938b0b65e3d2dca93b1ed (diff) | |
Pure location assignment (#4352)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/issue-2480-counter-reset-2.png | bin | 0 -> 576 bytes | |||
| -rw-r--r-- | tests/ref/issue-2480-counter-reset.png | bin | 0 -> 355 bytes | |||
| -rw-r--r-- | tests/ref/measure-citation-deeply-nested.png | bin | 0 -> 706 bytes | |||
| -rw-r--r-- | tests/ref/measure-citation-in-flow.png | bin | 0 -> 743 bytes | |||
| -rw-r--r-- | tests/ref/measure-counter-multiple-times.png | bin | 0 -> 471 bytes | |||
| -rw-r--r-- | tests/ref/measure-counter-width.png | bin | 0 -> 2754 bytes | |||
| -rw-r--r-- | tests/ref/table-contextual-measurement.png | bin | 0 -> 453 bytes | |||
| -rw-r--r-- | tests/ref/table-header-citation.png | bin | 0 -> 624 bytes | |||
| -rw-r--r-- | tests/ref/table-header-counter.png | bin | 0 -> 359 bytes | |||
| -rw-r--r-- | tests/ref/table-header-footer-madness.png | bin | 0 -> 613 bytes | |||
| -rw-r--r-- | tests/suite/introspection/counter.typ | 28 | ||||
| -rw-r--r-- | tests/suite/layout/measure.typ | 72 | ||||
| -rw-r--r-- | tests/suite/layout/table.typ | 49 |
13 files changed, 149 insertions, 0 deletions
diff --git a/tests/ref/issue-2480-counter-reset-2.png b/tests/ref/issue-2480-counter-reset-2.png Binary files differnew file mode 100644 index 00000000..26b8502c --- /dev/null +++ b/tests/ref/issue-2480-counter-reset-2.png diff --git a/tests/ref/issue-2480-counter-reset.png b/tests/ref/issue-2480-counter-reset.png Binary files differnew file mode 100644 index 00000000..5dd52b52 --- /dev/null +++ b/tests/ref/issue-2480-counter-reset.png diff --git a/tests/ref/measure-citation-deeply-nested.png b/tests/ref/measure-citation-deeply-nested.png Binary files differnew file mode 100644 index 00000000..4027fd76 --- /dev/null +++ b/tests/ref/measure-citation-deeply-nested.png diff --git a/tests/ref/measure-citation-in-flow.png b/tests/ref/measure-citation-in-flow.png Binary files differnew file mode 100644 index 00000000..14834e76 --- /dev/null +++ b/tests/ref/measure-citation-in-flow.png diff --git a/tests/ref/measure-counter-multiple-times.png b/tests/ref/measure-counter-multiple-times.png Binary files differnew file mode 100644 index 00000000..f1d1bc06 --- /dev/null +++ b/tests/ref/measure-counter-multiple-times.png diff --git a/tests/ref/measure-counter-width.png b/tests/ref/measure-counter-width.png Binary files differnew file mode 100644 index 00000000..3a92f816 --- /dev/null +++ b/tests/ref/measure-counter-width.png diff --git a/tests/ref/table-contextual-measurement.png b/tests/ref/table-contextual-measurement.png Binary files differnew file mode 100644 index 00000000..1a97cbbd --- /dev/null +++ b/tests/ref/table-contextual-measurement.png diff --git a/tests/ref/table-header-citation.png b/tests/ref/table-header-citation.png Binary files differnew file mode 100644 index 00000000..0495d5af --- /dev/null +++ b/tests/ref/table-header-citation.png diff --git a/tests/ref/table-header-counter.png b/tests/ref/table-header-counter.png Binary files differnew file mode 100644 index 00000000..04a8e92d --- /dev/null +++ b/tests/ref/table-header-counter.png diff --git a/tests/ref/table-header-footer-madness.png b/tests/ref/table-header-footer-madness.png Binary files differnew file mode 100644 index 00000000..4e4f771e --- /dev/null +++ b/tests/ref/table-header-footer-madness.png diff --git a/tests/suite/introspection/counter.typ b/tests/suite/introspection/counter.typ index 8a5315f9..c0b17921 100644 --- a/tests/suite/introspection/counter.typ +++ b/tests/suite/introspection/counter.typ @@ -76,3 +76,31 @@ At Beta, it was #context { // Hint: 2-28 try wrapping this in a `context` expression // Hint: 2-28 the `context` expression should wrap everything that depends on this function #counter("key").at(<label>) + +--- issue-2480-counter-reset --- +#let q = counter("question") +#let step-show = q.step() + q.display("1") +#let g = grid(step-show, step-show, gutter: 2pt) + +#g +#pagebreak() +#step-show +#q.update(10) +#g + +--- issue-2480-counter-reset-2 --- +#set block(spacing: 3pt) +#let c = counter("c") +#let foo() = context { + c.step() + c.display("1") + str(c.get().first()) +} + +#foo() +#block(foo()) +#foo() +#foo() +#block(foo()) +#block(foo()) +#foo() 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( |
