diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-04-13 10:39:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-13 08:39:45 +0000 |
| commit | 020294fca9a7065d4b9cf4e677f606ebaaa29b00 (patch) | |
| tree | c0027ad22046e2726c22298461327823d6b88d53 /tests/suite/scripting/recursion.typ | |
| parent | 72dd79210602ecc799726fc096b078afbb47f299 (diff) | |
Better test runner (#3922)
Diffstat (limited to 'tests/suite/scripting/recursion.typ')
| -rw-r--r-- | tests/suite/scripting/recursion.typ | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/suite/scripting/recursion.typ b/tests/suite/scripting/recursion.typ new file mode 100644 index 00000000..43fe848e --- /dev/null +++ b/tests/suite/scripting/recursion.typ @@ -0,0 +1,55 @@ +// Test recursive function calls. + +--- recursion-named --- +// Test with named function. +#let fib(n) = { + if n <= 2 { + 1 + } else { + fib(n - 1) + fib(n - 2) + } +} + +#test(fib(10), 55) + +--- recursion-unnamed-invalid --- +// Test with unnamed function. +// Error: 17-18 unknown variable: f +#let f = (n) => f(n - 1) +#f(10) + +--- recursion-named-returns-itself --- +// Test capturing with named function. +#let f = 10 +#let f() = f +#test(type(f()), function) + +--- recursion-unnamed-does-not-return-itself --- +// Test capturing with unnamed function. +#let f = 10 +#let f = () => f +#test(type(f()), int) + +--- recursion-shadowing --- +// Test redefinition. +#let f(x) = "hello" +#let f(x) = if x != none { f(none) } else { "world" } +#test(f(1), "world") + +--- recursion-maximum-depth --- +// Error: 15-21 maximum function call depth exceeded +#let rec(n) = rec(n) + 1 +#rec(1) + +--- recursion-via-include-in-layout --- +// Test cyclic imports during layout. +// Error: 2-38 maximum show rule depth exceeded +// Hint: 2-38 check whether the show rule matches its own output +#layout(_ => include "recursion.typ") + +--- recursion-show-math --- +// Test recursive show rules. +// Error: 22-25 maximum show rule depth exceeded +// Hint: 22-25 check whether the show rule matches its own output +#show math.equation: $x$ +$ x $ |
