summaryrefslogtreecommitdiff
path: root/tests/typ/code/closure.typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-07 23:31:42 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-08 11:52:09 +0100
commit75fffc1f9b6ef8bf258b2b1845a4ba74a0f5f2c1 (patch)
treee8c841d9d9323fc3cff0f584f3267743e809dd25 /tests/typ/code/closure.typ
parent95866d5fc9ae89a23c5754193c7de5d4fe4873b1 (diff)
Fine-grained capturing
Diffstat (limited to 'tests/typ/code/closure.typ')
-rw-r--r--tests/typ/code/closure.typ46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ
index 3b8b4261..14e74e7e 100644
--- a/tests/typ/code/closure.typ
+++ b/tests/typ/code/closure.typ
@@ -57,6 +57,52 @@
}
---
+// Import bindings.
+{
+ let b = "target.typ"
+ let f() = {
+ import b from b
+ b
+ }
+ test(f(), 1)
+}
+
+---
+// For loop bindings.
+{
+ let v = (1, 2, 3)
+ let s = 0
+ let f() = {
+ for v in v { s += v }
+ }
+ f()
+ test(s, 6)
+}
+
+---
+// Let + closure bindings.
+{
+ let g = "hi"
+ let f() = {
+ let g() = "bye"
+ g()
+ }
+ test(f(), "bye")
+}
+
+---
+// Parameter bindings.
+{
+ let x = 5
+ let g() = {
+ let f(x, y: x) = x + y
+ f
+ }
+
+ test(g()(8), 13)
+}
+
+---
// Don't leak environment.
{
// Error: 16-17 unknown variable