diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-05-18 00:36:11 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-05-18 00:36:11 +0200 |
| commit | 8b58171d7ca036d71b32749286c251cc91bdd10e (patch) | |
| tree | 4594ab5088edf8eec44f3bafe3fb8fecb13ac61b /tests/typ/control | |
| parent | 8d67c0ca5eb3486dde97fd281bd4a51d535c600c (diff) | |
Reorganize test cases
Diffstat (limited to 'tests/typ/control')
| -rw-r--r-- | tests/typ/control/for-pattern.typ | 35 | ||||
| -rw-r--r-- | tests/typ/control/for.typ | 71 | ||||
| -rw-r--r-- | tests/typ/control/if.typ | 71 | ||||
| -rw-r--r-- | tests/typ/control/invalid.typ | 100 | ||||
| -rw-r--r-- | tests/typ/control/let.typ | 63 | ||||
| -rw-r--r-- | tests/typ/control/while.typ | 43 |
6 files changed, 0 insertions, 383 deletions
diff --git a/tests/typ/control/for-pattern.typ b/tests/typ/control/for-pattern.typ deleted file mode 100644 index a6a7c16a..00000000 --- a/tests/typ/control/for-pattern.typ +++ /dev/null @@ -1,35 +0,0 @@ -// Test for loop patterns. -// Ref: false - ---- -#let out = () - -// Values of array. -#for v in (1, 2, 3) { - out += (v,) -} - -// Indices and values of array. -#for i, v in ("1", "2", "3") { - test(repr(i + 1), v) -} - -// Values of dictionary. -#for v in (a: 4, b: 5) { - out += (v,) -} - -// Keys and values of dictionary. -#for k, v in (a: 6, b: 7) { - out += (k,) - out += (v,) -} - -#test(out, (1, 2, 3, 4, 5, "a", 6, "b", 7)) - ---- -// Keys and values of strings. -// Error: 6-10 mismatched pattern -#for k, v in "hi" { - dont-care -} diff --git a/tests/typ/control/for.typ b/tests/typ/control/for.typ deleted file mode 100644 index bca1af46..00000000 --- a/tests/typ/control/for.typ +++ /dev/null @@ -1,71 +0,0 @@ -// Test for loops. - ---- -// Empty array. -#for x in () [Nope] - -// Array. -#let sum = 0 -#for x in (1, 2, 3, 4, 5) { - sum += x -} - -#test(sum, 15) - -// Dictionary is not traversed in insertion order. -// Should output `age: 1, name: Typst,`. -#for k, v in (Name: "Typst", Age: 2) [ - {k}: {v}. -] - -// String. -{ - let out = "" - let first = true - for c in "abc" { - if not first { - out += ", " - } - first = false - out += c - } - test(out, "a, b, c") -} - ---- -// Block body. -// Should output `[1st, 2nd, 3rd, 4th, 5th, 6th]`. -{ - "[" + for v in (1, 2, 3, 4, 5, 6) { - (if v > 1 [, ] - + [{v}] - + if v == 1 [st] - + if v == 2 [nd] - + if v == 3 [rd] - + if v >= 4 [th]) - } + "]" -} - -// Template body. -// Should output `234`. -#for v in (1, 2, 3, 4, 5, 6, 7) [#if v >= 2 and v <= 5 { repr(v) }] - ---- -// Value of for loops. -// Ref: false -#test(type(for v in () {}), "template") -#test(type(for v in () []), "template") - ---- -// Uniterable expression. -// Error: 11-15 cannot loop over boolean -#for v in true {} - -// Make sure that we don't complain twice. -// Error: 11-18 cannot add integer and string -#for v in 1 + "2" {} - -// A single error stops iteration. -#test(error, for v in (1, 2, 3) { - if v < 2 [Ok] else {error} -}) diff --git a/tests/typ/control/if.typ b/tests/typ/control/if.typ deleted file mode 100644 index 8d07e9b8..00000000 --- a/tests/typ/control/if.typ +++ /dev/null @@ -1,71 +0,0 @@ -// Test if-else expressions. - ---- -// Test condition evaluation. -#if 1 < 2 [ - One. -] - -#if true == false [ - {Bad}, but we {dont-care}! -] - ---- -// Braced condition. -#if {true} [ - One. -] - -// Template in condition. -#if [] != none [ - Two. -] - -// Multi-line condition with parens. -#if ( - 1 + 1 - == 1 -) [ - Nope. -] #else { - "Three." -} - -// Multiline. -#if false [ - Bad. -] #else { - let point = "." - "Four" + point -} - ---- -// Value of if expressions. -// Ref: false -{ - let x = 1 - let y = 2 - let z - - // Returns if branch. - z = if x < y { "ok" } - test(z, "ok") - - // Returns else branch. - z = if x > y { "bad" } else { "ok" } - test(z, "ok") - - // Missing else evaluates to none. - z = if x > y { "bad" } - test(z, none) -} - ---- -// Condition must be boolean. -// If it isn't, neither branch is evaluated. -// Error: 5-14 expected boolean, found string -#if "a" + "b" { nope } #else { nope } - -// Make sure that we don't complain twice. -// Error: 5-12 cannot add integer and string -#if 1 + "2" {} diff --git a/tests/typ/control/invalid.typ b/tests/typ/control/invalid.typ deleted file mode 100644 index 49158a68..00000000 --- a/tests/typ/control/invalid.typ +++ /dev/null @@ -1,100 +0,0 @@ -// Test invalid control syntax. - ---- -// Error: 5 expected identifier -#let - -// Error: 5 expected identifier -{let} - -// Error: 6-9 expected identifier, found string -#let "v" - -// Should output `1`. -// Error: 7 expected semicolon or line break -#let v 1 - -// Error: 9 expected expression -#let v = - -// Should output `= 1`. -// Error: 6-9 expected identifier, found string -#let "v" = 1 - ---- -// Error: 4 expected expression -#if - -// Error: 4 expected expression -{if} - -// Error: 6 expected body -#if x - -// Error: 1-6 unexpected keyword `else` -#else {} - -// Should output `x`. -// Error: 4 expected expression -#if -x {} - -// Should output `something`. -// Error: 6 expected body -#if x something - -// Should output `A thing.` -// Error: 20 expected body -A#if false {} #else thing - ---- -// Error: 7 expected expression -#while - -// Error: 7 expected expression -{while} - -// Error: 9 expected body -#while x - -// Should output `x`. -// Error: 7 expected expression -#while -x {} - -// Should output `something`. -// Error: 9 expected body -#while x something - ---- -// Error: 5 expected identifier -#for - -// Error: 5 expected identifier -{for} - -// Error: 7 expected keyword `in` -#for v - -// Error: 10 expected expression -#for v in - -// Error: 15 expected body -#for v in iter - -// Should output `v in iter`. -// Error: 5 expected identifier -#for -v in iter {} - -// Should output `A thing`. -// Error: 7-10 expected identifier, found string -A#for "v" thing - -// Should output `in iter`. -// Error: 6-9 expected identifier, found string -#for "v" in iter {} - -// Should output `+ b in iter`. -// Error: 7 expected keyword `in` -#for a + b in iter {} diff --git a/tests/typ/control/let.typ b/tests/typ/control/let.typ deleted file mode 100644 index 4f84aa67..00000000 --- a/tests/typ/control/let.typ +++ /dev/null @@ -1,63 +0,0 @@ -// Test let bindings. - ---- -// Ref: false - -// Automatically initialized with none. -#let x -#test(x, none) - -// Error: 9 expected expression -#let y = -#test(y, none) - -// Manually initialized with one. -#let z = 1 -#test(z, 1) - ---- -// Syntax sugar for function definitions. -#let background = #9feb52 -#let rect(body) = rect(width: 2cm, fill: background, pad(5pt, body)) -#rect[Hi!] - -// Error: 13 expected body -#let func(x) - -// Error: 2-6 unknown variable -{func} - -// Error: 15 expected expression -#let func(x) = - -// Error: 2-6 unknown variable -{func} - ---- -// Termination. - -// Terminated by line break. -#let v1 = 1 -One - -// Terminated by semicolon. -#let v2 = 2; Two - -// Terminated by semicolon and line break. -#let v3 = 3; -Three - -// Terminated because expression ends. -// Error: 12 expected semicolon or line break -#let v4 = 4 Four - -// Terminated by semicolon even though we are in a paren group. -// Error: 2:19 expected expression -// Error: 1:19 expected closing paren -#let v5 = (1, 2 + ; Five - -#test(v1, 1) -#test(v2, 2) -#test(v3, 3) -#test(v4, 4) -#test(v5, (1, 2)) diff --git a/tests/typ/control/while.typ b/tests/typ/control/while.typ deleted file mode 100644 index acf7951e..00000000 --- a/tests/typ/control/while.typ +++ /dev/null @@ -1,43 +0,0 @@ -// Test while expressions. - ---- -// Should output `2 4 6 8 10`. -#let i = 0 -#while i < 10 [ - { i += 2 } - #i -] - -// Should output `Hi`. -#let iter = true -#while iter { - iter = false - "Hi." -} - -#while false { - dont-care -} - ---- -// Value of while loops. -// Ref: false -#test(type(while false {}), "template") -#test(type(while false []), "template") - ---- -// Condition must be boolean. -// Error: 8-14 expected boolean, found template -#while [nope] [nope] - -// Make sure that we don't complain twice. -// Error: 8-15 unknown variable -#while nothing {} - -// A single error stops iteration. -#let i = 0 -#test(error, while i < 10 { - i += 1 - if i < 5 [nope] else { error } -}) -#test(i, 5) |
