diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref/layout/box-block.png (renamed from tests/ref/layout/containers.png) | bin | 5194 -> 5194 bytes | |||
| -rw-r--r-- | tests/ref/layout/image.png (renamed from tests/ref/elements/image.png) | bin | 186196 -> 186196 bytes | |||
| -rw-r--r-- | tests/ref/layout/place-background.png (renamed from tests/ref/layout/background.png) | bin | 80160 -> 80160 bytes | |||
| -rw-r--r-- | tests/ref/layout/place.png (renamed from tests/ref/layout/placed.png) | bin | 33917 -> 33917 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-aspect.png (renamed from tests/ref/layout/aspect.png) | bin | 3601 -> 3601 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-circle.png (renamed from tests/ref/elements/circle.png) | bin | 18861 -> 18861 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-ellipse.png (renamed from tests/ref/elements/ellipse.png) | bin | 9455 -> 9455 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-fill-stroke.png (renamed from tests/ref/elements/fill-stroke.png) | bin | 1942 -> 1942 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-rect.png (renamed from tests/ref/elements/rect.png) | bin | 2914 -> 2914 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-square.png (renamed from tests/ref/elements/square.png) | bin | 6585 -> 6585 bytes | |||
| -rw-r--r-- | tests/ref/layout/spacing.png | bin | 2412 -> 2927 bytes | |||
| -rw-r--r-- | tests/ref/markup/heading.png | bin | 6474 -> 9141 bytes | |||
| -rw-r--r-- | tests/ref/style/set-block.png | bin | 0 -> 812 bytes | |||
| -rw-r--r-- | tests/ref/style/set-site.png | bin | 0 -> 4252 bytes | |||
| -rw-r--r-- | tests/ref/style/set-toggle.png | bin | 0 -> 968 bytes | |||
| -rw-r--r-- | tests/ref/text/em.png | bin | 0 -> 878 bytes | |||
| -rw-r--r-- | tests/ref/text/par.png | bin | 7388 -> 8169 bytes | |||
| -rw-r--r-- | tests/ref/text/whitespace.png | bin | 5322 -> 4674 bytes | |||
| -rw-r--r-- | tests/typ/layout/box-block.typ (renamed from tests/typ/layout/containers.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/image.typ (renamed from tests/typ/elements/image.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/place-background.typ (renamed from tests/typ/layout/background.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/place.typ (renamed from tests/typ/layout/placed.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-aspect.typ (renamed from tests/typ/layout/aspect.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-circle.typ (renamed from tests/typ/elements/circle.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-ellipse.typ (renamed from tests/typ/elements/ellipse.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-fill-stroke.typ (renamed from tests/typ/elements/fill-stroke.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-rect.typ (renamed from tests/typ/elements/rect.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-square.typ (renamed from tests/typ/elements/square.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/spacing.typ | 12 | ||||
| -rw-r--r-- | tests/typ/markup/heading.typ | 9 | ||||
| -rw-r--r-- | tests/typ/style/set-block.typ | 10 | ||||
| -rw-r--r-- | tests/typ/style/set-site.typ | 30 | ||||
| -rw-r--r-- | tests/typ/style/set-toggle.typ | 10 | ||||
| -rw-r--r-- | tests/typ/text/em.typ | 17 | ||||
| -rw-r--r-- | tests/typ/text/par.typ | 10 | ||||
| -rw-r--r-- | tests/typ/text/whitespace.typ | 41 | ||||
| -rw-r--r-- | tests/typeset.rs | 19 |
37 files changed, 124 insertions, 34 deletions
diff --git a/tests/ref/layout/containers.png b/tests/ref/layout/box-block.png Binary files differindex f6981fe5..f6981fe5 100644 --- a/tests/ref/layout/containers.png +++ b/tests/ref/layout/box-block.png diff --git a/tests/ref/elements/image.png b/tests/ref/layout/image.png Binary files differindex bdcfd200..bdcfd200 100644 --- a/tests/ref/elements/image.png +++ b/tests/ref/layout/image.png diff --git a/tests/ref/layout/background.png b/tests/ref/layout/place-background.png Binary files differindex 805139f5..805139f5 100644 --- a/tests/ref/layout/background.png +++ b/tests/ref/layout/place-background.png diff --git a/tests/ref/layout/placed.png b/tests/ref/layout/place.png Binary files differindex 4fdb1f70..4fdb1f70 100644 --- a/tests/ref/layout/placed.png +++ b/tests/ref/layout/place.png diff --git a/tests/ref/layout/aspect.png b/tests/ref/layout/shape-aspect.png Binary files differindex f76b4980..f76b4980 100644 --- a/tests/ref/layout/aspect.png +++ b/tests/ref/layout/shape-aspect.png diff --git a/tests/ref/elements/circle.png b/tests/ref/layout/shape-circle.png Binary files differindex 30734cb5..30734cb5 100644 --- a/tests/ref/elements/circle.png +++ b/tests/ref/layout/shape-circle.png diff --git a/tests/ref/elements/ellipse.png b/tests/ref/layout/shape-ellipse.png Binary files differindex e3c63427..e3c63427 100644 --- a/tests/ref/elements/ellipse.png +++ b/tests/ref/layout/shape-ellipse.png diff --git a/tests/ref/elements/fill-stroke.png b/tests/ref/layout/shape-fill-stroke.png Binary files differindex 2d04b3dd..2d04b3dd 100644 --- a/tests/ref/elements/fill-stroke.png +++ b/tests/ref/layout/shape-fill-stroke.png diff --git a/tests/ref/elements/rect.png b/tests/ref/layout/shape-rect.png Binary files differindex b6ab89aa..b6ab89aa 100644 --- a/tests/ref/elements/rect.png +++ b/tests/ref/layout/shape-rect.png diff --git a/tests/ref/elements/square.png b/tests/ref/layout/shape-square.png Binary files differindex 86bc1ff5..86bc1ff5 100644 --- a/tests/ref/elements/square.png +++ b/tests/ref/layout/shape-square.png diff --git a/tests/ref/layout/spacing.png b/tests/ref/layout/spacing.png Binary files differindex 6c7a4e63..09f7d6d9 100644 --- a/tests/ref/layout/spacing.png +++ b/tests/ref/layout/spacing.png diff --git a/tests/ref/markup/heading.png b/tests/ref/markup/heading.png Binary files differindex 55c681b0..52911d66 100644 --- a/tests/ref/markup/heading.png +++ b/tests/ref/markup/heading.png diff --git a/tests/ref/style/set-block.png b/tests/ref/style/set-block.png Binary files differnew file mode 100644 index 00000000..8ee5cfb6 --- /dev/null +++ b/tests/ref/style/set-block.png diff --git a/tests/ref/style/set-site.png b/tests/ref/style/set-site.png Binary files differnew file mode 100644 index 00000000..affe2e1c --- /dev/null +++ b/tests/ref/style/set-site.png diff --git a/tests/ref/style/set-toggle.png b/tests/ref/style/set-toggle.png Binary files differnew file mode 100644 index 00000000..ae8101ca --- /dev/null +++ b/tests/ref/style/set-toggle.png diff --git a/tests/ref/text/em.png b/tests/ref/text/em.png Binary files differnew file mode 100644 index 00000000..4c168db6 --- /dev/null +++ b/tests/ref/text/em.png diff --git a/tests/ref/text/par.png b/tests/ref/text/par.png Binary files differindex 900c668c..03117e67 100644 --- a/tests/ref/text/par.png +++ b/tests/ref/text/par.png diff --git a/tests/ref/text/whitespace.png b/tests/ref/text/whitespace.png Binary files differindex 7e79c177..36fb2475 100644 --- a/tests/ref/text/whitespace.png +++ b/tests/ref/text/whitespace.png diff --git a/tests/typ/layout/containers.typ b/tests/typ/layout/box-block.typ index 14258c1e..14258c1e 100644 --- a/tests/typ/layout/containers.typ +++ b/tests/typ/layout/box-block.typ diff --git a/tests/typ/elements/image.typ b/tests/typ/layout/image.typ index 8817713f..8817713f 100644 --- a/tests/typ/elements/image.typ +++ b/tests/typ/layout/image.typ diff --git a/tests/typ/layout/background.typ b/tests/typ/layout/place-background.typ index f64bf0ee..f64bf0ee 100644 --- a/tests/typ/layout/background.typ +++ b/tests/typ/layout/place-background.typ diff --git a/tests/typ/layout/placed.typ b/tests/typ/layout/place.typ index 527e0559..527e0559 100644 --- a/tests/typ/layout/placed.typ +++ b/tests/typ/layout/place.typ diff --git a/tests/typ/layout/aspect.typ b/tests/typ/layout/shape-aspect.typ index 2c3e9b0c..2c3e9b0c 100644 --- a/tests/typ/layout/aspect.typ +++ b/tests/typ/layout/shape-aspect.typ diff --git a/tests/typ/elements/circle.typ b/tests/typ/layout/shape-circle.typ index 8b795830..8b795830 100644 --- a/tests/typ/elements/circle.typ +++ b/tests/typ/layout/shape-circle.typ diff --git a/tests/typ/elements/ellipse.typ b/tests/typ/layout/shape-ellipse.typ index 154144c4..154144c4 100644 --- a/tests/typ/elements/ellipse.typ +++ b/tests/typ/layout/shape-ellipse.typ diff --git a/tests/typ/elements/fill-stroke.typ b/tests/typ/layout/shape-fill-stroke.typ index 3ae5f987..3ae5f987 100644 --- a/tests/typ/elements/fill-stroke.typ +++ b/tests/typ/layout/shape-fill-stroke.typ diff --git a/tests/typ/elements/rect.typ b/tests/typ/layout/shape-rect.typ index add39b80..add39b80 100644 --- a/tests/typ/elements/rect.typ +++ b/tests/typ/layout/shape-rect.typ diff --git a/tests/typ/elements/square.typ b/tests/typ/layout/shape-square.typ index c4ece778..c4ece778 100644 --- a/tests/typ/elements/square.typ +++ b/tests/typ/layout/shape-square.typ diff --git a/tests/typ/layout/spacing.typ b/tests/typ/layout/spacing.typ index 98a6100c..37aa8eaa 100644 --- a/tests/typ/layout/spacing.typ +++ b/tests/typ/layout/spacing.typ @@ -18,7 +18,17 @@ Add #h(10pt) #h(10pt) up | #h(1fr) | #h(2fr) | #h(1fr) | --- -// Test that spacing has style properties. +// Test spacing collapsing with parbreaks. +#v(0pt) +A +#v(0pt) +B +#v(0pt) + +C #parbreak() D + +--- +// Test that spacing can carry paragraph and page style properties. A[#set par(align: right);#h(1cm)]B [#set page(height: 20pt);#v(1cm)] diff --git a/tests/typ/markup/heading.typ b/tests/typ/markup/heading.typ index cb022617..2ae97aa8 100644 --- a/tests/typ/markup/heading.typ +++ b/tests/typ/markup/heading.typ @@ -39,3 +39,12 @@ is not. = A { "B" } + +--- +// Test styling. += Heading + +#set heading(family: "Roboto", fill: eastern) + +===== Heading 🌍 +#heading(level: 5)[Heading] diff --git a/tests/typ/style/set-block.typ b/tests/typ/style/set-block.typ new file mode 100644 index 00000000..f260acdc --- /dev/null +++ b/tests/typ/style/set-block.typ @@ -0,0 +1,10 @@ +// Test set in code blocks. + +--- +// Test that template in block is not affected by set +// rule in block ... +A{set text(fill: eastern); [B]}C + +--- +// ... no matter the order. +A{[B]; set text(fill: eastern)}C diff --git a/tests/typ/style/set-site.typ b/tests/typ/style/set-site.typ new file mode 100644 index 00000000..97a5672d --- /dev/null +++ b/tests/typ/style/set-site.typ @@ -0,0 +1,30 @@ +// Test that set affects the instantiation site and not the +// definition site of a template. + +--- +// Test that text is affected by instantion-site bold. +#let x = [World] +Hello *{x}* + +--- +// Test that lists are affected by correct indents. +#set par(spacing: 4pt) +#let fruit = [ + - Apple + - Orange + #set list(body-indent: 10pt) + - Pear +] + +- Fruit +[#set list(label-indent: 10pt) + #fruit] +- No more fruit + +--- +// Test that that par spacing and text style are respected from +// the outside, but the more specific fill is respected. +#set par(spacing: 4pt) +#set text(style: "italic", fill: eastern) +#let x = [And the forest #parbreak() lay silent!] +#text(fill: forest, x) diff --git a/tests/typ/style/set-toggle.typ b/tests/typ/style/set-toggle.typ new file mode 100644 index 00000000..9f26bdf7 --- /dev/null +++ b/tests/typ/style/set-toggle.typ @@ -0,0 +1,10 @@ +// Test set rules for toggleable booleans. + +--- +// Test toggling and untoggling. +*AB_C*DE +*_* + +--- +// Test toggling and nested templates. +*A[B*[_C]]D*E diff --git a/tests/typ/text/em.typ b/tests/typ/text/em.typ new file mode 100644 index 00000000..d9b00f06 --- /dev/null +++ b/tests/typ/text/em.typ @@ -0,0 +1,17 @@ +// Test font-relative sizing. + +--- +#set text(size: 5pt) +A // 5pt +[ + #set text(size: 200%) + B // 10pt + [ + #set text(size: 150% + 1pt) + C // 16pt + #text(size: 200%)[D] // 32pt + E // 16pt + ] + F // 10pt +] +G // 5pt diff --git a/tests/typ/text/par.typ b/tests/typ/text/par.typ index 771a6218..8bd43deb 100644 --- a/tests/typ/text/par.typ +++ b/tests/typ/text/par.typ @@ -16,6 +16,16 @@ To the right! Where the sunlight peeks behind the mountain. Third --- +// Test that paragraph spacing uses correct set rule. +Hello + +#set par(spacing: 100pt) +World +#set par(spacing: 0pt) + +You + +--- // Test that paragraph break due to incompatibility respects // spacing defined by the two adjacent paragraphs. #let a = [#set par(spacing: 40pt);Hello] diff --git a/tests/typ/text/whitespace.typ b/tests/typ/text/whitespace.typ index 4c3d4db5..831a5543 100644 --- a/tests/typ/text/whitespace.typ +++ b/tests/typ/text/whitespace.typ @@ -1,32 +1,21 @@ // Test whitespace handling. --- -// Spacing around let. +// Spacing around code constructs. A#let x = 1;B #test(x, 1) \ -A #let x = 2;B #test(x, 2) \ -A#let x = 3; B #test(x, 3) +C #let x = 2;D #test(x, 2) \ +E#if true [F]G \ +H #if true{"I"} J \ +K #if true [L] else []M \ +#let c = true; N#while c [{c = false}O] P \ +#let c = true; Q #while c { c = false; "R" } S \ +T#for _ in (none,) {"U"}V --- -// Spacing around if-else. -A#if true [B]C \ -A#if true [B] C \ -A #if true{"B"}C \ -A #if true{"B"} C \ -A#if false [] else [B]C \ -A#if true [B] else [] C - ---- -// Spacing around while loop. -#let c = true; A#while c [{c = false}B]C \ -#let c = true; A#while c [{c = false}B] C \ -#let c = true; A #while c { c = false; "B" }C \ -#let c = true; A #while c { c = false; "B" } C - ---- -// Spacing around for loop. -A#for _ in (none,) [B]C \ -A#for _ in (none,) [B] C \ -A #for _ in (none,) {"B"}C +// Test spacing with comments. +A/**/B/**/C \ +A /**/ B/**/C \ +A /**/B/**/ C --- // Test that a run consisting only of whitespace isn't trimmed. @@ -37,7 +26,11 @@ A[#set text(serif); ]B Left [#set text(serif);Right]. --- -// Test that space at start of line is not trimmed. +// Test that linebreak consumed surrounding spaces. +#align(center)[A \ B \ C] + +--- +// Test that space at start of non-backslash-linebreak line isn't trimmed. A{"\n"} B --- diff --git a/tests/typeset.rs b/tests/typeset.rs index 03bd9920..c53250b3 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -17,9 +17,9 @@ use typst::font::Face; use typst::frame::{Element, Frame, Geometry, Group, Shape, Stroke, Text}; use typst::geom::{self, Color, Length, Paint, PathElement, RgbaColor, Size, Transform}; use typst::image::{Image, RasterImage, Svg}; -use typst::layout::layout; #[cfg(feature = "layout-cache")] -use typst::library::{DocumentNode, PageNode, TextNode}; +use typst::layout::RootNode; +use typst::library::{PageNode, TextNode}; use typst::loading::FsLoader; use typst::parse::Scanner; use typst::source::SourceFile; @@ -254,16 +254,17 @@ fn test_part( let compare_ref = local_compare_ref.unwrap_or(compare_ref); let mut ok = true; - let (frames, mut errors) = match ctx.execute(id) { - Ok(document) => { + let (frames, mut errors) = match ctx.evaluate(id) { + Ok(module) => { + let tree = module.into_root(); if debug { - println!("{:#?}", document); + println!("{:#?}", tree); } - let mut frames = layout(ctx, &document); + let mut frames = tree.layout(ctx); #[cfg(feature = "layout-cache")] - (ok &= test_incremental(ctx, i, &document, &frames)); + (ok &= test_incremental(ctx, i, &tree, &frames)); if !compare_ref { frames.clear(); @@ -311,7 +312,7 @@ fn test_part( fn test_incremental( ctx: &mut Context, i: usize, - document: &DocumentNode, + tree: &RootNode, frames: &[Rc<Frame>], ) -> bool { let mut ok = true; @@ -326,7 +327,7 @@ fn test_incremental( ctx.layouts.turnaround(); - let cached = silenced(|| layout(ctx, document)); + let cached = silenced(|| tree.layout(ctx)); let misses = ctx .layouts .entries() |
