diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-20 21:33:13 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-20 21:33:13 +0100 |
| commit | 84ba547c7c80e45cc8edafcde8714973bb2a3a2f (patch) | |
| tree | e5b7eb97799def1907f9138cbe1fa001060c0196 /tests/lang | |
| parent | dd246e5bc944f90be7ba2981c2b73520a4bfbf45 (diff) | |
If expressions 🔀
Diffstat (limited to 'tests/lang')
| -rw-r--r-- | tests/lang/ref/if.png | bin | 0 -> 4352 bytes | |||
| -rw-r--r-- | tests/lang/ref/let.png | bin | 1563 -> 3347 bytes | |||
| -rw-r--r-- | tests/lang/typ/bracket-call.typ | 2 | ||||
| -rw-r--r-- | tests/lang/typ/headings.typ | 2 | ||||
| -rw-r--r-- | tests/lang/typ/if.typ | 66 | ||||
| -rw-r--r-- | tests/lang/typ/let.typ | 63 |
6 files changed, 102 insertions, 31 deletions
diff --git a/tests/lang/ref/if.png b/tests/lang/ref/if.png Binary files differnew file mode 100644 index 00000000..da99e185 --- /dev/null +++ b/tests/lang/ref/if.png diff --git a/tests/lang/ref/let.png b/tests/lang/ref/let.png Binary files differindex d9833391..4b8a1131 100644 --- a/tests/lang/ref/let.png +++ b/tests/lang/ref/let.png diff --git a/tests/lang/typ/bracket-call.typ b/tests/lang/typ/bracket-call.typ index 7bbaeac1..4b92a4b8 100644 --- a/tests/lang/typ/bracket-call.typ +++ b/tests/lang/typ/bracket-call.typ @@ -70,7 +70,7 @@ --- // Ref: false -// Error: 2:2-2:3 a value of type string is not callable +// Error: 2:2-2:3 expected function, found string #let x = "string" [x] diff --git a/tests/lang/typ/headings.typ b/tests/lang/typ/headings.typ index 765d0377..e63574ca 100644 --- a/tests/lang/typ/headings.typ +++ b/tests/lang/typ/headings.typ @@ -6,7 +6,7 @@ ###### Six // Too many hashtags. -// Warning: 1:1-1:8 section depth should not exceed 6 +// Warning: 1:1-1:8 should not exceed depth 6 ####### Seven --- diff --git a/tests/lang/typ/if.typ b/tests/lang/typ/if.typ new file mode 100644 index 00000000..5f4c986a --- /dev/null +++ b/tests/lang/typ/if.typ @@ -0,0 +1,66 @@ +#let x = true + +// The two different bodies. +#if true [_1_,] #if x {"2"} + +// Braced condition is fine. +#if {true} {"3"} + +// Newline between body and else-clause. +#if false [] +#else [4] + +// Multiline (condition needs parens because it's terminated by the line break, +// just like the right-hand side of a let-binding). +#if + x +{ + "Fi" + "ve" +} + +// Spacing is somewhat delicated. We only want to have spacing in the output if +// there was whitespace before/after the full if-else statement. In particular, +// spacing after a simple if should be retained, but spacing between the first +// body and the else should be ignored. +a#if true[b]c \ +a#if true[b] c \ +a #if true{"b"}c \ +a #if true{"b"} c \ +a#if false [?] #else [b]c \ +a#if true {"b"} #else {"?"} c \ + +// Body not evaluated at all if condition is false. +#if false { dont-care-about-undefined-variables } + +--- +#let x = true + +// Needs condition. +// Error: 1:6-1:7 expected expression, found closing brace +a#if } + +// Needs if-body. +// Error: 2:7-2:7 expected body +// Error: 1:16-1:16 expected body +a#if x b#if (x)c + +// Needs if-body expression. +// Error: 1:12-1:12 expected expression +a#if true {} + +// Needs else-body. +// Error: 1:20-1:20 expected body +a#if true [b] #else c + +// Lone else. +// Error: 2:1-2:6 unexpected else keyword +// Error: 1:8-1:8 expected function name +#else [] + +// Condition must be boolean. If it isn't, neither branch is evaluated. +// Error: 1:5-1:14 expected boolean, found string +#if "a" + "b" { "nope" } #else { "nope" } + +// No coercing from empty array or or stuff like that. +// Error: 1:5-1:7 expected boolean, found array +#if () { "nope" } #else { "nope" } diff --git a/tests/lang/typ/let.typ b/tests/lang/typ/let.typ index 28fc6649..3f8f5e0f 100644 --- a/tests/lang/typ/let.typ +++ b/tests/lang/typ/let.typ @@ -1,5 +1,3 @@ -// Ref: false - // Automatically initialized with `none`. #let x [eq x, none] @@ -8,46 +6,53 @@ #let y = 1 [eq y, 1] +// Initialize with template, not terminated by semicolon in template. +#let v = [Hello; there] + +// Not terminated by line break due to parens. +#let x = ( + 1, + 2, + 3, +) +[eq x, (1, 2, 3)] + // Multiple bindings in one line. #let x = "a"; #let y = "b"; [eq x + y, "ab"] -// No name. +// Invalid name. // Error: 1:6-1:7 expected identifier, found integer #let 1 ---- +// Terminated by end of line before binding name. +// Error: 1:5-1:5 expected identifier +#let +x = 5 + +// No name at all. +// Error: 1:11-1:11 expected identifier +The Fi#let;rst + // Terminated with just a line break. #let v = "a" -First -[eq v, "a"] - -// Terminated with just a semicolon. -#let v = "a"; Second -[eq v, "a"] +The Second [eq v, "a"] // Terminated with semicolon + line break. #let v = "a"; -Third -[eq v, "a"] +The Third [eq v, "a"] + +// Terminated with just a semicolon. +The#let v = "a"; Fourth [eq v, "a"] // Terminated by semicolon even though we are in a paren group. -// Error: 2:22-2:22 expected expression -// Error: 1:22-1:22 expected closing paren -#let array = (1, 2 + ;Fourth -[eq array, (1, 2)] +// Error: 2:25-2:25 expected expression +// Error: 1:25-1:25 expected closing paren +The#let array = (1, 2 + ;Fifth [eq array, (1, 2)] // Not terminated. -// Error: 1:14-1:20 expected semicolon or line break, found identifier -#let v = "a" Unseen Fifth -[eq v, "a"] +// Error: 1:16-1:16 expected semicolon or line break +The#let v = "a"Sixth [eq v, "a"] -// Not terminated by semicolon in template. -#let v = [Hello; there] - -// Not terminated by line break due to parens. -#let x = ( - 1, - 2, - 3, -) -[eq x, (1, 2, 3)] +// Not terminated. +// Error: 1:16-1:16 expected semicolon or line break +The#let v = "a" [eq v, "a"] Seventh |
