diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/style/show.png | bin | 0 -> 19940 bytes | |||
| -rw-r--r-- | tests/typ/style/set.typ | 2 | ||||
| -rw-r--r-- | tests/typ/style/show.typ | 52 | ||||
| -rw-r--r-- | tests/typ/style/wrap.typ | 2 | ||||
| -rw-r--r-- | tests/typeset.rs | 33 |
5 files changed, 64 insertions, 25 deletions
diff --git a/tests/ref/style/show.png b/tests/ref/style/show.png Binary files differnew file mode 100644 index 00000000..0f1a16a3 --- /dev/null +++ b/tests/ref/style/show.png diff --git a/tests/typ/style/set.typ b/tests/typ/style/set.typ index 0d4d47cc..6ce1d303 100644 --- a/tests/typ/style/set.typ +++ b/tests/typ/style/set.typ @@ -1,5 +1,5 @@ // General tests for set. --- -// Error: 2-10 set is only allowed directly in markup +// Error: 2-10 set, show and wrap are only allowed directly in markup {set f(x)} diff --git a/tests/typ/style/show.typ b/tests/typ/style/show.typ index 533e50f5..1055f9c7 100644 --- a/tests/typ/style/show.typ +++ b/tests/typ/style/show.typ @@ -1,9 +1,53 @@ // Test show rules. +#set page("a8", footer: p => v(-5pt) + align(right, [#p])) + +#let i = 1 +#set heading(size: 100%) +#show heading(level, body) as { + if level == 1 { + v(10pt) + underline(text(150%, blue)[{i}. #body]) + i += 1 + } else { + text(red, body) + } +} + +#v(-10pt) + += Aufgabe +Some text. + +== Subtask +Some more text. + +== Another subtask +Some more text. + += Aufgabe +Another text. + +--- +#set heading(size: 100%, strong: false, block: false) +#show heading(a, b) as [B] +A [= Heading] C + +--- +// Error: 1-22 unexpected argument +#show heading() as [] += Heading + +--- +// Error: 1-28 expected template, found string +#show heading(_, _) as "hi" += Heading + --- -// Error: 1-34 show rules are not yet implemented -#show heading(body) as [*{body}*] +// Error: 1-29 show rule is recursive +#show strong(x) as strong(x) +*Hi* --- -// Error: 2-15 show is only allowed directly in markup -{show (a) as b} +// Error: 2-19 set, show and wrap are only allowed directly in markup +{show list(a) as b} diff --git a/tests/typ/style/wrap.typ b/tests/typ/style/wrap.typ index 2fa7716e..9c94b9ae 100644 --- a/tests/typ/style/wrap.typ +++ b/tests/typ/style/wrap.typ @@ -25,5 +25,5 @@ A [_B #wrap c in [*#c*]; C_] D Forest --- -// Error: 6-17 wrap is only allowed directly in markup +// Error: 6-17 set, show and wrap are only allowed directly in markup {1 + wrap x in y} diff --git a/tests/typeset.rs b/tests/typeset.rs index dadcfed3..98c85df9 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -23,7 +23,7 @@ use typst::{Context, Vm}; use { filedescriptor::{FileDescriptor, StdioDescriptor::*}, std::fs::File, - typst::eval::Template, + typst::source::SourceId, }; const TYP_DIR: &str = "./typ"; @@ -110,7 +110,7 @@ fn main() { &png_path, &ref_path, pdf_path.as_deref(), - args.debug, + args.syntax, ) as usize; } @@ -126,7 +126,7 @@ fn main() { struct Args { filter: Vec<String>, exact: bool, - debug: bool, + syntax: bool, pdf: bool, } @@ -134,7 +134,7 @@ impl Args { fn new(args: impl Iterator<Item = String>) -> Self { let mut filter = Vec::new(); let mut exact = false; - let mut debug = false; + let mut syntax = false; let mut pdf = false; for arg in args { @@ -146,13 +146,13 @@ impl Args { // Generate PDFs. "--pdf" => pdf = true, // Debug print the layout trees. - "--debug" | "-d" => debug = true, + "--syntax" => syntax = true, // Everything else is a file filter. _ => filter.push(arg), } } - Self { filter, pdf, debug, exact } + Self { filter, pdf, syntax, exact } } fn matches(&self, path: &Path) -> bool { @@ -172,7 +172,7 @@ fn test( png_path: &Path, ref_path: &Path, pdf_path: Option<&Path>, - debug: bool, + syntax: bool, ) -> bool { let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path); println!("Testing {}", name.display()); @@ -208,7 +208,7 @@ fn test( i, compare_ref, line, - debug, + syntax, &mut rng, ); ok &= part_ok; @@ -242,7 +242,7 @@ fn test( } if ok { - if !debug { + if !syntax { print!("\x1b[1A"); } println!("Testing {} ✔", name.display()); @@ -258,14 +258,14 @@ fn test_part( i: usize, compare_ref: bool, line: usize, - debug: bool, + syntax: bool, rng: &mut LinearShift, ) -> (bool, bool, Vec<Arc<Frame>>) { let mut ok = true; let id = ctx.sources.provide(src_path, src); let source = ctx.sources.get(id); - if debug { + if syntax { println!("Syntax Tree: {:#?}", source.root()) } @@ -277,13 +277,8 @@ fn test_part( let mut vm = Vm::new(ctx); let (frames, mut errors) = match vm.typeset(id) { Ok(mut frames) => { - let module = vm.evaluate(id).unwrap(); - if debug { - println!("Template: {:#?}", module.template); - } - #[cfg(feature = "layout-cache")] - (ok &= test_incremental(ctx, i, &module.template, &frames)); + (ok &= test_incremental(ctx, i, id, &frames)); if !compare_ref { frames.clear(); @@ -483,7 +478,7 @@ fn test_reparse(src: &str, i: usize, rng: &mut LinearShift) -> bool { fn test_incremental( ctx: &mut Context, i: usize, - template: &Template, + id: SourceId, frames: &[Arc<Frame>], ) -> bool { let mut ok = true; @@ -498,7 +493,7 @@ fn test_incremental( ctx.layout_cache.turnaround(); - let cached = silenced(|| template.layout_pages(&mut Vm::new(ctx)).unwrap()); + let cached = silenced(|| ctx.typeset(id).unwrap()); let total = reference.levels() - 1; let misses = ctx .layout_cache |
