summaryrefslogtreecommitdiff
path: root/tests/typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-09 00:03:57 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-09 00:03:57 +0200
commit1927cc86dae1df300b3472c52f1777baf637dc6f (patch)
treefb156dd4c1a73d2f6880d10e53dd4f1b911fbd95 /tests/typ
parentbfaf5447a789cd0dbbb1e418bea62fef9edc2b7d (diff)
Set, show, wrap in code blocks
Diffstat (limited to 'tests/typ')
-rw-r--r--tests/typ/code/break-continue.typ57
-rw-r--r--tests/typ/code/return.typ35
-rw-r--r--tests/typ/style/set.typ14
-rw-r--r--tests/typ/style/show-node.typ31
-rw-r--r--tests/typ/style/wrap.typ11
5 files changed, 135 insertions, 13 deletions
diff --git a/tests/typ/code/break-continue.typ b/tests/typ/code/break-continue.typ
index 60dac44d..02c221a4 100644
--- a/tests/typ/code/break-continue.typ
+++ b/tests/typ/code/break-continue.typ
@@ -66,13 +66,28 @@
---
// Test break outside of loop.
-
#let f() = {
// Error: 3-8 cannot break outside of loop
break
}
-#f()
+#for i in range(1) {
+ f()
+}
+
+---
+// Test break in function call.
+#let identity(x) = x
+#let out = for i in range(5) {
+ "A"
+ identity({
+ "B"
+ break
+ })
+ "C"
+}
+
+#test(out, "AB")
---
// Test continue outside of loop.
@@ -81,5 +96,41 @@
#let x = { continue }
---
-// Error: 1-10 unexpected keyword `continue`
+// Error: 1-10 cannot continue outside of loop
#continue
+
+---
+// Ref: true
+// Should output `Hello World 🌎`.
+#for _ in range(10) {
+ [Hello ]
+ [World {
+ [🌎]
+ break
+ }]
+}
+
+---
+// Ref: true
+// Should output `Some` in red, `Some` in blue and `Last` in green.
+// Everything should be in smallcaps.
+#for color in (red, blue, green, yellow) [
+ #set text("Roboto")
+ #wrap body in text(fill: color, body)
+ #smallcaps(if color != green [
+ Some
+ ] else [
+ Last
+ #break
+ ])
+]
+
+---
+// Ref: true
+// Test break in set rule.
+// Should output `Hi` in blue.
+#for i in range(10) {
+ [Hello]
+ set text(blue, ..break)
+ [Not happening]
+}
diff --git a/tests/typ/code/return.typ b/tests/typ/code/return.typ
index d3016444..8db99a81 100644
--- a/tests/typ/code/return.typ
+++ b/tests/typ/code/return.typ
@@ -35,10 +35,7 @@
#let f(text, caption: none) = {
text
- if caption == none {
- [\.]
- return
- }
+ if caption == none [\.#return]
[, ]
emph(caption)
[\.]
@@ -55,3 +52,33 @@
// Error: 3-9 cannot return outside of function
return
}
+
+---
+// Test that the expression is evaluated to the end.
+#let y = 1
+#let identity(x, ..rest) = x
+#let f(x) = {
+ identity(
+ ..return,
+ x + 1,
+ y = 2,
+ )
+ "nope"
+}
+
+#test(f(1), 2)
+#test(y, 2)
+
+---
+// Test value return from content.
+#let x = 3
+#let f() = [
+ Hello 😀
+ { x = 1 }
+ #return "nope"
+ { x = 2 }
+ World
+]
+
+#test(f(), "nope")
+#test(x, 1)
diff --git a/tests/typ/style/set.typ b/tests/typ/style/set.typ
index 24966612..2c12d3e9 100644
--- a/tests/typ/style/set.typ
+++ b/tests/typ/style/set.typ
@@ -27,5 +27,15 @@ Hello *{x}*
#text(fill: forest, x)
---
-// Error: 2-10 set, show and wrap are only allowed directly in markup
-{set f(x)}
+// Test that scoping works as expected.
+{
+ if true {
+ set text(blue)
+ [Blue ]
+ }
+ [Not blue]
+}
+
+---
+// Error: 11-25 set is only allowed directly in code and content blocks
+{ let x = set text(blue) }
diff --git a/tests/typ/style/show-node.typ b/tests/typ/style/show-node.typ
index d0586c9d..678ff151 100644
--- a/tests/typ/style/show-node.typ
+++ b/tests/typ/style/show-node.typ
@@ -49,6 +49,33 @@ Some more text.
Another text.
---
+// Test set and show in code blocks.
+#show node: heading as {
+ set text(red)
+ show "ding" as [🛎]
+ node.body
+}
+
+= Heading
+
+---
+// Test that scoping works as expected.
+{
+ let world = [ World ]
+ show c: "W" as strong(c)
+ world
+ {
+ set text(blue)
+ wrap it in {
+ show "o" as "Ø"
+ it
+ }
+ world
+ }
+ world
+}
+
+---
// Error: 18-22 expected content, found integer
#show heading as 1234
= Heading
@@ -67,5 +94,5 @@ Another text.
#show red as []
---
-// Error: 2-16 set, show and wrap are only allowed directly in markup
-{show list as a}
+// Error: 7-27 show is only allowed directly in code and content blocks
+{ 1 + show heading as none }
diff --git a/tests/typ/style/wrap.typ b/tests/typ/style/wrap.typ
index 2a9074cb..57f21f99 100644
--- a/tests/typ/style/wrap.typ
+++ b/tests/typ/style/wrap.typ
@@ -25,5 +25,12 @@ A [_B #wrap c in [*#c*]; C_] D
Forest
---
-// Error: 6-17 set, show and wrap are only allowed directly in markup
-{1 + wrap x in y}
+{
+ // Error: 3-24 expected remaining block to yield content, found integer
+ wrap body in 2 * body
+ 2
+}
+
+---
+// Error: 4-18 wrap is only allowed directly in code and content blocks
+{ (wrap body in 2) * body }