summaryrefslogtreecommitdiff
path: root/tests/suite
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-06-09 15:23:56 +0200
committerGitHub <noreply@github.com>2024-06-09 13:23:56 +0000
commitf91cad7d7829556e24d219e55db7da56a966523f (patch)
treeadce387eb0008198852dd243693512237d3b5f2a /tests/suite
parentcc3e9c86022c5ae5a82938b0b65e3d2dca93b1ed (diff)
Pure location assignment (#4352)
Diffstat (limited to 'tests/suite')
-rw-r--r--tests/suite/introspection/counter.typ28
-rw-r--r--tests/suite/layout/measure.typ72
-rw-r--r--tests/suite/layout/table.typ49
3 files changed, 149 insertions, 0 deletions
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(