summaryrefslogtreecommitdiff
path: root/tests/typ/style
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-07 12:21:12 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-07 12:46:05 +0100
commitefd1853d069fbd1476e82d015da4d0d04cfaccc0 (patch)
tree842b745c134306539d10c61be9485794fe8dc7dc /tests/typ/style
parenteb951c008beea502042db4a3a0e8d1f8b51f6f52 (diff)
Show it!
- New show rule syntax - Set if syntax - Removed wrap syntax
Diffstat (limited to 'tests/typ/style')
-rw-r--r--tests/typ/style/set.typ13
-rw-r--r--tests/typ/style/show-bare.typ (renamed from tests/typ/style/wrap.typ)23
-rw-r--r--tests/typ/style/show-node.typ45
-rw-r--r--tests/typ/style/show-recursive.typ23
-rw-r--r--tests/typ/style/show-text.typ32
5 files changed, 76 insertions, 60 deletions
diff --git a/tests/typ/style/set.typ b/tests/typ/style/set.typ
index 25dc1b81..2864b81b 100644
--- a/tests/typ/style/set.typ
+++ b/tests/typ/style/set.typ
@@ -49,5 +49,18 @@ Hello *{x}*
+ Tiger
---
+// Test conditional set.
+#show ref: it => {
+ set text(red) if it.target == "unknown"
+ it
+}
+
+@hello from the @unknown
+
+---
+// Error: 19-24 expected boolean, found integer
+#set text(red) if 1 + 2
+
+---
// Error: 11-25 set is only allowed directly in code and content blocks
{ let x = set text(blue) }
diff --git a/tests/typ/style/wrap.typ b/tests/typ/style/show-bare.typ
index e37c4bc9..2dba742f 100644
--- a/tests/typ/style/wrap.typ
+++ b/tests/typ/style/show-bare.typ
@@ -1,4 +1,4 @@
-// Test wrap.
+// Test bare show without pattern.
---
#set page(height: 130pt)
@@ -9,28 +9,25 @@
T. Ypst
]
-#wrap body in columns(2, body)
+#show columns.with(2)
Great typography is at the essence of great storytelling. It is the medium that
transports meaning from parchment to reader, the wave that sparks a flame
in booklovers and the great fulfiller of human need.
---
-// Test wrap in content block.
-A [_B #wrap c in [*#c*]; C_] D
+// Test bare show in content block.
+A [_B #show c => [*#c*]; C_] D
---
-// Test wrap style precedence.
+// Test style precedence.
#set text(fill: eastern, size: 1.5em)
-#wrap body in text(fill: forest, body)
+#show text.with(fill: forest)
Forest
---
-// Ok, whatever.
-{
- wrap body in 2 * body
- 2
-}
+#show [Shown]
+Ignored
---
-// Error: 4-18 wrap is only allowed directly in code and content blocks
-{ (wrap body in 2) * body }
+// Error: 4-18 show is only allowed directly in code and content blocks
+{ (show body => 2) * body }
diff --git a/tests/typ/style/show-node.typ b/tests/typ/style/show-node.typ
index b35ab4c4..56b7e34a 100644
--- a/tests/typ/style/show-node.typ
+++ b/tests/typ/style/show-node.typ
@@ -3,7 +3,7 @@
---
// Override lists.
#set list(around: none)
-#show v: list as "(" + v.items.join(", ") + ")"
+#show list: it => "(" + it.items.join(", ") + ")"
- A
- B
@@ -14,12 +14,12 @@
---
// Test full reset.
#set heading(size: 1em, strong: false, around: none)
-#show heading as [B]
+#show heading: [B]
A [= Heading] C
---
// Test full removal.
-#show heading as []
+#show heading: none
#set heading(around: none)
Where is
@@ -29,13 +29,13 @@ my heading?
---
// Test integrated example.
#set heading(size: 1em)
-#show node: heading as {
+#show heading: it => {
move(dy: -1pt)[📖]
h(5pt)
- if node.level == 1 {
- underline(text(1.25em, blue, node.body))
+ if it.level == 1 {
+ underline(text(1.25em, blue, it.body))
} else {
- text(red, node.body)
+ text(red, it.body)
}
}
@@ -50,10 +50,10 @@ Another text.
---
// Test set and show in code blocks.
-#show node: heading as {
+#show heading: it => {
set text(red)
- show "ding" as [🛎]
- node.body
+ show "ding": [🛎]
+ it.body
}
= Heading
@@ -62,12 +62,12 @@ Another text.
// Test that scoping works as expected.
{
let world = [ World ]
- show c: "W" as strong(c)
+ show "W": strong
world
{
set text(blue)
- wrap it in {
- show "o" as "Ø"
+ show it => {
+ show "o": "Ø"
it
}
world
@@ -76,22 +76,27 @@ Another text.
}
---
-#show heading as 1234
+#show heading: [1234]
= Heading
---
// Error: 25-29 unknown field "page"
-#show it: heading as it.page
+#show heading: it => it.page
= Heading
---
-// Error: 10-15 this function cannot be customized with show
-#show _: upper as {}
+// Error: 7-12 this function cannot be customized with show
+#show upper: it => {}
+
+---
+// Error: 16-20 expected content or function, found integer
+#show heading: 1234
+= Heading
---
// Error: 7-10 expected function, string or regular expression, found color
-#show red as []
+#show red: []
---
-// Error: 7-27 show is only allowed directly in code and content blocks
-{ 1 + show heading as none }
+// Error: 7-25 show is only allowed directly in code and content blocks
+{ 1 + show heading: none }
diff --git a/tests/typ/style/show-recursive.typ b/tests/typ/style/show-recursive.typ
index 9e93739c..566879af 100644
--- a/tests/typ/style/show-recursive.typ
+++ b/tests/typ/style/show-recursive.typ
@@ -2,17 +2,18 @@
---
// Test basic identity.
-#show it: heading as it
+#show heading: it => it
= Heading
---
// Test more recipes down the chain.
-#show it: list as scale(origin: left, x: 80%, it)
-#show heading as []
-#show enum as []
+#show list: scale.with(origin: left, x: 80%)
+#show heading: []
+#show enum: []
- Actual
- Tight
- List
+= Nope
---
// Test recursive base recipe. (Burn it with fire!)
@@ -23,11 +24,11 @@
---
// Test show rule in function.
#let starwars(body) = [
- #show v: list as {
+ #show list: it => {
stack(dir: ltr,
- text(red, v),
+ text(red, it),
1fr,
- scale(x: -100%, text(blue, v)),
+ scale(x: -100%, text(blue, it)),
)
}
#body
@@ -44,8 +45,8 @@
---
// Test multi-recursion with nested lists.
#set rect(inset: 2pt)
-#show v: list as rect(stroke: blue, v)
-#show v: list as rect(stroke: red, v)
+#show list: rect.with(stroke: blue)
+#show list: rect.with(stroke: red)
- List
- Nested
@@ -55,8 +56,8 @@
---
// Inner heading is not finalized. Bug?
#set heading(around: none)
-#show it: heading as it.body
-#show heading as [
+#show heading: it => it.body
+#show heading: [
= A [
= B
]
diff --git a/tests/typ/style/show-text.typ b/tests/typ/style/show-text.typ
index 283a2887..457ce9b7 100644
--- a/tests/typ/style/show-text.typ
+++ b/tests/typ/style/show-text.typ
@@ -3,22 +3,22 @@
---
// Test classic example.
#set text("Roboto")
-#show phrase: "Der Spiegel" as smallcaps[#phrase]
+#show "Der Spiegel": smallcaps
Die Zeitung Der Spiegel existiert.
---
// Another classic example.
-#show "TeX" as [T#h(-0.145em)#move(dy: 0.233em)[E]#h(-0.135em)X]
-#show name: regex("(Lua)?(La)?TeX") as box(text("Latin Modern Roman")[#name])
+#show "TeX": [T#h(-0.145em)#move(dy: 0.233em)[E]#h(-0.135em)X]
+#show regex("(Lua)?(La)?TeX"): name => box(text("Latin Modern Roman")[#name])
TeX, LaTeX, LuaTeX and LuaLaTeX!
---
// Test out-of-order guarding.
-#show "Good" as [Typst!]
-#show "Typst" as [Fun!]
-#show "Fun" as [Good!]
-#show enum as []
+#show "Good": [Typst!]
+#show "Typst": [Fun!]
+#show "Fun": [Good!]
+#show enum: []
Good \
Fun \
@@ -26,32 +26,32 @@ Typst \
---
// Test that replacements happen exactly once.
-#show "A" as [BB]
-#show "B" as [CC]
+#show "A": [BB]
+#show "B": [CC]
AA (8)
---
// Test caseless match and word boundaries.
-#show regex("(?i)\bworld\b") as [🌍]
+#show regex("(?i)\bworld\b"): [🌍]
Treeworld, the World of worlds, is a world.
---
// This is a fun one.
#set par(justify: true)
-#show letter: regex("\S") as rect(inset: 2pt)[#upper(letter)]
+#show regex("\S"): letter => rect(inset: 2pt)[#upper(letter)]
#lorem(5)
---
// See also: https://github.com/mTvare6/hello-world.rs
-#show it: regex("(?i)rust") as [#it (🚀)]
+#show regex("(?i)rust"): it => [#it (🚀)]
Rust is memory-safe and blazingly fast. Let's rewrite everything in rust.
---
// Replace worlds but only in lists.
-#show node: list as [
- #show "World" as [🌎]
- #node
+#show list: it => [
+ #show "World": [🌎]
+ #it
]
World
@@ -60,6 +60,6 @@ World
---
// Test absolute path in layout phase.
-#show "GRAPH" as image("/res/graph.png")
+#show "GRAPH": image("/res/graph.png")
The GRAPH has nodes.