Update tests for type system changes

This commit is contained in:
Laurenz 2023-09-11 14:42:43 +02:00
parent b471ac7d59
commit 305524d005
35 changed files with 116 additions and 109 deletions

View File

@ -10,7 +10,7 @@ publish = false
typst = { path = "../crates/typst" }
typst-library = { path = "../crates/typst-library" }
comemo = "0.3"
ecow = { version = "0.1.1", features = ["serde"] }
ecow = { version = "0.1.2", features = ["serde"] }
iai = { git = "https://github.com/reknih/iai" }
once_cell = "1"
oxipng = { version = "8.0.0", default-features = false, features = ["filetime", "parallel", "zopfli"] }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -151,8 +151,6 @@ fn main() {
}
fn library() -> Library {
/// Display: Test
/// Category: test
#[func]
fn test(lhs: Value, rhs: Value) -> StrResult<NoneValue> {
if lhs != rhs {
@ -161,8 +159,6 @@ fn library() -> Library {
Ok(NoneValue)
}
/// Display: Print
/// Category: test
#[func]
fn print(#[variadic] values: Vec<Value>) -> NoneValue {
let mut stdout = io::stdout().lock();
@ -191,8 +187,8 @@ fn library() -> Library {
lib.styles.set(TextElem::set_size(TextSize(Abs::pt(10.0).into())));
// Hook up helpers into the global scope.
lib.global.scope_mut().define("test", test_func());
lib.global.scope_mut().define("print", print_func());
lib.global.scope_mut().define_func::<test>();
lib.global.scope_mut().define_func::<print>();
lib.global
.scope_mut()
.define("conifer", RgbaColor::new(0x9f, 0xEB, 0x52, 0xFF));

View File

@ -9,7 +9,7 @@
rect(width: 100%, fill: red),
rect(width: 100%, fill: blue),
rect(width: 100%, height: 80%, fill: green),
[hello \ darkness #parbreak my \ old \ friend \ I],
[hello \ darkness #parbreak() my \ old \ friend \ I],
rect(width: 100%, height: 20%, fill: blue),
polygon(fill: red, (0%, 0%), (100%, 0%), (100%, 20%))
)

View File

@ -71,7 +71,7 @@
---
// Test bad lvalue.
// Error: 2:3-2:15 type array has no method `yolo`
// Error: 2:9-2:13 type array has no method `yolo`
#let array = (1, 2, 3)
#(array.yolo() = 4)
@ -122,7 +122,7 @@
}
---
// Error: 2:16-2:18 missing argument: index
// Error: 2:2-2:18 missing argument: index
#let numbers = ()
#numbers.insert()

View File

@ -46,7 +46,7 @@
#test({
type("")
none
}, "string")
}, str)
---
// Some things can't be joined.

View File

@ -31,12 +31,12 @@
// Call function assigned to variable.
#let alias = type
#test(alias(alias), "function")
#test(alias(alias), type)
// Callee expressions.
#{
// Wrapped in parens.
test((type)("hi"), "string")
test((type)("hi"), str)
// Call the return value of a function.
let adder(dx) = x => x + dx

View File

@ -115,7 +115,7 @@
---
// Too few arguments.
#{
let types(x, y) = "[" + type(x) + ", " + type(y) + "]"
let types(x, y) = "[" + str(type(x)) + ", " + str(type(y)) + "]"
test(types(14%, 12pt), "[ratio, length]")
// Error: 13-21 missing argument: y

View File

@ -12,7 +12,7 @@ C/*
// Works in code.
#test(type(/*1*/ 1) //
, "integer")
, int)
// End of block comment in line comment.
// Hello */

View File

@ -98,8 +98,8 @@
let dict = (
func: () => 1,
)
// Error: 3-14 type dictionary has no method `func`
// Hint: 3-14 to call the function stored in the dictionary, surround the field access with parentheses
// Error: 8-12 type dictionary has no method `func`
// Hint: 8-12 to call the function stored in the dictionary, surround the field access with parentheses
dict.func()
}
@ -109,6 +109,6 @@
nonfunc: 1
)
// Error: 3-17 type dictionary has no method `nonfunc`
// Error: 8-15 type dictionary has no method `nonfunc`
dict.nonfunc()
}
}

