diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/style/set.png | bin | 20825 -> 24880 bytes | |||
| -rw-r--r-- | tests/ref/style/show-bare.png (renamed from tests/ref/style/wrap.png) | bin | 24846 -> 25853 bytes | |||
| -rw-r--r-- | tests/ref/text/code.png | bin | 38900 -> 40777 bytes | |||
| -rw-r--r-- | tests/src/tests.rs | 2 | ||||
| -rw-r--r-- | tests/typ/base/eval.typ | 11 | ||||
| -rw-r--r-- | tests/typ/code/break-continue.typ | 2 | ||||
| -rw-r--r-- | tests/typ/code/field.typ | 4 | ||||
| -rw-r--r-- | tests/typ/code/import.typ | 2 | ||||
| -rw-r--r-- | tests/typ/code/include.typ | 2 | ||||
| -rw-r--r-- | tests/typ/graphics/shape-rect.typ | 4 | ||||
| -rw-r--r-- | tests/typ/structure/desc.typ | 2 | ||||
| -rw-r--r-- | tests/typ/structure/heading.typ | 6 | ||||
| -rw-r--r-- | tests/typ/style/set.typ | 13 | ||||
| -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.typ | 45 | ||||
| -rw-r--r-- | tests/typ/style/show-recursive.typ | 23 | ||||
| -rw-r--r-- | tests/typ/style/show-text.typ | 32 | ||||
| -rw-r--r-- | tests/typ/text/code.typ | 1 |
18 files changed, 94 insertions, 78 deletions
diff --git a/tests/ref/style/set.png b/tests/ref/style/set.png Binary files differindex 502d74b5..6e154980 100644 --- a/tests/ref/style/set.png +++ b/tests/ref/style/set.png diff --git a/tests/ref/style/wrap.png b/tests/ref/style/show-bare.png Binary files differindex 7fb8dfc5..ff746d26 100644 --- a/tests/ref/style/wrap.png +++ b/tests/ref/style/show-bare.png diff --git a/tests/ref/text/code.png b/tests/ref/text/code.png Binary files differindex c4e94a73..e0387870 100644 --- a/tests/ref/text/code.png +++ b/tests/ref/text/code.png diff --git a/tests/src/tests.rs b/tests/src/tests.rs index 389938a4..aa9beaee 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -38,7 +38,7 @@ fn main() { // cache, a deterministic order is important for reproducibility. for entry in WalkDir::new("typ").sort_by_file_name() { let entry = entry.unwrap(); - if entry.depth() <= 1 { + if entry.depth() == 0 { continue; } diff --git a/tests/typ/base/eval.typ b/tests/typ/base/eval.typ index 86b1f0c4..668264d3 100644 --- a/tests/typ/base/eval.typ +++ b/tests/typ/base/eval.typ @@ -9,7 +9,7 @@ --- #set raw(around: none) -#show it: raw as text("IBM Plex Sans", eval(it.text)) +#show raw: it => text("IBM Plex Sans", eval(it.text)) Interacting ``` @@ -31,19 +31,18 @@ Blue #move(dy: -0.15em)[🌊] --- // Error: 23-30 cannot access file system from here -#show it: raw as eval(it.text) +#show raw: it => eval(it.text) ``` -#show strong as image("/res/tiger.jpg") -*No absolute tiger!* +#image("/res/tiger.jpg") ``` --- // Error: 23-30 cannot access file system from here -#show it: raw as eval(it.text) +#show raw: it => eval(it.text) ``` -#show emph as image("../../res/giraffe.jpg") +#show emph: _ => image("../../res/giraffe.jpg") _No relative giraffe!_ ``` diff --git a/tests/typ/code/break-continue.typ b/tests/typ/code/break-continue.typ index 2415cb8f..fb3222fa 100644 --- a/tests/typ/code/break-continue.typ +++ b/tests/typ/code/break-continue.typ @@ -116,7 +116,7 @@ // Everything should be in smallcaps. #for color in (red, blue, green, yellow) [ #set text("Roboto") - #wrap body in text(fill: color, body) + #show it => text(fill: color, it) #smallcaps(if color != green [ Some ] else [ diff --git a/tests/typ/code/field.typ b/tests/typ/code/field.typ index b63a8768..abea87fb 100644 --- a/tests/typ/code/field.typ +++ b/tests/typ/code/field.typ @@ -14,7 +14,7 @@ --- // Test field on node. -#show node: list as { +#show list: node => { test(node.items.len(), 3) } @@ -32,7 +32,7 @@ --- // Error: 29-32 unknown field "fun" -#show node: heading as node.fun +#show heading: node => node.fun = A --- diff --git a/tests/typ/code/import.typ b/tests/typ/code/import.typ index b554d6e7..5291af39 100644 --- a/tests/typ/code/import.typ +++ b/tests/typ/code/import.typ @@ -1,4 +1,4 @@ -// Test import statements. +// Test module imports. --- // Test importing semantics. diff --git a/tests/typ/code/include.typ b/tests/typ/code/include.typ index cd3328a2..e862adac 100644 --- a/tests/typ/code/include.typ +++ b/tests/typ/code/include.typ @@ -1,4 +1,4 @@ -// Test include statements. +// Test module includes. --- #set page(width: 200pt) diff --git a/tests/typ/graphics/shape-rect.typ b/tests/typ/graphics/shape-rect.typ index 7d110180..94686da2 100644 --- a/tests/typ/graphics/shape-rect.typ +++ b/tests/typ/graphics/shape-rect.typ @@ -47,10 +47,10 @@ --- // Outset padding. #set raw(lang: "rust") -#show node: raw as [ +#show raw: it => [ #set text(8pt) #h(5.6pt, weak: true) - #rect(radius: 3pt, outset: (y: 3pt, x: 2.5pt), fill: rgb(239, 241, 243), node) + #rect(radius: 3pt, outset: (y: 3pt, x: 2.5pt), fill: rgb(239, 241, 243), it) #h(5.6pt, weak: true) ] diff --git a/tests/typ/structure/desc.typ b/tests/typ/structure/desc.typ index e12bbd16..af1b2986 100644 --- a/tests/typ/structure/desc.typ +++ b/tests/typ/structure/desc.typ @@ -37,7 +37,7 @@ No: list \ --- // Test grid like show rule. -#show it: desc as table( +#show desc: it => table( columns: 2, padding: 3pt, ..it.items.map(item => (emph(item.term), item.body)).flatten(), diff --git a/tests/typ/structure/heading.typ b/tests/typ/structure/heading.typ index d37d8796..d08b3687 100644 --- a/tests/typ/structure/heading.typ +++ b/tests/typ/structure/heading.typ @@ -1,7 +1,7 @@ // Test headings. --- -#show node: heading as text(blue, node.body) +#show heading: it => text(blue, it.body) = No heading @@ -46,8 +46,8 @@ multiline. = Heading #set heading(family: "Roboto", fill: eastern) -#show it: heading as it.body -#show it: strong as it.body + [!] +#show heading: it => it.body +#show strong: it => it.body + [!] ===== Heading 🌍 #heading(level: 5)[Heading] 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. diff --git a/tests/typ/text/code.typ b/tests/typ/text/code.typ index 4230dd87..d89f1c05 100644 --- a/tests/typ/text/code.typ +++ b/tests/typ/text/code.typ @@ -7,6 +7,7 @@ #lorem(100) #let hi = "Hello World" +#show heading: emph ``` --- |
