diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-06-06 21:13:59 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-06-06 22:06:16 +0200 |
| commit | fd417da04f7ca4b995de7f6510abafd3e9c31307 (patch) | |
| tree | 3675529c75ca7363701ac8ea306de2cc1d3cbcb3 /tests | |
| parent | 168bdf35bd773e67343c965cb473492cc5cae9e7 (diff) | |
Improve value casting infrastructure
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/src/tests.rs | 20 | ||||
| -rw-r--r-- | tests/typ/visualize/stroke.typ | 5 |
2 files changed, 10 insertions, 15 deletions
diff --git a/tests/src/tests.rs b/tests/src/tests.rs index 2c94af6c..bf3d19c1 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -20,9 +20,9 @@ use tiny_skia as sk; use unscanny::Scanner; use walkdir::WalkDir; -use typst::diag::{bail, FileError, FileResult}; +use typst::diag::{bail, FileError, FileResult, StrResult}; use typst::doc::{Document, Frame, FrameItem, Meta}; -use typst::eval::{func, Datetime, Library, Value}; +use typst::eval::{func, Datetime, Library, NoneValue, Value}; use typst::font::{Font, FontBook}; use typst::geom::{Abs, Color, RgbaColor, Sides, Smart}; use typst::syntax::{Source, SourceId, Span, SyntaxNode}; @@ -145,20 +145,18 @@ fn main() { fn library() -> Library { /// Display: Test /// Category: test - /// Returns: #[func] - fn test(lhs: Value, rhs: Value) -> Value { + fn test(lhs: Value, rhs: Value) -> StrResult<NoneValue> { if lhs != rhs { - bail!(args.span, "Assertion failed: {:?} != {:?}", lhs, rhs,); + bail!("Assertion failed: {lhs:?} != {rhs:?}"); } - Value::None + Ok(NoneValue) } /// Display: Print /// Category: test - /// Returns: #[func] - fn print(#[variadic] values: Vec<Value>) -> Value { + fn print(#[variadic] values: Vec<Value>) -> NoneValue { let mut stdout = io::stdout().lock(); write!(stdout, "> ").unwrap(); for (i, value) in values.into_iter().enumerate() { @@ -168,7 +166,7 @@ fn library() -> Library { write!(stdout, "{value:?}").unwrap(); } writeln!(stdout).unwrap(); - Value::None + NoneValue } let mut lib = typst_library::build(); @@ -185,8 +183,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); - lib.global.scope_mut().define("print", print); + lib.global.scope_mut().define("test", test_func()); + lib.global.scope_mut().define("print", print_func()); lib.global .scope_mut() .define("conifer", RgbaColor::new(0x9f, 0xEB, 0x52, 0xFF)); diff --git a/tests/typ/visualize/stroke.typ b/tests/typ/visualize/stroke.typ index 844cd8c2..88185403 100644 --- a/tests/typ/visualize/stroke.typ +++ b/tests/typ/visualize/stroke.typ @@ -56,18 +56,15 @@ (0pt, 20pt), (15pt, 0pt), (0pt, 40pt), (15pt, 45pt)), ) --- - // Error: 29-56 unexpected key "thicknes", valid keys are "paint", "thickness", "cap", "join", "dash", and "miter-limit" #line(length: 60pt, stroke: (paint: red, thicknes: 1pt)) --- - -// Error: 29-55 expected "solid", "dotted", "densely-dotted", "loosely-dotted", "dashed", "densely-dashed", "loosely-dashed", "dash-dotted", "densely-dash-dotted", "loosely-dash-dotted", array, dictionary, dash pattern, or none +// Error: 29-55 expected "solid", "dotted", "densely-dotted", "loosely-dotted", "dashed", "densely-dashed", "loosely-dashed", "dash-dotted", "densely-dash-dotted", "loosely-dash-dotted", array, dictionary, or none #line(length: 60pt, stroke: (paint: red, dash: "dash")) --- // 0pt strokes must function exactly like 'none' strokes and not draw anything - #rect(width: 10pt, height: 10pt, stroke: none) #rect(width: 10pt, height: 10pt, stroke: 0pt) #rect(width: 10pt, height: 10pt, stroke: none, fill: blue) |
