diff options
Diffstat (limited to 'tests/typ/code/block.typ')
| -rw-r--r-- | tests/typ/code/block.typ | 143 |
1 files changed, 110 insertions, 33 deletions
diff --git a/tests/typ/code/block.typ b/tests/typ/code/block.typ index 8c30fa64..ac289abf 100644 --- a/tests/typ/code/block.typ +++ b/tests/typ/code/block.typ @@ -1,58 +1,135 @@ // Test code blocks. +// Ref: false --- -All none - -// Nothing evaluates to none. -{} +// Ref: true -// Let evaluates to none. -{ let v = 0 } +// Evaluates to join of none, [My ] and the two loop bodies. +{ + let parts = ("my fri", "end.") + [Hello, ] + for s in parts [{s}] +} -// Type is joined with trailing none, evaluates to string. +// Evaluates to join of the templates and strings. { - type("") - none + [How] + if true { + " are" + } + [ ] + if false [Nope] + [you] + "?" } --- +// Nothing evaluates to none. +#test({}, none) + +// Let evaluates to none. +#test({ let v = 0 }, none) + // Evaluates to single expression. -{ "Hello" } +#test({ "hello" }, "hello") // Evaluates to string. -{ let x = "Hel"; x + "lo" } +#test({ let x = "m"; x + "y" }, "my") + +// Evaluated to int. +#test({ + let x = 1 + let y = 2 + x + y +}, 3) + +// String is joined with trailing none, evaluates to string. +#test({ + type("") + none +}, "string") -// Evaluates to join of none, [He] and the two loop bodies. +--- +// Some things can't be joined. { - let parts = ("l", "lo") - [He] - for s in parts [{s}] + [A] + // Error: 5-6 cannot join template with integer + 1 + [B] } --- -// Evaluates to join of the templates and strings. +// Block in template does not create a scope. +{ let x = 1 } +#test(x, 1) + +--- +// Block in expression does create a scope. +#let a = { + let b = 1 + b +} + +#test(a, 1) + +// Error: 2-3 unknown variable +{b} + +--- +// Double block creates a scope. +{{ + import b from "target.typ" + test(b, 1) +}} + +// Error: 2-3 unknown variable +{b} + +--- +// Multiple nested scopes. { - [Hey, ] - if true { - "there!" + let a = "a1" + { + let a = "a2" + { + test(a, "a2") + let a = "a3" + test(a, "a3") + } + test(a, "a2") } - [ ] - if false [Nope] - [How are ] + "you?" + test(a, "a1") } +--- +// Multiple unseparated expressions in one line. + +// Error: 2-4 expected expression, found invalid token +{1u} + +// Should output `1`. +// Error: 3 expected semicolon or line break +{1 2} + +// Should output `2`. +// Error: 12 expected semicolon or line break +// Error: 22 expected semicolon or line break +{let x = -1 let y = 3 x + y} + +// Should output `3`. { - [A] - // Error: 5-6 cannot join template with integer - 1 - [B] + // Error: 9-12 expected identifier, found string + for "v" + + // Error: 10 expected keyword `in` + for v let z = 1 + 2 + + z } --- -// Works the same way in code environment. -// Ref: false -#test(3, { - let x = 1 - let y = 2 - x + y -}) +// Error: 2:1 expected closing brace +{ + +--- +// Error: 1-2 unexpected closing brace +} |
