From 264a7dedd42e27cd9e604037640cf0594b2ec46b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 19 Mar 2021 17:57:31 +0100 Subject: =?UTF-8?q?Scheduled=20maintenance=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New naming scheme - TextNode instead of NodeText - CallExpr instead of ExprCall - ... - Less glob imports - Removes Value::Args variant - Removes prelude - Renames Layouted to Fragment - Moves font into env - Moves shaping into layout - Moves frame into separate module --- tests/README.md | 26 ++++++++++++++++---------- tests/typeset.rs | 26 +++++++++++++++----------- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index fb755f1b..57d47fe2 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,29 +3,35 @@ ## Directory structure Top level directory structure: - `typ`: Input files. +- `res`: Resource files used by tests. - `ref`: Reference images which the output is compared with to determine whether a test passed or failed. - `png`: PNG files produced by tests. - `pdf`: PDF files produced by tests. -- `res`: Resource files used by tests. ## Running the tests +Running the integration tests (the tests in this directory). ```bash -# Run all tests -cargo test - -# Run unit tests -cargo test --lib - -# Run integration tests (the tests in this directory) cargo test --test typeset +``` -# Run all tests whose names contain the word `filter` +Running all tests whose names contain the word `filter`. +```bash cargo test --test typeset filter ``` +To make the integration tests go faster they don't generate PDFs by default. +Pass the `--pdf` flag to generate those. Mind that PDFs are not tested +automatically at the moment, so you should always check the output manually when +making changes. +```bash +cargo test --test typeset -- --pdf +``` + ## Creating new tests -To keep things small, please optimize reference images before committing them: +To keep things small, please optimize reference images before committing them. +When you use the approve buttom from the Test Helper (see the `tools` folder) +this happens automatically if you have `oxipng` installed. ```bash # One image oxipng -o max path/to/image.png diff --git a/tests/typeset.rs b/tests/typeset.rs index 0cd146f4..7e7efc67 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -15,16 +15,15 @@ use ttf_parser::OutlineBuilder; use walkdir::WalkDir; use typst::diag::{Diag, DiagSet, Level, Pass}; -use typst::env::{Env, ImageResource, ResourceLoader}; -use typst::eval::{EvalContext, Scope, Value, ValueArgs, ValueFunc}; +use typst::env::{Env, FsIndexExt, ImageResource, ResourceLoader}; +use typst::eval::{EvalContext, FuncArgs, FuncValue, Scope, Value}; use typst::exec::State; use typst::export::pdf; -use typst::font::FsIndexExt; use typst::geom::{Length, Point, Sides, Size}; -use typst::layout::{Element, Fill, Frame, Geometry, Image, Shape}; +use typst::layout::{Element, Fill, Frame, Geometry, Image, Shape, Shaped}; use typst::library; use typst::parse::{LineMap, Scanner}; -use typst::shaping::Shaped; +use typst::pretty::pretty; use typst::syntax::{Location, Pos}; use typst::typeset; @@ -313,13 +312,18 @@ struct Panic { } fn register_helpers(scope: &mut Scope, panics: Rc>>) { - pub fn args(_: &mut EvalContext, args: &mut ValueArgs) -> Value { - let value = args.clone().into(); + pub fn args(_: &mut EvalContext, args: &mut FuncArgs) -> Value { + let repr = pretty(args); args.items.clear(); - value + Value::template("args", move |ctx| { + let snapshot = ctx.state.clone(); + ctx.set_monospace(); + ctx.push_text(&repr); + ctx.state = snapshot; + }) } - let test = move |ctx: &mut EvalContext, args: &mut ValueArgs| -> Value { + let test = move |ctx: &mut EvalContext, args: &mut FuncArgs| -> Value { let lhs = args.require::(ctx, "left-hand side"); let rhs = args.require::(ctx, "right-hand side"); if lhs != rhs { @@ -331,8 +335,8 @@ fn register_helpers(scope: &mut Scope, panics: Rc>>) { }; scope.def_const("error", Value::Error); - scope.def_const("args", ValueFunc::new(Some("args".into()), args)); - scope.def_const("test", ValueFunc::new(Some("test".into()), test)); + scope.def_const("args", FuncValue::new(Some("args".into()), args)); + scope.def_const("test", FuncValue::new(Some("test".into()), test)); } fn print_diag(diag: &Diag, map: &LineMap, lines: u32) { -- cgit v1.2.3