From 75fffc1f9b6ef8bf258b2b1845a4ba74a0f5f2c1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 7 Nov 2021 23:31:42 +0100 Subject: Fine-grained capturing --- tests/typ/code/closure.typ | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/typ/code') 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 @@ -56,6 +56,52 @@ test(f(), 3) } +--- +// 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. { -- cgit v1.2.3