Move test files into category subfolders 🚚
@ -25,6 +25,7 @@ serde = { version = "1", features = ["derive"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
tiny-skia = "0.2"
|
||||
walkdir = "2"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 2
|
||||
|
@ -13,7 +13,7 @@ use typst::parse::parse;
|
||||
use typst::typeset;
|
||||
|
||||
const FONT_DIR: &str = "../fonts";
|
||||
const COMA: &str = include_str!("../../tests/typ/example-coma.typ");
|
||||
const COMA: &str = include_str!("../../tests/typ/full/coma.typ");
|
||||
|
||||
fn benchmarks(c: &mut Criterion) {
|
||||
macro_rules! bench {
|
||||
|
@ -3,7 +3,7 @@ use std::fmt::{self, Debug, Formatter};
|
||||
use super::*;
|
||||
use crate::eval::Softness;
|
||||
|
||||
/// A spacing node.
|
||||
/// A spacing node.
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub struct NodeSpacing {
|
||||
/// The amount of spacing to insert.
|
||||
|
@ -8,3 +8,8 @@
|
||||
- `res`: Resource files used by tests.
|
||||
- `png`: PNG files produced by tests.
|
||||
- `pdf`: PDF files produced by tests.
|
||||
|
||||
The test files are split into three categories:
|
||||
- `full`: Tests of full documents.
|
||||
- `lang`: Tests for specific language features.
|
||||
- `library`: Tests for specific library functions.
|
||||
|
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
BIN
tests/ref/lang/basics.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 94 B After Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 215 KiB |
BIN
tests/ref/library/page.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 821 B After Width: | Height: | Size: 821 B |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
@ -1,5 +1,3 @@
|
||||
// Test integration of syntax, library and layouting.
|
||||
|
||||
[page width: 450pt, height: 300pt, margins: 1cm]
|
||||
|
||||
[box][
|
@ -1,17 +1,9 @@
|
||||
// Test text, emph and strong.
|
||||
|
||||
Hello 🌏!
|
||||
|
||||
_Emph_ and *strong*!
|
||||
|
||||
---
|
||||
// Test non-breaking space.
|
||||
|
||||
The non-breaking~space does not work.
|
||||
|
||||
---
|
||||
// Test backslash.
|
||||
|
||||
// Directly after word.
|
||||
Line\ Break
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Number of hashtags.
|
||||
// Test different numbers of hashtags.
|
||||
|
||||
# One
|
||||
### Three
|
||||
@ -8,7 +8,7 @@
|
||||
####### Seven
|
||||
|
||||
---
|
||||
// Heading vs. no heading.
|
||||
// Test heading vs. no heading.
|
||||
|
||||
/**/ # Heading
|
||||
{[## Heading]}
|
||||
@ -24,7 +24,7 @@ Nr#1
|
||||
#nope
|
||||
|
||||
---
|
||||
// Heading continues over linebreak.
|
||||
// Heading continuation over linebreak.
|
||||
|
||||
# This {
|
||||
"works"
|
@ -19,8 +19,22 @@
|
||||
// Set stretch (not available, matching closest).
|
||||
[font stretch: ultra-condensed][Condensed]
|
||||
|
||||
// Error: 1:7-1:12 unexpected argument
|
||||
[font false]
|
||||
|
||||
// Error: 3:14-3:18 expected font style, found font weight
|
||||
// Error: 2:28-2:34 expected font weight, found string
|
||||
// Error: 1:43-1:44 expected font family or array of font families, found integer
|
||||
[font style: bold, weight: "thin", serif: 0]
|
||||
|
||||
// Warning: 1:15-1:19 must be between 100 and 900
|
||||
[font weight: 2700]
|
||||
|
||||
// Error: 1:7-1:27 unexpected argument
|
||||
[font something: "invalid"]
|
||||
|
||||
---
|
||||
// Test font fallback.
|
||||
// Test font fallback and class definitions.
|
||||
|
||||
// Source Sans Pro + Segoe UI Emoji.
|
||||
Emoji: 🏀
|
||||
@ -40,21 +54,3 @@ Emoji: 🏀
|
||||
[font sans-serif: "Noto Emoji"]
|
||||
[font sans-serif: ("Archivo", sans-serif)]
|
||||
New sans-serif. 🚀
|
||||
|
||||
---
|
||||
// Test error cases.
|
||||
// Ref: false
|
||||
|
||||
// Error: 1:7-1:12 unexpected argument
|
||||
[font false]
|
||||
|
||||
// Error: 3:14-3:18 expected font style, found font weight
|
||||
// Error: 2:28-2:34 expected font weight, found string
|
||||
// Error: 1:43-1:44 expected font family or array of font families, found integer
|
||||
[font style: bold, weight: "thin", serif: 0]
|
||||
|
||||
// Warning: 1:15-1:19 must be between 100 and 900
|
||||
[font weight: 2700]
|
||||
|
||||
// Error: 1:7-1:27 unexpected argument
|
||||
[font something: "invalid"]
|
@ -1,5 +1,3 @@
|
||||
// Test the `h` and `v` functions.
|
||||
|
||||
// Ends paragraphs.
|
||||
Tightly [v -5pt] packed
|
||||
|
@ -7,6 +7,12 @@
|
||||
// Load an RGB JPEG image.
|
||||
[image "res/tiger.jpg"]
|
||||
|
||||
// Error: 1:8-1:29 failed to load image
|
||||
[image "path/does/not/exist"]
|
||||
|
||||
// Error: 1:8-1:29 failed to load image
|
||||
[image "typ/image-error.typ"]
|
||||
|
||||
---
|
||||
// Test configuring the size and fitting behaviour of images.
|
||||
|
||||
@ -31,14 +37,3 @@
|
||||
[align bottom, right][
|
||||
[image "res/tiger.jpg", width: 60pt]
|
||||
]
|
||||
|
||||
---
|
||||
// Test error cases.
|
||||
//
|
||||
// Ref: false
|
||||
|
||||
// Error: 1:8-1:29 failed to load image
|
||||
[image "path/does/not/exist"]
|
||||
|
||||
// Error: 1:8-1:29 failed to load image
|
||||
[image "typ/image-error.typ"]
|
@ -21,8 +21,11 @@
|
||||
// Ensure that specific margins override general margins.
|
||||
[page margins: 0pt, left: 20pt][Overriden]
|
||||
|
||||
---
|
||||
// Test flipping.
|
||||
// Error: 1:7-1:18 unknown variable
|
||||
[page nonexistant]
|
||||
|
||||
// Error: 1:17-1:20 aligned axis
|
||||
[page main-dir: ltr]
|
||||
|
||||
// Flipped predefined paper.
|
||||
[page "a11", flip: true][Flipped A11]
|
||||
@ -32,6 +35,11 @@
|
||||
[page flip: true]
|
||||
Wide
|
||||
|
||||
// Test changing the layouting directions of pages.
|
||||
|
||||
[page height: 50pt, main-dir: btt, cross-dir: rtl]
|
||||
Right to left!
|
||||
|
||||
---
|
||||
// Test a combination of pages with bodies and normal content.
|
||||
|
||||
@ -44,21 +52,3 @@ Fourth
|
||||
[page][]
|
||||
Sixth
|
||||
[page][Seventh and last]
|
||||
|
||||
---
|
||||
// Test changing the layouting directions of pages.
|
||||
|
||||
[page height: 50pt, main-dir: btt, cross-dir: rtl]
|
||||
|
||||
Right to left!
|
||||
|
||||
---
|
||||
// Test error cases.
|
||||
//
|
||||
// Ref: false
|
||||
|
||||
// Error: 1:7-1:18 unknown variable
|
||||
[page nonexistant]
|
||||
|
||||
// Error: 1:17-1:20 aligned axis
|
||||
[page main-dir: ltr]
|
@ -1,5 +1,3 @@
|
||||
// Test trailing pagebreak.
|
||||
|
||||
First of two
|
||||
[pagebreak]
|
||||
[page height: 40pt]
|
@ -1,5 +1,3 @@
|
||||
// Test the `rgb` function.
|
||||
|
||||
// Check the output.
|
||||
[rgb 0.0, 0.3, 0.7]
|
||||
|
@ -12,6 +12,7 @@ use tiny_skia::{
|
||||
Rect, SpreadMode, Transform,
|
||||
};
|
||||
use ttf_parser::OutlineBuilder;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use typst::diag::{Diag, Feedback, Level, Pass};
|
||||
use typst::env::{Env, ImageResource, ResourceLoader, SharedEnv};
|
||||
@ -37,15 +38,15 @@ fn main() {
|
||||
let filter = TestFilter::new(env::args().skip(1));
|
||||
let mut filtered = Vec::new();
|
||||
|
||||
for entry in fs::read_dir(TYP_DIR).unwrap() {
|
||||
let src_path = entry.unwrap().path();
|
||||
for entry in WalkDir::new(TYP_DIR).into_iter() {
|
||||
let entry = entry.unwrap();
|
||||
let src_path = entry.into_path();
|
||||
if src_path.extension() != Some(OsStr::new("typ")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = src_path.file_stem().unwrap().to_string_lossy().to_string();
|
||||
if filter.matches(&name) {
|
||||
filtered.push((name, src_path));
|
||||
if filter.matches(&src_path.to_string_lossy().to_string()) {
|
||||
filtered.push(src_path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,9 +57,6 @@ fn main() {
|
||||
println!("Running {} tests", len);
|
||||
}
|
||||
|
||||
fs::create_dir_all(PNG_DIR).unwrap();
|
||||
fs::create_dir_all(PDF_DIR).unwrap();
|
||||
|
||||
let mut index = FsIndex::new();
|
||||
index.search_dir(FONT_DIR);
|
||||
|
||||
@ -69,9 +67,8 @@ fn main() {
|
||||
}));
|
||||
|
||||
let playground = Path::new("playground.typ");
|
||||
if playground.exists() {
|
||||
if playground.exists() && filtered.is_empty() {
|
||||
test(
|
||||
"playground",
|
||||
playground,
|
||||
Path::new("playground.png"),
|
||||
Path::new("playground.pdf"),
|
||||
@ -81,18 +78,12 @@ fn main() {
|
||||
}
|
||||
|
||||
let mut ok = true;
|
||||
for (name, src_path) in filtered {
|
||||
let png_path = Path::new(PNG_DIR).join(&name).with_extension("png");
|
||||
let pdf_path = Path::new(PDF_DIR).join(&name).with_extension("pdf");
|
||||
let ref_path = Path::new(REF_DIR).join(&name).with_extension("png");
|
||||
ok &= test(
|
||||
&name,
|
||||
&src_path,
|
||||
&png_path,
|
||||
&pdf_path,
|
||||
Some(&ref_path),
|
||||
&env,
|
||||
);
|
||||
for src_path in filtered {
|
||||
let relative = src_path.strip_prefix(TYP_DIR).unwrap();
|
||||
let png_path = Path::new(PNG_DIR).join(&relative).with_extension("png");
|
||||
let pdf_path = Path::new(PDF_DIR).join(&relative).with_extension("pdf");
|
||||
let ref_path = Path::new(REF_DIR).join(&relative).with_extension("png");
|
||||
ok &= test(&src_path, &png_path, &pdf_path, Some(&ref_path), &env);
|
||||
}
|
||||
|
||||
if !ok {
|
||||
@ -131,14 +122,14 @@ impl TestFilter {
|
||||
}
|
||||
|
||||
fn test(
|
||||
name: &str,
|
||||
src_path: &Path,
|
||||
png_path: &Path,
|
||||
pdf_path: &Path,
|
||||
ref_path: Option<&Path>,
|
||||
env: &SharedEnv,
|
||||
) -> bool {
|
||||
println!("Testing {}.", name);
|
||||
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
|
||||
println!("Testing {}", name.display());
|
||||
|
||||
let src = fs::read_to_string(src_path).unwrap();
|
||||
|
||||
@ -154,9 +145,11 @@ fn test(
|
||||
let env = env.borrow();
|
||||
if !frames.is_empty() {
|
||||
let pdf_data = pdf::export(&frames, &env);
|
||||
fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
|
||||
fs::write(pdf_path, pdf_data).unwrap();
|
||||
|
||||
let canvas = draw(&frames, &env, 2.0);
|
||||
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
|
||||
canvas.pixmap.save_png(png_path).unwrap();
|
||||
|
||||
if let Some(ref_path) = ref_path {
|
||||
@ -173,7 +166,7 @@ fn test(
|
||||
}
|
||||
|
||||
if ok {
|
||||
println!("\x1b[1ATesting {}. ✔", name);
|
||||
println!("\x1b[1ATesting {} ✔", name.display());
|
||||
}
|
||||
|
||||
ok
|
||||
|