diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-02-01 14:30:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-01 13:30:17 +0000 |
| commit | 7d33436e55f8b1aec06d136ebe095dd86bf23e57 (patch) | |
| tree | 2c7b0673ef7a1992c03ef0b3aad4c25a29490400 /tests | |
| parent | 426445edfc8d32d9ff8fcb79cda5b7765209f567 (diff) | |
Fix show-set semantics (#3311)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/compiler/content-field.png | bin | 24702 -> 8252 bytes | |||
| -rw-r--r-- | tests/ref/compiler/show-set-func.png | bin | 0 -> 5772 bytes | |||
| -rw-r--r-- | tests/ref/compiler/show-set.png | bin | 0 -> 22168 bytes | |||
| -rw-r--r-- | tests/typ/compiler/content-field.typ | 29 | ||||
| -rw-r--r-- | tests/typ/compiler/show-selector.typ | 2 | ||||
| -rw-r--r-- | tests/typ/compiler/show-set-func.typ | 16 | ||||
| -rw-r--r-- | tests/typ/compiler/show-set.typ | 55 |
7 files changed, 92 insertions, 10 deletions
diff --git a/tests/ref/compiler/content-field.png b/tests/ref/compiler/content-field.png Binary files differindex 9fdcb667..3095ba8c 100644 --- a/tests/ref/compiler/content-field.png +++ b/tests/ref/compiler/content-field.png diff --git a/tests/ref/compiler/show-set-func.png b/tests/ref/compiler/show-set-func.png Binary files differnew file mode 100644 index 00000000..c5ff2489 --- /dev/null +++ b/tests/ref/compiler/show-set-func.png diff --git a/tests/ref/compiler/show-set.png b/tests/ref/compiler/show-set.png Binary files differnew file mode 100644 index 00000000..e87fc600 --- /dev/null +++ b/tests/ref/compiler/show-set.png 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]) |