View File

@ -47,7 +47,7 @@
#f.invalid
---
// Error: 6-13 dictionary does not contain key "invalid" and no default value was specified
// Error: 6-13 dictionary does not contain key "invalid"
#(:).invalid
---
@ -55,7 +55,7 @@
#false.ok
---
// Error: 25-28 content does not contain field "fun" and no default value was specified
// Error: 25-28 content does not contain field "fun"
#show heading: it => it.fun
= A
@ -73,21 +73,21 @@
---
// Test length fields.
#test((1pt).em, 0em)
#test((1pt).em, 0.0)
#test((1pt).abs, 1pt)
#test((3em).em, 3em)
#test((3em).em, 3.0)
#test((3em).abs, 0pt)
#test((2em + 2pt).em, 2em)
#test((2em + 2pt).em, 2.0)
#test((2em + 2pt).abs, 2pt)
---
// Test stroke fields for simple strokes.
#test((1em + blue).paint, blue)
#test((1em + blue).thickness, 1em)
#test((1em + blue).cap, "butt")
#test((1em + blue).join, "miter")
#test((1em + blue).dash, none)
#test((1em + blue).miter-limit, 4.0)
#test((1em + blue).cap, auto)
#test((1em + blue).join, auto)
#test((1em + blue).dash, auto)
#test((1em + blue).miter-limit, auto)
---
// Test complex stroke fields.
@ -102,7 +102,7 @@
#test(s1.cap, "round")
#test(s1.join, "bevel")
#test(s1.miter-limit, 5.0)
#test(s3.miter-limit, 4.0)
#test(s3.miter-limit, auto)
#test(s1.dash, none)
#test(s2.dash, (array: (3pt, "dot", 4em), phase: 0pt))
#test(s3.dash, (array: (3pt, "dot", 4em), phase: 5em))

View File

@ -76,7 +76,7 @@
// Return value.
#test(for v in "" [], none)
#test(type(for v in "1" []), "content")
#test(type(for v in "1" []), content)
---
// Uniterable expression.

View File

@ -41,8 +41,8 @@
// Content block can be argument or body depending on whitespace.
#{
if "content" == type[b] [Fi] else [Nope]
if "content" == type [Nope] else [ve.]
if content == type[b] [Fi] else [Nope]
if content == type [Nope] else [ve.]
}
#let i = 3

View File

@ -116,12 +116,10 @@
---
// Usual importing syntax also works for function scopes
#import enum
#let d = (e: enum)
#import d.e
#import d.e as renamed
#import d.e: item
#item(2)[a]
---
@ -166,11 +164,11 @@
#import () => {5}: x
---
// Error: 9-10 expected path, module or function, found integer
// Error: 9-10 expected path, module, function, or type, found integer
#import 5: something
---
// Error: 9-10 expected path, module or function, found integer
// Error: 9-10 expected path, module, function, or type, found integer
#import 5 as x
---
@ -213,14 +211,14 @@ This is never reached.
---
// Renaming does not import the old name (without items).
#import "module.typ" as something
// Error: 7-13 unknown variable: module
#test(module.b, 1)
// Error: 7-12 unknown variable: mymod
#test(mymod.b, 1)
---
// Renaming does not import the old name (with items).
#import "module.typ" as something: b as other
// Error: 7-13 unknown variable: module
#test(module.b, 1)
// Error: 7-12 unknown variable: mymod
#test(mymod.b, 1)
---
// Error: 8 expected expression

View File

@ -189,11 +189,11 @@ Three
#let (a: "a", b: 2) = (a: 1, b: 2)
---
// Error: 10-11 destructuring key not found in dictionary
// Error: 10-11 dictionary does not contain key "b"
#let (a, b) = (a: 1)
---
// Error: 10-11 destructuring key not found in dictionary
// Error: 10-11 dictionary does not contain key "b"
#let (a, b: b) = (a: 1)
---

View File

