From ed50661378f356e02c6ec943bc4840091d33cfbd Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 22 Nov 2021 14:30:43 +0100 Subject: Castable optional and smart values --- tests/ref/elements/fill-stroke.png | Bin 0 -> 1942 bytes tests/ref/layout/page.png | Bin 5829 -> 4157 bytes tests/ref/layout/pagebreak.png | Bin 1254 -> 3145 bytes tests/typ/elements/fill-stroke.typ | 26 ++++++++++++++++++++++++++ tests/typ/layout/page.typ | 20 ++++---------------- tests/typ/layout/pagebreak.typ | 14 ++++++++++++++ tests/typ/text/features.typ | 8 ++++++++ tests/typeset.rs | 4 ++-- 8 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 tests/ref/elements/fill-stroke.png create mode 100644 tests/typ/elements/fill-stroke.typ (limited to 'tests') diff --git a/tests/ref/elements/fill-stroke.png b/tests/ref/elements/fill-stroke.png new file mode 100644 index 00000000..2d04b3dd Binary files /dev/null and b/tests/ref/elements/fill-stroke.png differ diff --git a/tests/ref/layout/page.png b/tests/ref/layout/page.png index dae3d488..57e4b8f1 100644 Binary files a/tests/ref/layout/page.png and b/tests/ref/layout/page.png differ diff --git a/tests/ref/layout/pagebreak.png b/tests/ref/layout/pagebreak.png index 043b5086..fbb1d00c 100644 Binary files a/tests/ref/layout/pagebreak.png and b/tests/ref/layout/pagebreak.png differ diff --git a/tests/typ/elements/fill-stroke.typ b/tests/typ/elements/fill-stroke.typ new file mode 100644 index 00000000..b8f2b4bc --- /dev/null +++ b/tests/typ/elements/fill-stroke.typ @@ -0,0 +1,26 @@ +// Test shape fill & stroke. + +--- +#let rect with (width: 20pt, height: 10pt) +#let items = for i, rect in ( + rect(stroke: none), + rect(), + rect(fill: none), + rect(thickness: 2pt), + rect(stroke: eastern), + rect(stroke: eastern, thickness: 2pt), + rect(fill: eastern), + rect(fill: eastern, stroke: none), + rect(fill: forest, stroke: none, thickness: 2pt), + rect(fill: forest, stroke: conifer), + rect(fill: forest, thickness: 2pt), + rect(fill: forest, stroke: conifer, thickness: 2pt), +) { + (align(vertical: center)[{i + 1}.], rect, []) +} + +#grid( + columns: (auto, auto, 1fr, auto, auto, 0fr), + gutter: 5pt, + ..items, +) diff --git a/tests/typ/layout/page.typ b/tests/typ/layout/page.typ index 9bb3097d..1f707327 100644 --- a/tests/typ/layout/page.typ +++ b/tests/typ/layout/page.typ @@ -26,21 +26,9 @@ // Flipped predefined paper. [#page(paper: "a11", flip: true) Flipped A11] ---- -// Test a combination of pages with bodies and normal content. - -#page(width: 80pt, height: 30pt) - -[#page() First] -[#page() Second] -#pagebreak() -#pagebreak() -Fourth -[#page(height: 25pt)] -Sixth -[#page() Seventh] - --- #page(width: 80pt, height: 40pt, fill: eastern) -#font(15pt, "Roboto", fill: white, smallcaps: true) -Typst +#font(15pt, "Roboto", fill: white, smallcaps: true)[Typst] + +#page(width: 40pt, fill: none, margins: auto, top: 10pt) +Hi diff --git a/tests/typ/layout/pagebreak.typ b/tests/typ/layout/pagebreak.typ index ab591c87..f9a935bc 100644 --- a/tests/typ/layout/pagebreak.typ +++ b/tests/typ/layout/pagebreak.typ @@ -18,3 +18,17 @@ C // No consequences from the page("A4") call here. #pagebreak() D + +--- +// Test a combination of pages with bodies and normal content. + +#page(width: 80pt, height: 30pt) + +[#page() First] +[#page() Second] +#pagebreak() +#pagebreak() +Fourth +[#page(height: 25pt)] +Sixth +[#page() Seventh] diff --git a/tests/typ/text/features.typ b/tests/typ/text/features.typ index fc84514b..d60583d8 100644 --- a/tests/typ/text/features.typ +++ b/tests/typ/text/features.typ @@ -52,10 +52,18 @@ fi vs. #font(ligatures: false)[No fi] \ #font(features: ("smcp",))[Smcp] \ fi vs. #font(features: (liga: 0))[No fi] +--- +// Error: 22-27 expected integer or none, found boolean +#font(stylistic-set: false) + --- // Error: 22-24 must be between 1 and 20 #font(stylistic-set: 25) +--- +// Error: 20-21 expected string or auto, found integer +#font(number-type: 2) + --- // Error: 20-31 expected "lining" or "old-style" #font(number-type: "different") diff --git a/tests/typeset.rs b/tests/typeset.rs index 723df4a8..6a21cf7b 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -10,7 +10,7 @@ use ttf_parser::{GlyphId, OutlineBuilder}; use walkdir::WalkDir; use typst::diag::Error; -use typst::eval::Value; +use typst::eval::{Smart, Value}; use typst::font::Face; use typst::frame::{Element, Frame, Geometry, Shape, Stroke, Text}; use typst::geom::{self, Color, Length, Paint, PathElement, RgbaColor, Sides, Size}; @@ -64,7 +64,7 @@ fn main() { // large and fit them to match their content. let mut style = Style::default(); style.page_mut().size = Size::new(Length::pt(120.0), Length::inf()); - style.page_mut().margins = Sides::splat(Some(Length::pt(10.0).into())); + style.page_mut().margins = Sides::splat(Smart::Custom(Length::pt(10.0).into())); style.text_mut().size = Length::pt(10.0); // Hook up an assert function into the global scope. -- cgit v1.2.3