summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/src/benches.rs27
-rw-r--r--tests/src/tests.rs46
2 files changed, 35 insertions, 38 deletions
diff --git a/tests/src/benches.rs b/tests/src/benches.rs
index 29117a90..1e5550c5 100644
--- a/tests/src/benches.rs
+++ b/tests/src/benches.rs
@@ -1,12 +1,13 @@
-use std::path::{Path, PathBuf};
+use std::path::Path;
use comemo::{Prehashed, Track, Tracked};
use iai::{black_box, main, Iai};
use typst::diag::{FileError, FileResult};
use typst::font::{Font, FontBook};
+use typst::model::Library;
use typst::syntax::{Source, SourceId, TokenMode, Tokens};
use typst::util::Buffer;
-use typst::{Config, World};
+use typst::World;
use unscanny::Scanner;
const TEXT: &str = include_str!("../typ/benches/bench.typ");
@@ -90,7 +91,7 @@ fn bench_render(iai: &mut Iai) {
}
struct BenchWorld {
- config: Prehashed<Config>,
+ library: Prehashed<Library>,
book: Prehashed<FontBook>,
font: Font,
source: Source,
@@ -98,22 +99,14 @@ struct BenchWorld {
impl BenchWorld {
fn new() -> Self {
- let config = Config {
- root: PathBuf::new(),
- scope: typst_library::scope(),
- styles: typst_library::styles(),
- items: typst_library::items(),
- };
-
let font = Font::new(FONT.into(), 0).unwrap();
let book = FontBook::from_fonts([&font]);
- let source = Source::detached(TEXT);
Self {
- config: Prehashed::new(config),
+ library: Prehashed::new(typst_library::new()),
book: Prehashed::new(book),
font,
- source,
+ source: Source::detached(TEXT),
}
}
@@ -123,8 +116,12 @@ impl BenchWorld {
}
impl World for BenchWorld {
- fn config(&self) -> &Prehashed<Config> {
- &self.config
+ fn root(&self) -> &Path {
+ Path::new("")
+ }
+
+ fn library(&self) -> &Prehashed<Library> {
+ &self.library
}
fn book(&self) -> &Prehashed<FontBook> {
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index 89c83857..2c0a1e71 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -15,10 +15,10 @@ use typst::diag::{bail, FileError, FileResult};
use typst::font::{Font, FontBook};
use typst::frame::{Element, Frame};
use typst::geom::{Abs, RgbaColor, Sides};
-use typst::model::{Smart, Value};
+use typst::model::{Library, Smart, Value};
use typst::syntax::{Source, SourceId, SyntaxNode};
use typst::util::{Buffer, PathExt};
-use typst::{Config, World};
+use typst::World;
use typst_library::layout::PageNode;
use typst_library::text::{TextNode, TextSize};
use unscanny::Scanner;
@@ -144,21 +144,22 @@ impl Args {
}
}
-fn config() -> Config {
+fn library() -> Library {
+ let mut lib = typst_library::new();
+
// 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.
- let mut styles = typst_library::styles();
- styles.set(PageNode::WIDTH, Smart::Custom(Abs::pt(120.0).into()));
- styles.set(PageNode::HEIGHT, Smart::Auto);
- styles.set(PageNode::MARGIN, Sides::splat(Some(Smart::Custom(Abs::pt(10.0).into()))));
- styles.set(TextNode::SIZE, TextSize(Abs::pt(10.0).into()));
+ 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.
- let mut scope = typst_library::scope();
- scope.define("conifer", RgbaColor::new(0x9f, 0xEB, 0x52, 0xFF));
- scope.define("forest", RgbaColor::new(0x43, 0xA1, 0x27, 0xFF));
- scope.def_fn("test", move |_, args| {
+ 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| {
let lhs = args.expect::<Value>("left-hand side")?;
let rhs = args.expect::<Value>("right-hand side")?;
if lhs != rhs {
@@ -166,7 +167,7 @@ fn config() -> Config {
}
Ok(Value::None)
});
- scope.def_fn("print", move |_, args| {
+ lib.scope.def_fn("print", move |_, args| {
print!("> ");
for (i, value) in args.all::<Value>()?.into_iter().enumerate() {
if i > 0 {
@@ -178,18 +179,13 @@ fn config() -> Config {
Ok(Value::None)
});
- Config {
- root: PathBuf::new(),
- scope,
- styles,
- items: typst_library::items(),
- }
+ lib
}
/// A world that provides access to the tests environment.
struct TestWorld {
print: PrintConfig,
- config: Prehashed<Config>,
+ library: Prehashed<Library>,
book: Prehashed<FontBook>,
fonts: Vec<Font>,
paths: RefCell<HashMap<PathBuf, PathSlot>>,
@@ -219,7 +215,7 @@ impl TestWorld {
Self {
print,
- config: Prehashed::new(config()),
+ library: Prehashed::new(library()),
book: Prehashed::new(FontBook::from_fonts(&fonts)),
fonts,
paths: RefCell::default(),
@@ -229,8 +225,12 @@ impl TestWorld {
}
impl World for TestWorld {
- fn config(&self) -> &Prehashed<Config> {
- &self.config
+ fn root(&self) -> &Path {
+ Path::new("")
+ }
+
+ fn library(&self) -> &Prehashed<Library> {
+ &self.library
}
fn book(&self) -> &Prehashed<FontBook> {