From 1ee1d078e2480ddd08d40915bc7a74a8352acff0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 30 Jul 2021 18:04:08 +0200 Subject: Fatal errors - Makes errors fatal, so that a phase is only reached when all previous phases were error-free - Parsing still recovers and can produce multiple errors - Evaluation fails fast and can thus produce only a single error (except for parse errors due to an import) - The single error that could occur during execution is removed for now - Removes Value::Error variant --- tests/typ/code/array.typ | 1 + tests/typ/code/block-invalid.typ | 38 ---------- tests/typ/code/block-scoping.typ | 45 ----------- tests/typ/code/block.typ | 143 +++++++++++++++++++++++++++-------- tests/typ/code/call-invalid.typ | 39 ---------- tests/typ/code/call-wide.typ | 40 ---------- tests/typ/code/call.typ | 128 ++++++++++++++++++++++--------- tests/typ/code/closure.typ | 31 +++++--- tests/typ/code/for-pattern.typ | 35 --------- tests/typ/code/for.typ | 91 ++++++++++++---------- tests/typ/code/if.typ | 10 ++- tests/typ/code/import.typ | 27 ++++--- tests/typ/code/importable/cycle1.typ | 1 - tests/typ/code/importable/cycle2.typ | 1 - tests/typ/code/include.typ | 13 ++-- tests/typ/code/let.typ | 48 ++++-------- tests/typ/code/ops-invalid.typ | 39 +++++++--- tests/typ/code/repr.typ | 3 - tests/typ/code/while.typ | 21 ++--- 19 files changed, 354 insertions(+), 400 deletions(-) delete mode 100644 tests/typ/code/block-invalid.typ delete mode 100644 tests/typ/code/block-scoping.typ delete mode 100644 tests/typ/code/call-invalid.typ delete mode 100644 tests/typ/code/call-wide.typ delete mode 100644 tests/typ/code/for-pattern.typ (limited to 'tests/typ/code') diff --git a/tests/typ/code/array.typ b/tests/typ/code/array.typ index 9e14bf16..fc8795c2 100644 --- a/tests/typ/code/array.typ +++ b/tests/typ/code/array.typ @@ -18,6 +18,7 @@ , rgb("002") ,)} +--- // Error: 3 expected closing paren {(} diff --git a/tests/typ/code/block-invalid.typ b/tests/typ/code/block-invalid.typ deleted file mode 100644 index 01df81d5..00000000 --- a/tests/typ/code/block-invalid.typ +++ /dev/null @@ -1,38 +0,0 @@ -// Test invalid code block syntax. - ---- -// Multiple unseparated expressions in one line. - -// Error: 2-4 expected expression, found invalid token -{1u} - -// Should output `1`. -// Error: 3 expected semicolon or line break -// Error: 4-5 cannot join integer with integer -{1 2} - -// Should output `2`. -// Error: 12 expected semicolon or line break -// Error: 22 expected semicolon or line break -{let x = -1 let y = 3 x + y} - -// Should output `3`. -{ - // Error: 9-12 expected identifier, found string - for "v" - - // Error: 10 expected keyword `in` - for v let z = 1 + 2 - - z -} - ---- -// Ref: false -// Error: 2:1 expected closing brace -{ - ---- -// Ref: false -// Error: 1-2 unexpected closing brace -} diff --git a/tests/typ/code/block-scoping.typ b/tests/typ/code/block-scoping.typ deleted file mode 100644 index 7970ee1b..00000000 --- a/tests/typ/code/block-scoping.typ +++ /dev/null @@ -1,45 +0,0 @@ -// Test scoping with blocks. -// Ref: false - ---- -// Block in template does not create a scope. -{ let x = 1 } -#test(x, 1) - ---- -// Block in expression does create a scope. -#let a = { - let b = 1 - b -} - -#test(a, 1) - -// Error: 2-3 unknown variable -{b} - ---- -// Double block creates a scope. -{{ - import b from "target.typ" - test(b, 1) -}} - -// Error: 2-3 unknown variable -{b} - ---- -// Multiple nested scopes. -{ - let a = "a1" - { - let a = "a2" - { - test(a, "a2") - let a = "a3" - test(a, "a3") - } - test(a, "a2") - } - test(a, "a1") -} diff --git a/tests/typ/code/block.typ b/tests/typ/code/block.typ index 8c30fa64..ac289abf 100644 --- a/tests/typ/code/block.typ +++ b/tests/typ/code/block.typ @@ -1,58 +1,135 @@ // Test code blocks. +// Ref: false --- -All none - -// Nothing evaluates to none. -{} +// Ref: true -// Let evaluates to none. -{ let v = 0 } +// Evaluates to join of none, [My ] and the two loop bodies. +{ + let parts = ("my fri", "end.") + [Hello, ] + for s in parts [{s}] +} -// Type is joined with trailing none, evaluates to string. +// Evaluates to join of the templates and strings. { - type("") - none + [How] + if true { + " are" + } + [ ] + if false [Nope] + [you] + "?" } --- +// Nothing evaluates to none. +#test({}, none) + +// Let evaluates to none. +#test({ let v = 0 }, none) + // Evaluates to single expression. -{ "Hello" } +#test({ "hello" }, "hello") // Evaluates to string. -{ let x = "Hel"; x + "lo" } +#test({ let x = "m"; x + "y" }, "my") + +// Evaluated to int. +#test({ + let x = 1 + let y = 2 + x + y +}, 3) + +// String is joined with trailing none, evaluates to string. +#test({ + type("") + none +}, "string") -// Evaluates to join of none, [He] and the two loop bodies. +--- +// Some things can't be joined. { - let parts = ("l", "lo") - [He] - for s in parts [{s}] + [A] + // Error: 5-6 cannot join template with integer + 1 + [B] } --- -// Evaluates to join of the templates and strings. +// Block in template does not create a scope. +{ let x = 1 } +#test(x, 1) + +--- +// Block in expression does create a scope. +#let a = { + let b = 1 + b +} + +#test(a, 1) + +// Error: 2-3 unknown variable +{b} + +--- +// Double block creates a scope. +{{ + import b from "target.typ" + test(b, 1) +}} + +// Error: 2-3 unknown variable +{b} + +--- +// Multiple nested scopes. { - [Hey, ] - if true { - "there!" + let a = "a1" + { + let a = "a2" + { + test(a, "a2") + let a = "a3" + test(a, "a3") + } + test(a, "a2") } - [ ] - if false [Nope] - [How are ] + "you?" + test(a, "a1") } +--- +// Multiple unseparated expressions in one line. + +// Error: 2-4 expected expression, found invalid token +{1u} + +// Should output `1`. +// Error: 3 expected semicolon or line break +{1 2} + +// Should output `2`. +// Error: 12 expected semicolon or line break +// Error: 22 expected semicolon or line break +{let x = -1 let y = 3 x + y} + +// Should output `3`. { - [A] - // Error: 5-6 cannot join template with integer - 1 - [B] + // Error: 9-12 expected identifier, found string + for "v" + + // Error: 10 expected keyword `in` + for v let z = 1 + 2 + + z } --- -// Works the same way in code environment. -// Ref: false -#test(3, { - let x = 1 - let y = 2 - x + y -}) +// Error: 2:1 expected closing brace +{ + +--- +// Error: 1-2 unexpected closing brace +} diff --git a/tests/typ/code/call-invalid.typ b/tests/typ/code/call-invalid.typ deleted file mode 100644 index dd5897b8..00000000 --- a/tests/typ/code/call-invalid.typ +++ /dev/null @@ -1,39 +0,0 @@ -// Test invalid function calls. - ---- -// Error: 7-8 expected expression, found colon -#args(:) - -// Error: 10-12 expected expression, found end of block comment -#args(a:1*/) - -// Error: 8 expected comma -#args(1 2) - -// Error: 7-8 expected identifier -// Error: 9 expected expression -#args(1:) - -// Error: 7-8 expected identifier -#args(1:2) - -// Error: 7-10 expected identifier -{args((x):1)} - ---- -#let x = "string" - -// Error: 1-3 expected function, found string -#x() - -// Error: 2:1 expected closing bracket -#args[`a]` - ---- -// Error: 7 expected closing paren -{args(} - ---- -// Error: 2:1 expected quote -// Error: 2:1 expected closing paren -#args("] diff --git a/tests/typ/code/call-wide.typ b/tests/typ/code/call-wide.typ deleted file mode 100644 index 1ad4995d..00000000 --- a/tests/typ/code/call-wide.typ +++ /dev/null @@ -1,40 +0,0 @@ -// Test wide calls. - ---- -// Test multiple wide calls in separate expressions. -#font!(fill: eastern) - First -#font!(fill: forest) - Second - ---- -// Test in heading. -= A #align!(right) B -C - ---- -// Test evaluation semantics. - -#let x = 1 -#let f(x, body) = (x, body) -#f!(x) -{ x = 2 } - ---- -// Test multiple wide calls in one expression. -// Ref: false - -#let f() = [] -#let g(x, y) = [] - -// Error: 2-4 wide calls are only allowed directly in templates -{f!()} - -// Test nested wide calls. -// Error: 5-7 wide calls are only allowed directly in templates -#g!(f!()) - ---- -// Test missing parentheses. -// Ref: false - -// Error: 4 expected argument list -#f! diff --git a/tests/typ/code/call.typ b/tests/typ/code/call.typ index eb5c6732..28ce860c 100644 --- a/tests/typ/code/call.typ +++ b/tests/typ/code/call.typ @@ -1,34 +1,64 @@ // Test function calls. +// Ref: false --- -// One argument. -#args(bold) +// Ref: true -// One argument and trailing comma. -#args(1,) +// Ommitted space. +#font(weight:bold)[Bold] -// One named argument. -#args(a:2) +// Call return value of function with body. +#let f(x, body) = (y) => [#x] + body + [#y] +#f(1)[2](3) -// Mixed arguments. -{args(1, b: "2", 3)} +// Don't parse this as a function. +// Should output ` (it)`. +#test (it) -// Should output `() + 2`. -#args() + 2 +#let f(body) = body +#f[A] +#f()[A] +#f([A]) --- -// Ref: false +// Ref: true + +// Test multiple wide calls in separate expressions inside a template. +[ + #font!(fill: eastern) - First + #font!(fill: forest) - Second +] + +// Test wide call in heading. += A #align!(right) B +C + +--- +// Test wide call in expression. + +// Error: 2-4 wide calls are only allowed directly in templates +{f!()} + +// Error: 5-7 wide calls are only allowed directly in templates +#g!(f!()) + +--- +// Test wide call evaluation semantics. +#let x = 1 +#let f(x, body) = test(x, 1) +#f!(x) +{ x = 2 } + +--- +// Trailing comma. +#test(1 + 1, 2,) // Call function assigned to variable. #let alias = type #test(alias(alias), "function") ---- // Callee expressions. { - // Error: 5-9 expected function, found boolean - true() - // Wrapped in parens. test((type)("hi"), "string") @@ -37,30 +67,60 @@ test(adder(2)(5), 7) } -#let f(x, body) = (y) => { - [{x}] + body + [{y}] -} - -// Call return value of function with body. -#f(1)[2](3) +--- +// Error: 2-6 expected function, found boolean +{true()} -// Don't allow this to be a closure. -// Should output `x => "hi"`. +--- #let x = "x" -#x => "hi" + +// Error: 1-3 expected function, found string +#x() + +--- +#let f(x) = x + +// Error: 1-6 expected function, found integer +#f(1)(2) + +--- +#let f(x) = x + +// Error: 1-6 expected function, found template +#f[1](2) --- -// Different forms of template arguments. +// Error: 7 expected argument list +#func! + +// Error: 7-8 expected expression, found colon +#func(:) + +// Error: 10-12 expected expression, found end of block comment +#func(a:1*/) -#let a = "a" +// Error: 8 expected comma +#func(1 2) -#args(a) \ -#args[a] \ -#args(a, [b]) +// Error: 7-8 expected identifier +// Error: 9 expected expression +#func(1:) -// Template can be argument or body depending on whitespace. -#if "template" == type[b] [Sure ] -#if "template" == type [Nope.] #else [thing.] +// Error: 7-8 expected identifier +#func(1:2) -// Should output ` (Okay.)`. -#args (Okay.) +// Error: 7-10 expected identifier +{func((x):1)} + +--- +// Error: 2:1 expected closing bracket +#func[`a]` + +--- +// Error: 7 expected closing paren +{func(} + +--- +// Error: 2:1 expected quote +// Error: 2:1 expected closing paren +#func("] diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ index 20a5f18d..75241f32 100644 --- a/tests/typ/code/closure.typ +++ b/tests/typ/code/closure.typ @@ -2,13 +2,22 @@ // Ref: false --- +// Don't parse closure directly in template. +// Ref: true +#let x = "\"hi\"" + +// Should output `"hi" => "bye"`. +#x => "bye" + +--- // Basic closure without captures. { let adder = (x, y) => x + y test(adder(2, 3), 5) } +--- // Pass closure as argument and return closure. // Also uses shorthand syntax for a single argument. { @@ -19,6 +28,7 @@ test(h(2), 5) } +--- // Capture environment. { let mark = "?" @@ -35,15 +45,7 @@ test(greet("Typst"), "Hi, Typst!") } -// Don't leak environment. -{ - // Error: 18-19 unknown variable - let func() = x - let x = "hi" - - test(func(), error) -} - +--- // Redefined variable. { let x = 1 @@ -54,6 +56,15 @@ test(f(), 3) } +--- +// Don't leak environment. +{ + // Error: 18-19 unknown variable + let func() = x + let x = "hi" + func() +} + --- // Too few arguments. { @@ -64,11 +75,11 @@ test(types("nope"), "[string, none]") } +--- // Too many arguments. { let f(x) = x + 1 // Error: 10-15 unexpected argument - // Error: 17-24 unexpected argument f(1, "two", () => x) } diff --git a/tests/typ/code/for-pattern.typ b/tests/typ/code/for-pattern.typ deleted file mode 100644 index a6a7c16a..00000000 --- a/tests/typ/code/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/code/for.typ b/tests/typ/code/for.typ index e6bcf269..62cb0bb5 100644 --- a/tests/typ/code/for.typ +++ b/tests/typ/code/for.typ @@ -1,42 +1,23 @@ // Test for loops. +// Ref: false --- +// Ref: true + // 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,`. +// Should output `Age: 2. Name: Typst.`. #for k, v in (Name: "Typst", Age: 2) [ {k}: {v}. ] -// String. -{ - let first = true - let out = for c in "abc" { - if not first { - ", " - } - c - first = false - } - test(out, "a, b, c") -} - ---- // Block body. -// Should output `[1st, 2nd, 3rd, 4th, 5th, 6th]`. +// Should output `[1st, 2nd, 3rd, 4th, 5th]`. { "[" - for v in (1, 2, 3, 4, 5, 6) { + for v in (1, 2, 3, 4, 5) { if v > 1 [, ] [#v] if v == 1 [st] @@ -48,30 +29,60 @@ } // Template body. -// Should output `234`. +// Should output `2345`. #for v in (1, 2, 3, 4, 5, 6, 7) [#if v >= 2 and v <= 5 { repr(v) }] --- -// Value of for loops. -// 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)) + +// Chars of string. +#let first = true +#let joined = for c in "abc" { + if not first { ", " } + first = false + c +} + +#test(joined, "a, b, c") + +// Return value. #test(for v in "" [], none) #test(type(for v in "1" []), "template") --- -// Ref: false - // 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" {} - -// Errors taint everything. -#test(error, for v in (1, 2, 3) { - if v < 2 [Ok] else {error} -}) +--- +// Keys and values of strings. +// Error: 6-10 mismatched pattern +#for k, v in "hi" { + dont-care +} --- // Error: 5 expected identifier @@ -89,19 +100,15 @@ // 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/code/if.typ b/tests/typ/code/if.typ index dd5d23a0..db8b059e 100644 --- a/tests/typ/code/if.typ +++ b/tests/typ/code/if.typ @@ -39,9 +39,16 @@ "Four" + point } +// Template can be argument or body depending on whitespace. +{ + if "template" == type[b] [Fi] else [Nope] + if "template" == type [Nope] else [ve.] +} + --- // Value of if expressions. // Ref: false + { let x = 1 let y = 2 @@ -61,13 +68,12 @@ } --- -// Ref: false - // 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/code/import.typ b/tests/typ/code/import.typ index e1af8ceb..93d4d168 100644 --- a/tests/typ/code/import.typ +++ b/tests/typ/code/import.typ @@ -11,8 +11,7 @@ #let value = [foo] // Import multiple things. -// Error: 9-10 expected expression, found comma -#import ,fn, value from "target.typ" +#import fn, value from "target.typ" #fn[Like and Subscribe!] #value @@ -24,10 +23,6 @@ #test(b, 1) -// This should not exist yet -// Error: 1-3 unknown variable -#d - // A wildcard import. #import * from "target.typ" @@ -45,30 +40,35 @@ #import a, c, from "target.typ" --- -// Test bad imports. -// Ref: false - // Error: 19-21 file not found #import name from "" +--- // Error: 16-27 file not found #import * from "lib/0.2.1" +--- // Some non-text stuff. // Error: 16-37 file is not valid utf-8 #import * from "../../res/rhino.png" +--- // Unresolved import. // Error: 9-21 unresolved import #import non_existing from "target.typ" -// Cyclic import. -// Error: 16-41 cyclic import -#import * from "./importable/cycle1.typ" +--- +// Cyclic import of this very file. +// Error: 16-30 cyclic import +#import * from "./import.typ" --- -// Test bad syntax. +// Cyclic import in other file. +#import * from "./importable/cycle1.typ" +This is never reached. + +--- // Error: 8 expected import items // Error: 8 expected keyword `from` #import @@ -100,7 +100,6 @@ #from "target.typ" // Should output `target`. -// Error: 1:16-2:2 file not found // Error: 2:2 expected semicolon or line break #import * from "target.typ "target diff --git a/tests/typ/code/importable/cycle1.typ b/tests/typ/code/importable/cycle1.typ index ae755fa0..a9c00f5e 100644 --- a/tests/typ/code/importable/cycle1.typ +++ b/tests/typ/code/importable/cycle1.typ @@ -1,6 +1,5 @@ // Ref: false -// Error: 16-28 cyclic import #import * from "cycle2.typ" #let inaccessible = "wow" diff --git a/tests/typ/code/importable/cycle2.typ b/tests/typ/code/importable/cycle2.typ index d4f94564..204da519 100644 --- a/tests/typ/code/importable/cycle2.typ +++ b/tests/typ/code/importable/cycle2.typ @@ -1,6 +1,5 @@ // Ref: false -// Error: 16-28 cyclic import #import * from "cycle1.typ" #let val = "much cycle" diff --git a/tests/typ/code/include.typ b/tests/typ/code/include.typ index 166c3945..0d1abc08 100644 --- a/tests/typ/code/include.typ +++ b/tests/typ/code/include.typ @@ -6,18 +6,21 @@ // Include a file #include "importable/chap1.typ" -// The variables of the file should not appear in this scope. -// Error: 1-6 unknown variable -#name - // Expression as a file name. #let chap2 = include "import" + "able/chap" + "2.typ" -- _Intermission_ -- #chap2 +--- { - // Expressions, code mode. // Error: 21-43 file not found let x = include "importable/chap3.typ" } + +--- +#include "importable/chap1.typ" + +// The variables of the file should not appear in this scope. +// Error: 1-6 unknown variable +#name diff --git a/tests/typ/code/let.typ b/tests/typ/code/let.typ index 9079b541..3f3f9d35 100644 --- a/tests/typ/code/let.typ +++ b/tests/typ/code/let.typ @@ -1,38 +1,19 @@ // 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 fill = conifer #let rect(body) = rect(width: 2cm, fill: fill, 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. @@ -47,20 +28,9 @@ One #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: 19 expected expression -// Error: 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)) --- // Error: 5 expected identifier @@ -72,13 +42,27 @@ Three // 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 a heading `1`. // Error: 6-9 expected identifier, found string #let "v" = 1 + +// 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: 19 expected expression +// Error: 19 expected closing paren +#let v5 = (1, 2 + ; Five + +--- +// Error: 13 expected body +#let func(x) + +// Error: 15 expected expression +#let func(x) = diff --git a/tests/typ/code/ops-invalid.typ b/tests/typ/code/ops-invalid.typ index 149a60dd..5e56ff98 100644 --- a/tests/typ/code/ops-invalid.typ +++ b/tests/typ/code/ops-invalid.typ @@ -1,67 +1,84 @@ -// Test invalid expressions. +// Test invalid operations. // Ref: false --- -// Missing expressions. - // Error: 3 expected expression {-} +--- // Error: 10 expected expression #test({1+}, 1) +--- // Error: 10 expected expression #test({2*}, 2) --- -// Mismatched types. - // Error: 2-12 cannot apply '+' to template {+([] + [])} +--- // Error: 2-5 cannot apply '-' to string {-""} +--- // Error: 2-8 cannot apply 'not' to array {not ()} +--- // Error: 2-12 cannot apply '<=' to relative and relative {30% <= 40%} +--- // Special messages for +, -, * and /. // Error: 03-10 cannot add integer and string +{(1 + "2", 40% - 1)} + +--- // Error: 12-19 cannot subtract integer from relative -// Error: 21-29 cannot multiply integer with boolean -// Error: 31-39 cannot divide integer by length -{(1 + "2", 40% - 1, 2 * true, 3 / 12pt)} +{(1234567, 40% - 1)} + +--- +// Error: 2-10 cannot multiply integer with boolean +{2 * true} -// Error: 14-22 cannot apply '+=' to integer and string +--- +// Error: 2-10 cannot divide integer by length +{3 / 12pt} + +--- +// Error: 14-22 cannot add integer and string { let x = 1; x += "2" } +--- // Error: 13-14 expected argument list, found integer { test with 2 } +--- // Error: 3-4 expected function, found integer { 1 with () } +--- // Error: 3-10 cannot apply '..' to integer and string { 1 .. "" } --- -// Bad left-hand sides of assignment. - // Error: 3-6 cannot assign to this expression { (x) = "" } +--- // Error: 3-8 cannot assign to this expression { 1 + 2 += 3 } +--- // Error: 3-4 unknown variable { z = 1 } +--- // Error: 3-7 cannot assign to a constant { rect = "hi" } +--- // Works if we define rect beforehand // (since then it doesn't resolve to the standard library version anymore). #let rect = "" diff --git a/tests/typ/code/repr.typ b/tests/typ/code/repr.typ index 3da86bf8..35a47e49 100644 --- a/tests/typ/code/repr.typ +++ b/tests/typ/code/repr.typ @@ -10,9 +10,6 @@ {ke-bab} \ {α} -// Error: 2-3 unknown variable -{_} - --- // Literal values. {none} (empty) \ diff --git a/tests/typ/code/while.typ b/tests/typ/code/while.typ index 306c1e45..2f0984d2 100644 --- a/tests/typ/code/while.typ +++ b/tests/typ/code/while.typ @@ -29,23 +29,16 @@ #test(type(while i < 1 [{ i += 1 }]), "template") --- -// Ref: false - // 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 {} - -// Errors taint everything. -#let i = 0 -#test(error, while i < 10 { - i += 1 - if i < 5 [nope] else { error } -}) -#test(i, 10) +--- +// Make sure that we terminate and don't complain multiple times. +#while true { + // Error: 5-9 unknown variable + nope +} --- // Error: 7 expected expression @@ -57,11 +50,9 @@ // 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 -- cgit v1.2.3