@ -31,7 +31,7 @@
#test(auto, [a].at("doesn't exist", default: auto))
---
// Error: 2:2-2:15 type array has no method `fun`
// Error: 2:10-2:13 type array has no method `fun`
#let numbers = ()
#numbers.fun()
@ -76,23 +76,23 @@
#test((5em + 6in).abs.inches(), 6.0)
---
// Error: 2-21 cannot convert a length with non-zero em units (-6pt + 10.5em) to pt
// Hint: 2-21 use 'length.abs.pt()' instead to ignore its em component
// Error: 2-21 cannot convert a length with non-zero em units (`-6pt + 10.5em`) to pt
// Hint: 2-21 use `length.abs.pt()` instead to ignore its em component
#(10.5em - 6pt).pt()
---
// Error: 2-12 cannot convert a length with non-zero em units (3em) to cm
// Hint: 2-12 use 'length.abs.cm()' instead to ignore its em component
// Error: 2-12 cannot convert a length with non-zero em units (`3em`) to cm
// Hint: 2-12 use `length.abs.cm()` instead to ignore its em component
#(3em).cm()
---
// Error: 2-20 cannot convert a length with non-zero em units (-226.77pt + 93em) to mm
// Hint: 2-20 use 'length.abs.mm()' instead to ignore its em component
// Error: 2-20 cannot convert a length with non-zero em units (`-226.77pt + 93em`) to mm
// Hint: 2-20 use `length.abs.mm()` instead to ignore its em component
#(93em - 80mm).mm()
---
// Error: 2-24 cannot convert a length with non-zero em units (432pt + 4.5em) to inches
// Hint: 2-24 use 'length.abs.inches()' instead to ignore its em component
// Error: 2-24 cannot convert a length with non-zero em units (`432pt + 4.5em`) to inches
// Hint: 2-24 use `length.abs.inches()` instead to ignore its em component
#(4.5em + 6in).inches()
---
@ -104,32 +104,32 @@
---
// Test color '.rgba()', '.cmyk()' and '.luma()' without conversions
#test(rgb(1, 2, 3, 4).rgba(), (1, 2, 3, 4))
#test(rgb(1, 2, 3).rgba(), (1, 2, 3, 255))
#test(cmyk(20%, 20%, 40%, 20%).cmyk(), (20%, 20%, 40%, 20%))
#test(luma(40).luma(), 40)
#test(rgb(1, 2, 3, 4).to-rgba(), (1, 2, 3, 4))
#test(rgb(1, 2, 3).to-rgba(), (1, 2, 3, 255))
#test(cmyk(20%, 20%, 40%, 20%).to-cmyk(), (20%, 20%, 40%, 20%))
#test(luma(40).to-luma(), 40)
---
// Test color conversions.
#test(rgb(1, 2, 3).hex(), "#010203")
#test(rgb(1, 2, 3, 4).hex(), "#01020304")
#test(cmyk(4%, 5%, 6%, 7%).rgba(), (228, 225, 223, 255))
#test(cmyk(4%, 5%, 6%, 7%).hex(), "#e4e1df")
#test(luma(40).rgba(), (40, 40, 40, 255))
#test(luma(40).hex(), "#282828")
#test(repr(luma(40).cmyk()), repr((11.76%, 10.59%, 10.59%, 14.12%)))
#test(rgb(1, 2, 3).to-hex(), "#010203")
#test(rgb(1, 2, 3, 4).to-hex(), "#01020304")
#test(cmyk(4%, 5%, 6%, 7%).to-rgba(), (228, 225, 223, 255))
#test(cmyk(4%, 5%, 6%, 7%).to-hex(), "#e4e1df")
#test(luma(40).to-rgba(), (40, 40, 40, 255))
#test(luma(40).to-hex(), "#282828")
#test(repr(luma(40).to-cmyk()), repr((11.76%, 10.59%, 10.59%, 14.12%)))
---
// Error: 2-24 cannot obtain cmyk values from rgba color
#rgb(1, 2, 3, 4).cmyk()
// Error: 2-27 cannot obtain cmyk values from rgba color
#rgb(1, 2, 3, 4).to-cmyk()
---
// Error: 2-24 cannot obtain the luma value of rgba color
#rgb(1, 2, 3, 4).luma()
// Error: 2-27 cannot obtain the luma value of rgba color
#rgb(1, 2, 3, 4).to-luma()
---
// Error: 2-29 cannot obtain the luma value of cmyk color
#cmyk(4%, 5%, 6%, 7%).luma()
// Error: 2-32 cannot obtain the luma value of cmyk color
#cmyk(4%, 5%, 6%, 7%).to-luma()
---
// Test alignment methods.

