summaryrefslogtreecommitdiff
path: root/tests/typ/control
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-03 17:53:40 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-03 17:53:40 +0100
commitc94a18833f23d2b57de1b87971458fd54b56d088 (patch)
tree9e1ed55cfca15aef6d39ced50a3a5b14d2800aae /tests/typ/control
parent4d90a066f197264341eff6bf67e8c06cae434eb4 (diff)
Closures and function definitions 🚀
Supports: - Closure syntax: `(x, y) => z` - Shorthand for a single argument: `x => y` - Function syntax: `let f(x) = y` - Capturing of variables from the environment - Error messages for too few / many passed arguments Does not support: - Named arguments - Variadic arguments with `..`
Diffstat (limited to 'tests/typ/control')
-rw-r--r--tests/typ/control/for.typ3
-rw-r--r--tests/typ/control/let.typ26
-rw-r--r--tests/typ/control/while.typ3
3 files changed, 24 insertions, 8 deletions
diff --git a/tests/typ/control/for.typ b/tests/typ/control/for.typ
index 36bce447..5eaa6ae8 100644
--- a/tests/typ/control/for.typ
+++ b/tests/typ/control/for.typ
@@ -57,9 +57,6 @@
#test(type(for v in () []), "template")
---
-// Error: 14-19 unknown variable
-#let error = error
-
// Uniterable expression.
// Error: 11-15 cannot loop over boolean
#for v in true {}
diff --git a/tests/typ/control/let.typ b/tests/typ/control/let.typ
index 8df29b11..7752ec90 100644
--- a/tests/typ/control/let.typ
+++ b/tests/typ/control/let.typ
@@ -7,9 +7,31 @@
#let x
#test(x, none)
+// Error: 9 expected expression
+#let y =
+#test(y, none)
+
// Manually initialized with one.
-#let x = 1
-#test(x, 1)
+#let z = 1
+#test(z, 1)
+
+---
+// Syntax sugar for function definitions.
+#let background = #239dad
+#let box(body) = box(width: 2cm, height: 1cm, color: background, body)
+#box[Hi!]
+
+// Error: 13 expected body
+#let func(x)
+
+// Error: 2-6 unknown variable
+{func}
+
+// Error: 15 expected expression
+#let func(x) =
+
+// Error: 2-6 unknown variable
+{func}
---
// Termination.
diff --git a/tests/typ/control/while.typ b/tests/typ/control/while.typ
index 7ad70372..acf7951e 100644
--- a/tests/typ/control/while.typ
+++ b/tests/typ/control/while.typ
@@ -26,9 +26,6 @@
#test(type(while false []), "template")
---
-// Error: 14-19 unknown variable
-#let error = error
-
// Condition must be boolean.
// Error: 8-14 expected boolean, found template
#while [nope] [nope]