summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/layout.rs19
-rw-r--r--tests/layouts/test.typ31
-rw-r--r--tests/render.py8
3 files changed, 49 insertions, 9 deletions
diff --git a/tests/layout.rs b/tests/layout.rs
index 33c12a2b..cca0dee0 100644
--- a/tests/layout.rs
+++ b/tests/layout.rs
@@ -23,10 +23,7 @@ fn main() -> Result<()> {
create_dir_all("tests/cache/pdf")?;
let tests: Vec<_> = read_dir("tests/layouts/")?.collect();
-
- let len = tests.len();
- println!();
- println!("Running {} test{}", len, if len > 1 { "s" } else { "" });
+ let mut filtered = Vec::new();
for entry in tests {
let path = entry?.path();
@@ -36,14 +33,23 @@ fn main() -> Result<()> {
let name = path
.file_stem().ok_or("expected file stem")?
- .to_string_lossy();
+ .to_string_lossy()
+ .to_string();
if opts.matches(&name) {
let src = read_to_string(&path)?;
- panic::catch_unwind(|| test(&name, &src)).ok();
+ filtered.push((name, src));
}
}
+ let len = filtered.len();
+ println!();
+ println!("Running {} test{}", len, if len > 1 { "s" } else { "" });
+
+ for (name, src) in filtered {
+ panic::catch_unwind(|| test(&name, &src)).ok();
+ }
+
println!();
Ok(())
@@ -79,6 +85,7 @@ fn test(name: &str, src: &str) -> Result<()> {
});
}
}
+ drop(loader);
// Write the serialized layout file.
let path = format!("tests/cache/serial/{}", name);
diff --git a/tests/layouts/test.typ b/tests/layouts/test.typ
new file mode 100644
index 00000000..063a7bfe
--- /dev/null
+++ b/tests/layouts/test.typ
@@ -0,0 +1,31 @@
+[page.size: w=5cm, h=5cm]
+[page.margins: 0cm]
+
+// [box: w=4cm, h=3cm][1]
+// //
+// [direction: ttb, ltr]
+// [box: w=2cm, h=1][2]
+// //
+// [direction: btt, rtl]
+// [align: bottom, right]
+// [box: w=3cm, h=1][3]
+// //
+// [direction: ltr, ttb]
+// [align: center, center]
+// [box: w=2cm, h=2cm][4]
+
+[align: center]
+
+//[direction: primary=btt, secondary=rtl]
+//[align: primary=bottom, secondary=right]
+//[box][Hi]
+
+[box][
+//[align: primary=center, secondary=bottom]
+[direction: secondary=btt]
+Blabla
+[v: 0.5cm]
+[align: vertical=end] Origin 2]
+//[align: vertical=center] Center
+//[align: vertical=center] Center
+//[align: vertical=end] End End End
diff --git a/tests/render.py b/tests/render.py
index 07a9b5b1..2e105eb2 100644
--- a/tests/render.py
+++ b/tests/render.py
@@ -16,7 +16,7 @@ def main():
assert len(sys.argv) == 2, 'usage: python render.py <name>'
name = sys.argv[1]
- filename = os.path.join(SERIAL, f'{name}.tld')
+ filename = os.path.join(SERIAL, name)
with open(filename, encoding='utf-8') as file:
lines = [line[:-1] for line in file.readlines()]
@@ -25,7 +25,7 @@ def main():
image = renderer.export()
pathlib.Path(RENDER).mkdir(parents=True, exist_ok=True)
- image.save(os.path.join(RENDER, f'{name}.png')
+ image.save(os.path.join(RENDER, f'{name}.png'))
class MultiboxRenderer:
@@ -56,6 +56,7 @@ class MultiboxRenderer:
renderer = BoxRenderer(self.fonts, width, height)
for i in range(action_count):
+ if i == 0: continue
command = self.content[start + i]
renderer.execute(command)
@@ -145,7 +146,8 @@ class BoxRenderer:
self.draw.text(self.cursor, text, (0, 0, 0, 255), font=self.font)
elif cmd == 'b':
- x, y, w, h = (pix(float(s)) for s in parts)
+ x, y = self.cursor
+ w, h = (pix(float(s)) for s in parts)
rect = [x, y, x+w-1, y+h-1]
forbidden_colors = set()