From 1927cc86dae1df300b3472c52f1777baf637dc6f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 9 May 2022 00:03:57 +0200 Subject: Set, show, wrap in code blocks --- tests/typ/code/break-continue.typ | 57 ++++++++++++++++++++++++++++++++++++--- tests/typ/code/return.typ | 35 +++++++++++++++++++++--- 2 files changed, 85 insertions(+), 7 deletions(-) (limited to 'tests/typ/code') 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) -- cgit v1.2.3