summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-14 10:09:44 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-14 10:09:44 +0100
commit9ba4d2c134479aad876a0e2ac4cd1622a353109e (patch)
treea94e0e6ae53a1ba440e869fca26cc2ea0b179057 /tests/src
parent4c73456fc1f5df8ebb3a89d9db657c3c54624d66 (diff)
New macro setup
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/tests.rs46
1 files changed, 26 insertions, 20 deletions
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index 700a9926..06162df0 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -11,11 +11,11 @@ use comemo::{Prehashed, Track};
use elsa::FrozenVec;
use once_cell::unsync::OnceCell;
use tiny_skia as sk;
-use typst::diag::{bail, FileError, FileResult};
+use typst::diag::{bail, FileError, FileResult, SourceResult};
use typst::doc::{Document, Element, Frame, Meta};
use typst::font::{Font, FontBook};
use typst::geom::{Abs, RgbaColor, Sides};
-use typst::model::{Library, Smart, Value};
+use typst::model::{func, Library, Smart, Value};
use typst::syntax::{Source, SourceId, SyntaxNode};
use typst::util::{Buffer, PathExt};
use typst::World;
@@ -145,29 +145,18 @@ impl Args {
}
fn library() -> Library {
- let mut lib = typst_library::build();
-
- // Set page width to 120pt with 10pt margins, so that the inner page is
- // exactly 100pt wide. Page height is unbounded and font size is 10pt so
- // that it multiplies to nice round numbers.
- lib.styles.set(PageNode::WIDTH, Smart::Custom(Abs::pt(120.0).into()));
- lib.styles.set(PageNode::HEIGHT, Smart::Auto);
- lib.styles
- .set(PageNode::MARGIN, Sides::splat(Some(Smart::Custom(Abs::pt(10.0).into()))));
- lib.styles.set(TextNode::SIZE, TextSize(Abs::pt(10.0).into()));
-
- // Hook up helpers into the global scope.
- lib.scope.define("conifer", RgbaColor::new(0x9f, 0xEB, 0x52, 0xFF));
- lib.scope.define("forest", RgbaColor::new(0x43, 0xA1, 0x27, 0xFF));
- lib.scope.def_fn("test", move |_, args| {
+ #[func]
+ fn test(args: &mut typst::model::Args) -> SourceResult<Value> {
let lhs = args.expect::<Value>("left-hand side")?;
let rhs = args.expect::<Value>("right-hand side")?;
if lhs != rhs {
bail!(args.span, "Assertion failed: {:?} != {:?}", lhs, rhs,);
}
Ok(Value::None)
- });
- lib.scope.def_fn("print", move |_, args| {
+ }
+
+ #[func]
+ fn print(args: &mut typst::model::Args) -> SourceResult<Value> {
print!("> ");
for (i, value) in args.all::<Value>()?.into_iter().enumerate() {
if i > 0 {
@@ -177,7 +166,24 @@ fn library() -> Library {
}
println!();
Ok(Value::None)
- });
+ }
+
+ let mut lib = typst_library::build();
+
+ // Set page width to 120pt with 10pt margins, so that the inner page is
+ // exactly 100pt wide. Page height is unbounded and font size is 10pt so
+ // that it multiplies to nice round numbers.
+ lib.styles.set(PageNode::WIDTH, Smart::Custom(Abs::pt(120.0).into()));
+ lib.styles.set(PageNode::HEIGHT, Smart::Auto);
+ lib.styles
+ .set(PageNode::MARGIN, Sides::splat(Some(Smart::Custom(Abs::pt(10.0).into()))));
+ lib.styles.set(TextNode::SIZE, TextSize(Abs::pt(10.0).into()));
+
+ // Hook up helpers into the global scope.
+ lib.scope.def_func::<TestFunc>("test");
+ lib.scope.def_func::<PrintFunc>("print");
+ lib.scope.define("conifer", RgbaColor::new(0x9f, 0xEB, 0x52, 0xFF));
+ lib.scope.define("forest", RgbaColor::new(0x43, 0xA1, 0x27, 0xFF));
lib
}