Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

tests(#230): add complex typst document test

Grant Lemons4ec7f7124c1b
diff --git a/harper-core/tests/run_tests.rs b/harper-core/tests/run_tests.rs
index 2832132f6..2b6034595 100644
--- a/harper-core/tests/run_tests.rs
+++ b/harper-core/tests/run_tests.rs
@@ -1,17 +1,17 @@
use harper_core::linting::{LintGroup, LintGroupConfig, Linter};
use harper_core::{Document, FstDictionary};
-/// Creates a unit test checking that the linting of a Markdown document (in
-/// `tests_sources`) produces the expected number of lints.
+/// Creates a unit test checking that the linting of a document in
+/// `tests_sources` produces the expected number of lints.
macro_rules! create_test {
- ($filename:ident.md, $correct_expected:expr) => {
+ ($filename:ident, $ext:literal, $correct_expected:expr) => {
paste::paste! {
#[test]
fn [<lints_ $filename _correctly>](){
let source = include_str!(
concat!(
"./test_sources/",
- concat!(stringify!($filename), ".md")
+ concat!(stringify!($filename), $ext)
)
);
@@ -34,6 +34,12 @@ macro_rules! create_test {
}
}
};
+ ($filename:ident.md, $correct_expected:expr) => {
+ create_test!($filename, ".md", $correct_expected);
+ };
+ ($filename:ident.typ, $correct_expected:expr) => {
+ create_test!($filename, ".typ", $correct_expected);
+ };
}
create_test!(whack_bullets.md, 1);
@@ -43,3 +49,4 @@ create_test!(issue_109_ext.md, 0);
create_test!(chinese_lorem_ipsum.md, 2);
create_test!(obsidian_links.md, 2);
create_test!(issue_267.md, 0);
+create_test!(complex_typst.typ, 0);
diff --git a/harper-core/tests/test_sources/complex_typst.typ b/harper-core/tests/test_sources/complex_typst.typ
new file mode 100644
index 000000000..81176d96e
--- /dev/null
+++ b/harper-core/tests/test_sources/complex_typst.typ
@@ -0,0 +1,61 @@
+#set page(
+ paper: "us-letter",
+ columns: 2,
+)
+
+#let titleblock(
+ title: "Default Title",
+ authors: ("Author 1", "Author 2"),
+ abstract: [*This is content*],
+) = {
+ set page(
+ header: context {
+ if counter(page).get().first() > 1 [
+ #counter(page).get().first() of #counter(page).final().at(0)
+ #h(1fr)
+ #title
+ ]
+ },
+ )
+ place(
+ top + center,
+ float: true,
+ scope: "parent",
+ clearance: 2em,
+ )[
+ #align(center, text(17pt)[
+ *#title*
+ ])
+
+ #let authors = authors.filter(x => x.len() > 0)
+ #let count = authors.len()
+ #let authors_slice = authors.slice(0, calc.min(count, 3))
+ _#if count > 3 {
+ authors_slice.push("et al.")
+ authors_slice.join(", ")
+ } else {
+ authors_slice.join(", ", last: ", and ")
+ }
+ _
+
+ #par(justify: false)[
+ *Abstract* \
+ #abstract
+ ]
+ ]
+}
+
+#show: doc => [
+ #titleblock(
+ title: "A fluid dynamic model for glacier flow",
+ authors: ("Grant Lemons", "John Doe", "Jane Doe"),
+ abstract: lorem(80)
+ )
+ #doc
+]
+
+= Introduction
+#lorem(300)
+
+= Related Work
+#lorem(200)