summaryrefslogtreecommitdiff
path: root/tests/typ/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'tests/typ/compiler')
-rw-r--r--tests/typ/compiler/content-field.typ29
-rw-r--r--tests/typ/compiler/show-selector.typ2
-rw-r--r--tests/typ/compiler/show-set-func.typ16
-rw-r--r--tests/typ/compiler/show-set.typ55
4 files changed, 92 insertions, 10 deletions
diff --git a/tests/typ/compiler/content-field.typ b/tests/typ/compiler/content-field.typ
index f8adfc42..dab4ec4b 100644
--- a/tests/typ/compiler/content-field.typ
+++ b/tests/typ/compiler/content-field.typ
@@ -1,19 +1,30 @@
-// Tests for field introspection.
+// Tests content field access.
---
-// Verify that non-inherent fields are hidden if not set.
-#show figure: it => [
- `repr(it)`: #repr(it) \
- `it.has("gap"): `#repr(it.has("gap")) \
-]
+// Ensure that fields from set rules are materialized into the element before
+// a show rule runs.
+#set table(columns: (10pt, auto))
+#show table: it => it.columns
+#table[A][B][C][D]
-#figure[]
+---
+// Test it again with a different element.
+#set heading(numbering: "(I)")
+#show heading: set text(size: 11pt, weight: "regular")
+#show heading: it => it.numbering
+= Heading
-#figure([], gap: 1pt)
+---
+// Test it with query.
+#set raw(lang: "rust")
+#locate(loc => {
+ let elem = query(<myraw>, loc).first()
+ elem.lang
+})
+`raw` <myraw>
---
// Integrated test for content fields.
-
#let compute(equation, ..vars) = {
let vars = vars.named()
let f(elem) = {
diff --git a/tests/typ/compiler/show-selector.typ b/tests/typ/compiler/show-selector.typ
index 6bc08f7a..48a26014 100644
--- a/tests/typ/compiler/show-selector.typ
+++ b/tests/typ/compiler/show-selector.typ
@@ -31,9 +31,9 @@ You can use the ```rs *const T``` pointer or
the ```rs &mut T``` reference.
---
+#show heading: set text(green)
#show heading.where(level: 1): set text(red)
#show heading.where(level: 2): set text(blue)
-#show heading: set text(green)
= Red
== Blue
=== Green
diff --git a/tests/typ/compiler/show-set-func.typ b/tests/typ/compiler/show-set-func.typ
new file mode 100644
index 00000000..0447d946
--- /dev/null
+++ b/tests/typ/compiler/show-set-func.typ
@@ -0,0 +1,16 @@
+// Test set rules on an element in show rules for said element.
+
+---
+// These are both red because in the expanded form, `set text(red)` ends up
+// closer to the content than `set text(blue)`.
+#show strong: it => { set text(red); it }
+Hello *World*
+
+#show strong: it => { set text(blue); it }
+Hello *World*
+
+---
+// This doesn't have an effect. An element is materialized before any show
+// rules run.
+#show heading: it => { set heading(numbering: "(I)"); it }
+= Heading
diff --git a/tests/typ/compiler/show-set.typ b/tests/typ/compiler/show-set.typ
new file mode 100644
index 00000000..e336f517
--- /dev/null
+++ b/tests/typ/compiler/show-set.typ
@@ -0,0 +1,55 @@
+// Test show-set rules.
+
+---
+// Test overriding show-set rules.
+#show strong: set text(red)
+Hello *World*
+
+#show strong: set text(blue)
+Hello *World*
+
+---
+// Test show-set rule on the same element.
+#set figure(supplement: [Default])
+#show figure.where(kind: table): set figure(supplement: [Tableau])
+#figure(
+ table(columns: 2)[A][B][C][D],
+ caption: [Four letters],
+)
+
+---
+// Test both things at once.
+#show heading: set text(red)
+= Level 1
+== Level 2
+
+#show heading.where(level: 1): set text(blue)
+#show heading.where(level: 1): set text(green)
+#show heading.where(level: 1): set heading(numbering: "(I)")
+= Level 1
+== Level 2
+
+---
+// Test setting the thing we just matched on.
+// This is quite cursed, but it works.
+#set heading(numbering: "(I)")
+#show heading.where(numbering: "(I)"): set heading(numbering: "1.")
+= Heading
+
+---
+// Same thing, but even more cursed, because `kind` is synthesized.
+#show figure.where(kind: table): set figure(kind: raw)
+#figure(table[A], caption: [Code])
+
+---
+// Test that show-set rules on the same element don't affect each other. This
+// could be implemented, but isn't as of yet.
+#show heading.where(level: 1): set heading(numbering: "(I)")
+#show heading.where(numbering: "(I)"): set text(red)
+= Heading
+
+---
+// Test show-set rules on layoutable element to ensure it is realized
+// even though it implements `LayoutMultiple`.
+#show table: set text(red)
+#pad(table(columns: 4)[A][B][C][D])