diff options
| author | Sébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com> | 2024-11-26 21:51:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-26 20:51:46 +0000 |
| commit | 85d3a49a1a0bd50556b8b724a15aa29b074a2db7 (patch) | |
| tree | bbce57ce9e782d28ea10e148027aa25198958384 /tests/suite/scripting | |
| parent | 8fe8b2a23940f76077aa36eda305febd22e7cadc (diff) | |
Added warning when explicit return in code (not markup) discards joined content (#5413)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'tests/suite/scripting')
| -rw-r--r-- | tests/suite/scripting/return.typ | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/suite/scripting/return.typ b/tests/suite/scripting/return.typ index 63e1c0b9..5cb2d15a 100644 --- a/tests/suite/scripting/return.typ +++ b/tests/suite/scripting/return.typ @@ -85,3 +85,87 @@ // Error: 16-16 expected semicolon or line break #return a + b Hello World ] + +--- return-discard-content --- +// Test that discarding joined content is a warning. +#let f() = { + [Hello, World!] + // Warning: 3-16 this return unconditionally discards the content before it + // Hint: 3-16 try omitting the `return` to automatically join all values + return "nope" +} + +#test(f(), "nope") + +--- return-discard-content-nested --- +#let f() = { + [Hello, World!] + { + // Warning: 5-18 this return unconditionally discards the content before it + // Hint: 5-18 try omitting the `return` to automatically join all values + return "nope" + } +} + +#test(f(), "nope") + +--- return-discard-state --- +// Test that discarding a joined content with state is special warning + +#let f() = { + state("hello").update("world") + + // Warning: 3-19 this return unconditionally discards the content before it + // Hint: 3-19 try omitting the `return` to automatically join all values + // Hint: 3-19 state/counter updates are content that must end up in the document to have an effect + return [ Hello ] +} + +#test(f(), [ Hello ]) + +--- return-discard-loop --- +// Test that return from within a control flow construct is not a warning. +#let f1() = { + state("hello").update("world") + for x in range(3) { + return "nope1" + } +} + +#let f2() = { + state("hello").update("world") + let i = 0 + while i < 10 { + return "nope2" + } +} + +#test(f1(), "nope1") +#test(f2(), "nope2") + +--- return-no-discard --- +// Test that returning the joined content is not a warning. +#let f() = { + state("hello").update("world") + return +} + +#test(f(), state("hello").update("world")) + +--- return-discard-not-content --- +// Test that non-content joined value is not a warning. +#let f() = { + (33,) + return (66,) +} + +#test(f(), (66, )) + +--- return-discard-markup --- +// Test that discarding markup is not a warning. +#let f() = [ + hello + #return [nope] +] + +#test(f(), [nope]) |
