From 7cb7b25fd79fed61575751dc872382d3d2f2dbc9 Mon Sep 17 00:00:00 2001 From: Grant Lemons Date: Wed, 15 Jan 2025 16:30:46 -0700 Subject: [PATCH 1/6] tests: rename typst tests and add simplified document Co-authored-by: Andrew Voynov --- harper-typst/tests/run_tests.rs | 5 +- ...complex_typst.typ => complex_document.typ} | 0 ...typ => complex_with_spelling_mistakes.typ} | 0 .../test_sources/simplified_document.typ | 55 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) rename harper-typst/tests/test_sources/{complex_typst.typ => complex_document.typ} (100%) rename harper-typst/tests/test_sources/{typst_spelling_mistakes.typ => complex_with_spelling_mistakes.typ} (100%) create mode 100644 harper-typst/tests/test_sources/simplified_document.typ diff --git a/harper-typst/tests/run_tests.rs b/harper-typst/tests/run_tests.rs index c9c15f73..a9acc4df 100644 --- a/harper-typst/tests/run_tests.rs +++ b/harper-typst/tests/run_tests.rs @@ -37,5 +37,6 @@ macro_rules! create_test { }; } -create_test!(complex_typst.typ, 0); -create_test!(typst_spelling_mistakes.typ, 4); +create_test!(complex_document.typ, 0); +create_test!(simplified_document.typ, 0); +create_test!(complex_with_spelling_mistakes.typ, 4); diff --git a/harper-typst/tests/test_sources/complex_typst.typ b/harper-typst/tests/test_sources/complex_document.typ similarity index 100% rename from harper-typst/tests/test_sources/complex_typst.typ rename to harper-typst/tests/test_sources/complex_document.typ diff --git a/harper-typst/tests/test_sources/typst_spelling_mistakes.typ b/harper-typst/tests/test_sources/complex_with_spelling_mistakes.typ similarity index 100% rename from harper-typst/tests/test_sources/typst_spelling_mistakes.typ rename to harper-typst/tests/test_sources/complex_with_spelling_mistakes.typ diff --git a/harper-typst/tests/test_sources/simplified_document.typ b/harper-typst/tests/test_sources/simplified_document.typ new file mode 100644 index 00000000..cd22f9be --- /dev/null +++ b/harper-typst/tests/test_sources/simplified_document.typ @@ -0,0 +1,55 @@ +#let template( + title: "Default Title", + authors: ("Author 1", "Author 2"), + abstract: [*This is content*], + body, +) = { + set par(justify: true) + set page( + paper: "us-letter", + columns: 2, + number-align: top, + numbering: (..n) => if n.pos().first() > 1 { + n.pos().map(str).join(" of ") + h(1fr) + title + }, + ) + + place( + top + center, + float: true, + scope: "parent", + clearance: 2em, + )[ + #show heading: set text(17pt) + = #title + + #let authors-line = if authors.len() > 3 { + // "et al." isn't parsed properly, but this isn't the fault of the Typst + // parser. + // authors-max3.push("et al.") + authors => authors.join(", ") + } else { + authors => authors.join(", ", last: ", and ") + } + #emph(authors-line(authors.slice(0, calc.min(authors.len(), 3)))) + + #par(justify: false)[ + *Abstract* \ + #abstract + ] + ] + + body +} + +#show: template.with( + title: "A fluid dynamic model for glacier flow", + authors: ("Grant Lemons", "John Doe", "Jane Doe"), + abstract: lorem(80), +) + += Introduction +#lorem(300) + += Related Work +#lorem(200) From f448dc944866a4d3c24138f1be1306e2decae666 Mon Sep 17 00:00:00 2001 From: Grant Lemons Date: Wed, 15 Jan 2025 16:31:33 -0700 Subject: [PATCH 2/6] tests: remove contraction-posessive tests and correct r# string use --- harper-typst/src/lib.rs | 60 +++++++---------------------------------- 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/harper-typst/src/lib.rs b/harper-typst/src/lib.rs index 3f9bbd9a..24836285 100644 --- a/harper-typst/src/lib.rs +++ b/harper-typst/src/lib.rs @@ -41,48 +41,6 @@ mod tests { use super::Typst; use harper_core::{Document, NounData, Punctuation, TokenKind, WordMetadata}; - #[test] - fn contraction() { - let document = Document::new_curated("doesn't", &Typst); - let token_kinds = document.tokens().map(|t| t.kind).collect_vec(); - dbg!(&token_kinds); - - assert_eq!(token_kinds.len(), 1); - assert!(!token_kinds.into_iter().any(|t| { - matches!( - t, - TokenKind::Word(WordMetadata { - noun: Some(NounData { - is_possessive: Some(true), - .. - }), - .. - }) - ) - })) - } - - #[test] - fn possessive() { - let document = Document::new_curated("person's", &Typst); - let token_kinds = document.tokens().map(|t| t.kind).collect_vec(); - dbg!(&token_kinds); - - assert_eq!(token_kinds.len(), 1); - assert!(token_kinds.into_iter().all(|t| { - matches!( - t, - TokenKind::Word(WordMetadata { - noun: Some(NounData { - is_possessive: Some(true), - .. - }), - .. - }) - ) - })) - } - #[test] fn number() { let source = "12 is larger than 11, but much less than 11!"; @@ -215,8 +173,8 @@ mod tests { #[test] fn header_parsing() { - let source = r"= Header - Paragraph"; + let source = "= Header + Paragraph"; let document = Document::new_curated(source, &Typst); let token_kinds = document.tokens().map(|t| t.kind).collect_vec(); @@ -239,9 +197,9 @@ mod tests { #[test] fn parbreak() { - let source = r"Paragraph + let source = "Paragraph - Paragraph"; + Paragraph"; let document = Document::new_curated(source, &Typst); let token_kinds = document.tokens().map(|t| t.kind).collect_vec(); @@ -259,9 +217,9 @@ mod tests { #[test] fn label_unlintable() { - let source = r"= Header -