From 81e80ecfba80f5bffab45719c1f2aba4f9b91b4f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 17 Dec 2020 00:20:27 +0100 Subject: =?UTF-8?q?Test=20[page]=20function=20=F0=9F=93=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Make page break behaviour more consistent - Allow skipping reference image testing for single tests with `// compare-ref: false` (useful for tests which only check error messages) --- tests/ref/image-error.png | Bin 120 -> 0 bytes tests/ref/image-formats.png | Bin 0 -> 107778 bytes tests/ref/image-jpeg.png | Bin 69754 -> 0 bytes tests/ref/image-png.png | Bin 37986 -> 0 bytes tests/ref/page-body.png | Bin 0 -> 2974 bytes tests/ref/page-dirs.png | Bin 0 -> 1030 bytes tests/ref/page-metrics.png | Bin 0 -> 5092 bytes tests/typ/example-coma.typ | 2 +- tests/typ/image-error.typ | 5 ++++- tests/typ/image-fit.typ | 2 ++ tests/typ/image-formats.typ | 8 ++++++++ tests/typ/image-jpeg.typ | 2 -- tests/typ/image-png.typ | 2 -- tests/typ/page-body.typ | 11 +++++++++++ tests/typ/page-dirs.typ | 5 +++++ tests/typ/page-error.typ | 11 +++++++++++ tests/typ/page-metrics.typ | 25 +++++++++++++++++++++++++ tests/typeset.rs | 24 +++++++++++++++--------- 18 files changed, 82 insertions(+), 15 deletions(-) delete mode 100644 tests/ref/image-error.png create mode 100644 tests/ref/image-formats.png delete mode 100644 tests/ref/image-jpeg.png delete mode 100644 tests/ref/image-png.png create mode 100644 tests/ref/page-body.png create mode 100644 tests/ref/page-dirs.png create mode 100644 tests/ref/page-metrics.png create mode 100644 tests/typ/image-formats.typ delete mode 100644 tests/typ/image-jpeg.typ delete mode 100644 tests/typ/image-png.typ create mode 100644 tests/typ/page-body.typ create mode 100644 tests/typ/page-dirs.typ create mode 100644 tests/typ/page-error.typ create mode 100644 tests/typ/page-metrics.typ (limited to 'tests') diff --git a/tests/ref/image-error.png b/tests/ref/image-error.png deleted file mode 100644 index 812a3758..00000000 Binary files a/tests/ref/image-error.png and /dev/null differ diff --git a/tests/ref/image-formats.png b/tests/ref/image-formats.png new file mode 100644 index 00000000..45b23276 Binary files /dev/null and b/tests/ref/image-formats.png differ diff --git a/tests/ref/image-jpeg.png b/tests/ref/image-jpeg.png deleted file mode 100644 index ef9e74cb..00000000 Binary files a/tests/ref/image-jpeg.png and /dev/null differ diff --git a/tests/ref/image-png.png b/tests/ref/image-png.png deleted file mode 100644 index 4e0818d2..00000000 Binary files a/tests/ref/image-png.png and /dev/null differ diff --git a/tests/ref/page-body.png b/tests/ref/page-body.png new file mode 100644 index 00000000..a3b3d726 Binary files /dev/null and b/tests/ref/page-body.png differ diff --git a/tests/ref/page-dirs.png b/tests/ref/page-dirs.png new file mode 100644 index 00000000..2bf23ebc Binary files /dev/null and b/tests/ref/page-dirs.png differ diff --git a/tests/ref/page-metrics.png b/tests/ref/page-metrics.png new file mode 100644 index 00000000..2e8d626d Binary files /dev/null and b/tests/ref/page-metrics.png differ diff --git a/tests/typ/example-coma.typ b/tests/typ/example-coma.typ index f841a122..d41032c1 100644 --- a/tests/typ/example-coma.typ +++ b/tests/typ/example-coma.typ @@ -1,4 +1,4 @@ -// Small integration test of syntax, page setup, box layout and alignment. +// Test integration of syntax, page setup, box layout and alignment. [page: width=450pt, height=300pt, margins=1cm] diff --git a/tests/typ/image-error.typ b/tests/typ/image-error.typ index 4fde4ab2..9a7f2c40 100644 --- a/tests/typ/image-error.typ +++ b/tests/typ/image-error.typ @@ -1,5 +1,8 @@ -// error: 5:9-5:30 failed to load image +// Test error cases of the `image` function. + +// compare-ref: false // error: 8:9-8:30 failed to load image +// error: 11:9-11:30 failed to load image // File does not exist. [image: "path/does/not/exist"] diff --git a/tests/typ/image-fit.typ b/tests/typ/image-fit.typ index b735f058..eca7c1e4 100644 --- a/tests/typ/image-fit.typ +++ b/tests/typ/image-fit.typ @@ -1,3 +1,5 @@ +// Test configuring the size and fitting behaviour of images. + // Fit to width of page. [image: "res/rhino.png"] diff --git a/tests/typ/image-formats.typ b/tests/typ/image-formats.typ new file mode 100644 index 00000000..36b991d0 --- /dev/null +++ b/tests/typ/image-formats.typ @@ -0,0 +1,8 @@ +// Test loading different image formats. + +// Load an RGBA PNG image. +[image: "res/rhino.png"] +[pagebreak] + +// Load an RGB JPEG image. +[image: "res/tiger.jpg"] diff --git a/tests/typ/image-jpeg.typ b/tests/typ/image-jpeg.typ deleted file mode 100644 index 48cf1a0d..00000000 --- a/tests/typ/image-jpeg.typ +++ /dev/null @@ -1,2 +0,0 @@ -// Load an RGB JPEG image. -[image: "res/tiger.jpg"] diff --git a/tests/typ/image-png.typ b/tests/typ/image-png.typ deleted file mode 100644 index 482591e9..00000000 --- a/tests/typ/image-png.typ +++ /dev/null @@ -1,2 +0,0 @@ -// Load an RGBA PNG image. -[image: "res/rhino.png"] diff --git a/tests/typ/page-body.typ b/tests/typ/page-body.typ new file mode 100644 index 00000000..6067dcfe --- /dev/null +++ b/tests/typ/page-body.typ @@ -0,0 +1,11 @@ +// Test a combination of pages with bodies and normal content. + +[page: height=50pt] + +[page][First] +[page][Second] +[pagebreak] +Fourth +[page][Fifth] +Sixth +[page][Seventh and last] diff --git a/tests/typ/page-dirs.typ b/tests/typ/page-dirs.typ new file mode 100644 index 00000000..09ba4e9e --- /dev/null +++ b/tests/typ/page-dirs.typ @@ -0,0 +1,5 @@ +// Test changing the layouting directions of pages. + +[page: main-dir=btt, cross-dir=rtl] + +Right to left! diff --git a/tests/typ/page-error.typ b/tests/typ/page-error.typ new file mode 100644 index 00000000..dee5c449 --- /dev/null +++ b/tests/typ/page-error.typ @@ -0,0 +1,11 @@ +// Test error cases of the `page` function. + +// compare-ref: false +// error: 8:8-8:19 invalid paper +// error: 11:17-11:20 aligned axis + +// Invalid paper. +[page: nonexistant] + +// Aligned axes. +[page: main-dir=ltr] diff --git a/tests/typ/page-metrics.typ b/tests/typ/page-metrics.typ new file mode 100644 index 00000000..6c7bd461 --- /dev/null +++ b/tests/typ/page-metrics.typ @@ -0,0 +1,25 @@ +// Test configuring page sizes and margins. + +// Set width. +[page: width=50pt][High] + +// Set height. +[page: height=50pt][Wide] + +// Set all margins at once. +[page: margins=40pt][ + [align: top, left][TL] + [align: bottom, right][BR] +] + +// Set individual margins. +[page: left=0pt >> align: left][Left] +[page: right=0pt >> align: right][Right] +[page: top=0pt >> align: top][Top] +[page: bottom=0pt >> align: bottom][Bottom] + +// Ensure that specific margins override general margins. +[page: margins=0pt, left=40pt][Overriden] + +// Flip the page. +[page: a10, flip=true][Flipped] diff --git a/tests/typeset.rs b/tests/typeset.rs index 012aff63..5f108585 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -127,7 +127,7 @@ fn test( let src = fs::read_to_string(src_path).unwrap(); let map = LineMap::new(&src); - let ref_diags = parse_diags(&src, &map); + let (ref_diags, compare_ref) = parse_metadata(&src, &map); let mut state = State::default(); state.page.size = Size::uniform(Length::pt(120.0)); @@ -167,14 +167,16 @@ fn test( } } - if let Ok(ref_pixmap) = Pixmap::load_png(&ref_path) { - if canvas.pixmap != ref_pixmap { - println!(" Does not match reference image. ❌"); + if compare_ref { + if let Ok(ref_pixmap) = Pixmap::load_png(&ref_path) { + if canvas.pixmap != ref_pixmap { + println!(" Does not match reference image. ❌"); + ok = false; + } + } else { + println!(" Failed to open reference image. ❌"); ok = false; } - } else { - println!(" Failed to open reference image. ❌"); - ok = false; } if ok { @@ -184,10 +186,13 @@ fn test( ok } -fn parse_diags(src: &str, map: &LineMap) -> SpanVec { +fn parse_metadata(src: &str, map: &LineMap) -> (SpanVec, bool) { let mut diags = vec![]; + let mut compare_ref = true; for line in src.lines() { + compare_ref &= !line.starts_with("// compare-ref: false"); + let (level, rest) = if let Some(rest) = line.strip_prefix("// error: ") { (Level::Error, rest) } else if let Some(rest) = line.strip_prefix("// warning: ") { @@ -211,7 +216,8 @@ fn parse_diags(src: &str, map: &LineMap) -> SpanVec { } diags.sort(); - diags + + (diags, compare_ref) } fn print_diag(diag: &Spanned, map: &LineMap) { -- cgit v1.2.3