summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-26 23:42:40 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-26 23:52:01 +0100
commit6bafc6391061d4b589dea835705a08b25a4df9f8 (patch)
tree4add85f17fc56da341acfb58a223ea20d80c280a /tests
parent0579fd4409375aaa9fd8e87a06fd59097b5fcd97 (diff)
Document metadata
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/layout/page-box.pngbin756 -> 0 bytes
-rw-r--r--tests/src/benches.rs4
-rw-r--r--tests/src/tests.rs13
-rw-r--r--tests/typ/layout/page-box.typ14
-rw-r--r--tests/typ/style/document.typ30
5 files changed, 39 insertions, 22 deletions
diff --git a/tests/ref/layout/page-box.png b/tests/ref/layout/page-box.png
deleted file mode 100644
index c8d0320c..00000000
--- a/tests/ref/layout/page-box.png
+++ /dev/null
Binary files differ
diff --git a/tests/src/benches.rs b/tests/src/benches.rs
index 754f80a9..1ae012eb 100644
--- a/tests/src/benches.rs
+++ b/tests/src/benches.rs
@@ -94,8 +94,8 @@ fn bench_compile(iai: &mut Iai) {
fn bench_render(iai: &mut Iai) {
let world = BenchWorld::new();
- let frames = typst::compile(&world, &world.source).unwrap();
- iai.run(|| typst::export::render(&frames[0], 1.0))
+ let document = typst::compile(&world, &world.source).unwrap();
+ iai.run(|| typst::export::render(&document.pages[0], 1.0))
}
struct BenchWorld {
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index f96c651b..215d7fe7 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -12,8 +12,8 @@ use elsa::FrozenVec;
use once_cell::unsync::OnceCell;
use tiny_skia as sk;
use typst::diag::{bail, FileError, FileResult};
+use typst::doc::{Document, Element, Frame, Metadata};
use typst::font::{Font, FontBook};
-use typst::frame::{Element, Frame};
use typst::geom::{Abs, RgbaColor, Sides};
use typst::model::{Library, Smart, Value};
use typst::syntax::{Source, SourceId, SyntaxNode};
@@ -349,20 +349,21 @@ fn test(
line += part.lines().count() + 1;
}
+ let document = Document { pages: frames, metadata: Metadata::default() };
if compare_ever {
if let Some(pdf_path) = pdf_path {
- let pdf_data = typst::export::pdf(&frames);
+ let pdf_data = typst::export::pdf(&document);
fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
fs::write(pdf_path, pdf_data).unwrap();
}
if world.print.frames {
- for frame in &frames {
+ for frame in &document.pages {
println!("Frame:\n{:#?}\n", frame);
}
}
- let canvas = render(&frames);
+ let canvas = render(&document.pages);
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
canvas.save_png(png_path).unwrap();
@@ -378,7 +379,7 @@ fn test(
println!(" Does not match reference image. ❌");
ok = false;
}
- } else if !frames.is_empty() {
+ } else if !document.pages.is_empty() {
println!(" Failed to open reference image. ❌");
ok = false;
}
@@ -425,7 +426,7 @@ fn test_part(
}
let (mut frames, errors) = match typst::compile(world, source) {
- Ok(frames) => (frames, vec![]),
+ Ok(document) => (document.pages, vec![]),
Err(errors) => (vec![], *errors),
};
diff --git a/tests/typ/layout/page-box.typ b/tests/typ/layout/page-box.typ
deleted file mode 100644
index ed9d3e14..00000000
--- a/tests/typ/layout/page-box.typ
+++ /dev/null
@@ -1,14 +0,0 @@
-// Test that you can't do page related stuff in a container.
-
----
-A
-#box[
- B
- #pagebreak()
- #set page("a4")
-]
-C
-
-// No consequences from the page("A4") call here.
-#pagebreak()
-D
diff --git a/tests/typ/style/document.typ b/tests/typ/style/document.typ
new file mode 100644
index 00000000..1fcb8109
--- /dev/null
+++ b/tests/typ/style/document.typ
@@ -0,0 +1,30 @@
+// Test document and page-level styles.
+
+---
+// This is okay.
+// Ref: false
+#set document(title: "Hello")
+
+---
+Hello
+
+// Error: 1-30 must appear before any content
+#set document(title: "Hello")
+
+---
+#box[
+ // Error: 3-32 not allowed here
+ #set document(title: "Hello")
+]
+
+---
+#box[
+ // Error: 3-18 not allowed here
+ #set page("a4")
+]
+
+---
+#box[
+ // Error: 3-15 not allowed here
+ #pagebreak()
+]