summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--bench/src/bench.rs2
-rw-r--r--src/layout/spacing.rs2
-rw-r--r--tests/README.md5
-rw-r--r--tests/ref/basics.pngbin5179 -> 0 bytes
-rw-r--r--tests/ref/full/coma.png (renamed from tests/ref/example-coma.png)bin27418 -> 27418 bytes
-rw-r--r--tests/ref/func-page.pngbin8099 -> 0 bytes
-rw-r--r--tests/ref/lang/arrays.png (renamed from tests/ref/arrays.png)bin3479 -> 3479 bytes
-rw-r--r--tests/ref/lang/basics.pngbin0 -> 5051 bytes
-rw-r--r--tests/ref/lang/comments.png (renamed from tests/ref/comments.png)bin1332 -> 1332 bytes
-rw-r--r--tests/ref/lang/dictionaries.png (renamed from tests/ref/dictionaries.png)bin1769 -> 1769 bytes
-rw-r--r--tests/ref/lang/empty.png (renamed from tests/ref/empty.png)bin94 -> 94 bytes
-rw-r--r--tests/ref/lang/escaping.png (renamed from tests/ref/escaping.png)bin4148 -> 4148 bytes
-rw-r--r--tests/ref/lang/headings.png (renamed from tests/ref/headings.png)bin7850 -> 7850 bytes
-rw-r--r--tests/ref/library/font.png (renamed from tests/ref/func-font.png)bin5386 -> 5386 bytes
-rw-r--r--tests/ref/library/hv.png (renamed from tests/ref/func-hv.png)bin3961 -> 3961 bytes
-rw-r--r--tests/ref/library/image.png (renamed from tests/ref/func-image.png)bin220343 -> 220343 bytes
-rw-r--r--tests/ref/library/page.pngbin0 -> 8097 bytes
-rw-r--r--tests/ref/library/pagebreak.png (renamed from tests/ref/func-pagebreak.png)bin821 -> 821 bytes
-rw-r--r--tests/ref/library/rgb.png (renamed from tests/ref/func-rgb.png)bin2688 -> 2688 bytes
-rw-r--r--tests/typ/full/coma.typ (renamed from tests/typ/example-coma.typ)2
-rw-r--r--tests/typ/lang/arrays.typ (renamed from tests/typ/arrays.typ)0
-rw-r--r--tests/typ/lang/basics.typ (renamed from tests/typ/basics.typ)8
-rw-r--r--tests/typ/lang/comments.typ (renamed from tests/typ/comments.typ)0
-rw-r--r--tests/typ/lang/dictionaries.typ (renamed from tests/typ/dictionaries.typ)0
-rw-r--r--tests/typ/lang/empty.typ (renamed from tests/typ/empty.typ)0
-rw-r--r--tests/typ/lang/escaping.typ (renamed from tests/typ/escaping.typ)0
-rw-r--r--tests/typ/lang/headings.typ (renamed from tests/typ/headings.typ)6
-rw-r--r--tests/typ/library/font.typ (renamed from tests/typ/func-font.typ)34
-rw-r--r--tests/typ/library/hv.typ (renamed from tests/typ/func-hv.typ)2
-rw-r--r--tests/typ/library/image.typ (renamed from tests/typ/func-image.typ)17
-rw-r--r--tests/typ/library/page.typ (renamed from tests/typ/func-page.typ)30
-rw-r--r--tests/typ/library/pagebreak.typ (renamed from tests/typ/func-pagebreak.typ)2
-rw-r--r--tests/typ/library/rgb.typ (renamed from tests/typ/func-rgb.typ)2
-rw-r--r--tests/typeset.rs43
35 files changed, 60 insertions, 96 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 4492c84b..dba398a5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,6 +25,7 @@ serde = { version = "1", features = ["derive"], optional = true }
[dev-dependencies]
tiny-skia = "0.2"
+walkdir = "2"
[profile.dev]
opt-level = 2
diff --git a/bench/src/bench.rs b/bench/src/bench.rs
index b8093d53..58ecf9fd 100644
--- a/bench/src/bench.rs
+++ b/bench/src/bench.rs
@@ -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 {
diff --git a/src/layout/spacing.rs b/src/layout/spacing.rs
index f0024fab..1d6c7f9c 100644
--- a/src/layout/spacing.rs
+++ b/src/layout/spacing.rs
@@ -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.
diff --git a/tests/README.md b/tests/README.md
index fef13482..429207a5 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -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.
diff --git a/tests/ref/basics.png b/tests/ref/basics.png
deleted file mode 100644
index fbe85320..00000000
--- a/tests/ref/basics.png
+++ /dev/null
Binary files differ
diff --git a/tests/ref/example-coma.png b/tests/ref/full/coma.png
index 0c18b810..0c18b810 100644
--- a/tests/ref/example-coma.png
+++ b/tests/ref/full/coma.png
Binary files differ
diff --git a/tests/ref/func-page.png b/tests/ref/func-page.png
deleted file mode 100644
index fb1b7b39..00000000
--- a/tests/ref/func-page.png
+++ /dev/null
Binary files differ
diff --git a/tests/ref/arrays.png b/tests/ref/lang/arrays.png
index 2d70a3f6..2d70a3f6 100644
--- a/tests/ref/arrays.png
+++ b/tests/ref/lang/arrays.png
Binary files differ
diff --git a/tests/ref/lang/basics.png b/tests/ref/lang/basics.png
new file mode 100644
index 00000000..3c3dd7a0
--- /dev/null
+++ b/tests/ref/lang/basics.png
Binary files differ
diff --git a/tests/ref/comments.png b/tests/ref/lang/comments.png
index e3e42d23..e3e42d23 100644
--- a/tests/ref/comments.png
+++ b/tests/ref/lang/comments.png
Binary files differ
diff --git a/tests/ref/dictionaries.png b/tests/ref/lang/dictionaries.png
index aa40549e..aa40549e 100644
--- a/tests/ref/dictionaries.png
+++ b/tests/ref/lang/dictionaries.png
Binary files differ
diff --git a/tests/ref/empty.png b/tests/ref/lang/empty.png
index 87c06b0a..87c06b0a 100644
--- a/tests/ref/empty.png
+++ b/tests/ref/lang/empty.png
Binary files differ
diff --git a/tests/ref/escaping.png b/tests/ref/lang/escaping.png
index 575a4b2f..575a4b2f 100644
--- a/tests/ref/escaping.png
+++ b/tests/ref/lang/escaping.png
Binary files differ
diff --git a/tests/ref/headings.png b/tests/ref/lang/headings.png
index 1f374cce..1f374cce 100644
--- a/tests/ref/headings.png
+++ b/tests/ref/lang/headings.png
Binary files differ
diff --git a/tests/ref/func-font.png b/tests/ref/library/font.png
index 1e025c6f..1e025c6f 100644
--- a/tests/ref/func-font.png
+++ b/tests/ref/library/font.png
Binary files differ
diff --git a/tests/ref/func-hv.png b/tests/ref/library/hv.png
index ee649fb6..ee649fb6 100644
--- a/tests/ref/func-hv.png
+++ b/tests/ref/library/hv.png
Binary files differ
diff --git a/tests/ref/func-image.png b/tests/ref/library/image.png
index 70f263e6..70f263e6 100644
--- a/tests/ref/func-image.png
+++ b/tests/ref/library/image.png
Binary files differ
diff --git a/tests/ref/library/page.png b/tests/ref/library/page.png
new file mode 100644
index 00000000..97557437
--- /dev/null
+++ b/tests/ref/library/page.png
Binary files differ
diff --git a/tests/ref/func-pagebreak.png b/tests/ref/library/pagebreak.png
index 16eae0e4..16eae0e4 100644
--- a/tests/ref/func-pagebreak.png
+++ b/tests/ref/library/pagebreak.png
Binary files differ
diff --git a/tests/ref/func-rgb.png b/tests/ref/library/rgb.png
index 3060e42c..3060e42c 100644
--- a/tests/ref/func-rgb.png
+++ b/tests/ref/library/rgb.png
Binary files differ
diff --git a/tests/typ/example-coma.typ b/tests/typ/full/coma.typ
index 5374af1f..b7863fce 100644
--- a/tests/typ/example-coma.typ
+++ b/tests/typ/full/coma.typ
@@ -1,5 +1,3 @@
-// Test integration of syntax, library and layouting.
-
[page width: 450pt, height: 300pt, margins: 1cm]
[box][
diff --git a/tests/typ/arrays.typ b/tests/typ/lang/arrays.typ
index 0b8fb866..0b8fb866 100644
--- a/tests/typ/arrays.typ
+++ b/tests/typ/lang/arrays.typ
diff --git a/tests/typ/basics.typ b/tests/typ/lang/basics.typ
index b7630e7f..9220e376 100644
--- a/tests/typ/basics.typ
+++ b/tests/typ/lang/basics.typ
@@ -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
diff --git a/tests/typ/comments.typ b/tests/typ/lang/comments.typ
index 56906d0c..56906d0c 100644
--- a/tests/typ/comments.typ
+++ b/tests/typ/lang/comments.typ
diff --git a/tests/typ/dictionaries.typ b/tests/typ/lang/dictionaries.typ
index c729b92c..c729b92c 100644
--- a/tests/typ/dictionaries.typ
+++ b/tests/typ/lang/dictionaries.typ
diff --git a/tests/typ/empty.typ b/tests/typ/lang/empty.typ
index e69de29b..e69de29b 100644
--- a/tests/typ/empty.typ
+++ b/tests/typ/lang/empty.typ
diff --git a/tests/typ/escaping.typ b/tests/typ/lang/escaping.typ
index cb663612..cb663612 100644
--- a/tests/typ/escaping.typ
+++ b/tests/typ/lang/escaping.typ
diff --git a/tests/typ/headings.typ b/tests/typ/lang/headings.typ
index 0f364a9b..f62f6534 100644
--- a/tests/typ/headings.typ
+++ b/tests/typ/lang/headings.typ
@@ -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"
diff --git a/tests/typ/func-font.typ b/tests/typ/library/font.typ
index 8199ecb4..beaddd4e 100644
--- a/tests/typ/func-font.typ
+++ b/tests/typ/library/font.typ
@@ -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"]
diff --git a/tests/typ/func-hv.typ b/tests/typ/library/hv.typ
index b32a645c..36a6d242 100644
--- a/tests/typ/func-hv.typ
+++ b/tests/typ/library/hv.typ
@@ -1,5 +1,3 @@
-// Test the `h` and `v` functions.
-
// Ends paragraphs.
Tightly [v -5pt] packed
diff --git a/tests/typ/func-image.typ b/tests/typ/library/image.typ
index 1f94a66f..2e7b1eb5 100644
--- a/tests/typ/func-image.typ
+++ b/tests/typ/library/image.typ
@@ -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"]
diff --git a/tests/typ/func-page.typ b/tests/typ/library/page.typ
index 49671e14..9eeddc93 100644
--- a/tests/typ/func-page.typ
+++ b/tests/typ/library/page.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]
diff --git a/tests/typ/func-pagebreak.typ b/tests/typ/library/pagebreak.typ
index 603e11d4..2f539ce0 100644
--- a/tests/typ/func-pagebreak.typ
+++ b/tests/typ/library/pagebreak.typ
@@ -1,5 +1,3 @@
-// Test trailing pagebreak.
-
First of two
[pagebreak]
[page height: 40pt]
diff --git a/tests/typ/func-rgb.typ b/tests/typ/library/rgb.typ
index d29c2940..66d63d0d 100644
--- a/tests/typ/func-rgb.typ
+++ b/tests/typ/library/rgb.typ
@@ -1,5 +1,3 @@
-// Test the `rgb` function.
-
// Check the output.
[rgb 0.0, 0.3, 0.7]
diff --git a/tests/typeset.rs b/tests/typeset.rs
index f67649b0..79a884eb 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -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