summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
commit62f35602a87574dcc607f1637aeae1be574981ff (patch)
tree363a1918006e06d7d79dc2ace5f8e59cd3b6bb19 /tests
parentc38d72383d2068361d635d6c1c78ba97aa917801 (diff)
New #[func] macro
Diffstat (limited to 'tests')
-rw-r--r--tests/src/tests.rs20
-rw-r--r--tests/typ/compute/calc.typ4
-rw-r--r--tests/typ/text/lorem.typ2
3 files changed, 13 insertions, 13 deletions
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index b35ddcce..8a25af15 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -11,7 +11,7 @@ use comemo::{Prehashed, Track};
use elsa::FrozenVec;
use once_cell::unsync::OnceCell;
use tiny_skia as sk;
-use typst::diag::{bail, FileError, FileResult, SourceResult};
+use typst::diag::{bail, FileError, FileResult};
use typst::doc::{Document, Element, Frame, Meta};
use typst::eval::{func, Library, Value};
use typst::font::{Font, FontBook};
@@ -148,29 +148,29 @@ impl Args {
fn library() -> Library {
/// Display: Test
/// Category: test
+ /// Returns:
#[func]
- fn test(args: &mut typst::eval::Args) -> SourceResult<Value> {
- let lhs = args.expect::<Value>("left-hand side")?;
- let rhs = args.expect::<Value>("right-hand side")?;
+ fn test(lhs: Value, rhs: Value) -> Value {
if lhs != rhs {
bail!(args.span, "Assertion failed: {:?} != {:?}", lhs, rhs,);
}
- Ok(Value::None)
+ Value::None
}
/// Display: Print
/// Category: test
+ /// Returns:
#[func]
- fn print(args: &mut typst::eval::Args) -> SourceResult<Value> {
+ fn print(#[variadic] values: Vec<Value>) -> Value {
print!("> ");
- for (i, value) in args.all::<Value>()?.into_iter().enumerate() {
+ for (i, value) in values.into_iter().enumerate() {
if i > 0 {
print!(", ")
}
print!("{value:?}");
}
println!();
- Ok(Value::None)
+ Value::None
}
let mut lib = typst_library::build();
@@ -187,8 +187,8 @@ fn library() -> Library {
lib.styles.set(TextNode::set_size(TextSize(Abs::pt(10.0).into())));
// Hook up helpers into the global scope.
- lib.global.scope_mut().def_func::<TestFunc>("test");
- lib.global.scope_mut().def_func::<PrintFunc>("print");
+ lib.global.scope_mut().define("test", test);
+ lib.global.scope_mut().define("print", print);
lib.global
.scope_mut()
.define("conifer", RgbaColor::new(0x9f, 0xEB, 0x52, 0xFF));
diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ
index 67579493..ee063707 100644
--- a/tests/typ/compute/calc.typ
+++ b/tests/typ/compute/calc.typ
@@ -77,7 +77,7 @@
#test(calc.min("hi"), "hi")
---
-// Error: 10-12 missing argument: value
+// Error: 10-12 expected at least one value
#calc.min()
---
@@ -109,5 +109,5 @@
#range(4, step: "one")
---
-// Error: 18-19 step must not be zero
+// Error: 18-19 number must be positive
#range(10, step: 0)
diff --git a/tests/typ/text/lorem.typ b/tests/typ/text/lorem.typ
index 944fd5be..92dfbba4 100644
--- a/tests/typ/text/lorem.typ
+++ b/tests/typ/text/lorem.typ
@@ -28,5 +28,5 @@
}
---
-// Error: 7-9 missing argument: number of words
+// Error: 7-9 missing argument: words
#lorem()