View File

@ -87,7 +87,7 @@
#(3 / 12pt)
---
// Error: 3-10 cannot repeat this string -1 times
// Error: 3-10 number must be at least zero
#(-1 * "")
---

View File

@ -79,11 +79,11 @@
test(v + v, 2 * v)
// Integer addition does not give a float.
if type(v) != "integer" {
if type(v) != int {
test(v + v, 2.0 * v)
}
if "relative" not in type(v) and ("pt" not in repr(v) or "em" not in repr(v)) {
if type(v) != relative and ("pt" not in repr(v) or "em" not in repr(v)) {
test(v / v, 1.0)
}
}

View File

@ -19,8 +19,9 @@
---
#let p = plugin("/files/hello.wasm")
// Error: 10-14 unexpected argument
#p.hello(true)
// Error: 10-14 expected bytes, found boolean
// Error: 27-29 expected bytes, found integer
#p.hello(true, bytes(()), 10)
---
#let p = plugin("/files/hello.wasm")

View File

@ -23,13 +23,13 @@
// Test capturing with named function.
#let f = 10
#let f() = f
#test(type(f()), "function")
#test(type(f()), function)
---
// Test capturing with unnamed function.
#let f = 10
#let f = () => f
#test(type(f()), "integer")
#test(type(f()), int)
---
// Error: 15-21 maximum function call depth exceeded

View File

@ -37,9 +37,13 @@
// Content.
#raw(lang: "typc", repr[*Hey*])
// Functions are invisible.
Nothing
// Functions.
#let f(x) = x
#f
#rect
#f \
#rect \
#(() => none)
// Types.
#int \
#type("hi") \
#type((a: 1))

View File

@ -78,7 +78,7 @@ Another text.
= Heading
---
// Error: 25-29 content does not contain field "page" and no default value was specified
// Error: 25-29 content does not contain field "page"
#show heading: it => it.page
= Heading
@ -96,7 +96,7 @@ Hey
= Heading
---
// Error: 7-10 expected function, label, string, regular expression, symbol, or selector, found color
// Error: 7-10 expected symbol, string, label, function, regex, or selector, found color
#show red: []
---

View File

@ -40,4 +40,4 @@ the ```rs &mut T``` reference.
---
// Error: 7-35 this selector cannot be used with show
#show selector(heading).or(strong): none
#show selector(heading).or(figure): none

View File

@ -26,7 +26,7 @@
// Test doing things with arguments.
#{
let save(..args) = {
test(type(args), "arguments")
test(type(args), arguments)
test(repr(args), "(three: true, 1, 2)")
}

View File

@ -26,7 +26,7 @@
#test(while false {}, none)
#let i = 0
#test(type(while i < 1 [#(i += 1)]), "content")
#test(type(while i < 1 [#(i += 1)]), content)
---
// Condition must be boolean.

View File

@ -11,7 +11,7 @@
#test(float(10), 10.0)
#test(float(50% * 30%), 0.15)
#test(float("31.4e-1"), 3.14)
#test(type(float(10)), "float")
#test(type(float(10)), float)
---
#test(calc.round(calc.e, digits: 2), 2.72)
@ -22,7 +22,7 @@
#int(10pt)
---
// Error: 8-13 expected boolean, integer, ratio, string, or float, found function
// Error: 8-13 expected boolean, integer, ratio, string, or float, found type
#float(float)
---

View File

@ -62,7 +62,8 @@
---
// Error: 12-24 expected float or ratio, found string
#color.mix((red, "yes"), (green, "no"))
// Error: 26-39 expected float or ratio, found string
#color.mix((red, "yes"), (green, "no"), (green, 10%))
---
// Error: 12-23 expected a color or color-weight pair
@ -103,7 +104,7 @@
#test(str(10 / 3).len() > 10, true)
---
// Error: 6-8 expected integer, float, label, bytes, or string, found content
// Error: 6-8 expected integer, float, bytes, label, type, or string, found content
#str([])
---
@ -128,11 +129,11 @@
#str.to-unicode("ab")
---
// Error: 19-21 0xffffffffffffffff is not a valid codepoint
#str.from-unicode(-1) // negative values are not valid
// Error: 19-21 number must be at least zero
#str.from-unicode(-1)
---
// Error: 19-27 0x110000 is not a valid codepoint
// Error: 18-28 0x110000 is not a valid codepoint
#str.from-unicode(0x110000) // 0x10ffff is the highest valid code point
---
@ -205,21 +206,21 @@
#datetime(year: 2000, month: 2, day: 30)
---
// Error: 26-35 missing closing bracket for bracket at index 0
// Error: 27-34 missing closing bracket for bracket at index 0
#datetime.today().display("[year")
---
// Error: 26-39 invalid component name 'nothing' at index 1
// Error: 27-38 invalid component name 'nothing' at index 1
#datetime.today().display("[nothing]")
---
// Error: 26-51 invalid modifier 'wrong' at index 6
// Error: 27-50 invalid modifier 'wrong' at index 6
#datetime.today().display("[year wrong:last_two]")
---
// Error: 26-34 expected component name at index 2
// Error: 27-33 expected component name at index 2
#datetime.today().display(" []")
---
// Error: 26-36 failed to format datetime (insufficient information)
// Error: 2-36 failed to format datetime (insufficient information)
#datetime.today().display("[hour]")

View File

@ -2,9 +2,9 @@
// Ref: false
---
#test(type(1), "integer")
#test(type(ltr), "direction")
#test(type(10 / 3), "float")
#test(type(1), int)
#test(type(ltr), direction)
#test(type(10 / 3), float)
---
#test(repr(ltr), "ltr")
@ -68,9 +68,9 @@
---
// Test the `type` function.
#test(type(1), "integer")
#test(type(ltr), "direction")
#test(type(10 / 3), "float")
#test(type(1), int)
#test(type(ltr), direction)
#test(type(10 / 3), float)
---
// Test the eval function.

View File

@ -35,9 +35,9 @@
---
// Ref: false
#test(type(center), "alignment")
#test(type(horizon), "alignment")
#test(type(center + horizon), "2d alignment")
#test(type(center), alignment)
#test(type(horizon), alignment)
#test(type(center + horizon), alignment)
---
// Error: 8-22 cannot add two horizontal alignments
@ -46,3 +46,7 @@
---
// Error: 8-20 cannot add two vertical alignments
#align(top + bottom, [A])
---
// Error: 8-30 cannot add a vertical and a 2D alignment
#align(top + (bottom + right), [A])

View File

@ -33,9 +33,12 @@
---
// Test valid number align values (horizontal)
// Ref: false
#set enum(number-align: start)
#set enum(number-align: end)
#set enum(number-align: left)
#set enum(number-align: right)
// Error: 25-28 alignment must be horizontal
---
// Error: 25-28 expected `start`, `left`, `center`, `right`, or `end`, found top
#set enum(number-align: top)

View File

@ -10,7 +10,7 @@
---
#set page(width: 200pt)
= Details
See also #cite("arrgh", "distress", [p. 22]), @arrgh[p. 4], and @distress[p. 5].
See also #cite("arrgh", "distress", supplement: [p. 22]), @arrgh[p. 4], and @distress[p. 5].
#bibliography("/files/works.bib")
---

View File

@ -56,5 +56,5 @@
---
// Error: 2-23 cannot outline cite
#outline(target: cite)
#cite("arrgh", "distress", [p. 22])
#cite("arrgh", "distress", supplement: [p. 22])
#bibliography("/files/works.bib")

View File

@ -33,5 +33,5 @@ b = 324923
#lorem(20)
---
// Error: 17-20 alignment must be horizontal
// Error: 17-20 expected `start`, `left`, `center`, `right`, or `end`, found top
#set raw(align: top)