Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typst Test Fixes #391

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 27 additions & 69 deletions harper-typst/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down Expand Up @@ -141,9 +99,9 @@ mod tests {
#[test]
fn dict_parsing() {
let source = r#"#let dict = (
name: "Typst",
born: 2019,
)"#;
name: "Typst",
born: 2019,
)"#;

let document = Document::new_curated(source, &Typst);
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
Expand All @@ -156,11 +114,11 @@ mod tests {
assert!(matches!(
token_kinds.as_slice(),
&[
TokenKind::Unlintable, // Ident
TokenKind::Unlintable, // Key 1
TokenKind::Word(_), // Value 1
TokenKind::Unlintable, // Key 2
TokenKind::Unlintable, // Value 2
TokenKind::Unlintable, // dict
TokenKind::Unlintable, // name (key 1)
TokenKind::Word(_), // Typst (value 1)
TokenKind::Unlintable, // born (key 2)
TokenKind::Unlintable, // 2019 (value 2)
]
))
}
Expand All @@ -176,14 +134,14 @@ mod tests {
assert!(matches!(
&token_kinds.as_slice(),
&[
TokenKind::Unlintable,
TokenKind::Word(_), // This
TokenKind::Space(1),
TokenKind::Word(_), // Is
TokenKind::Space(1),
TokenKind::Word(_), // A
TokenKind::Space(1),
TokenKind::Word(_), // String
TokenKind::Unlintable, // ident
TokenKind::Word(_), // This
TokenKind::Space(1), //
TokenKind::Word(_), // is
TokenKind::Space(1), //
TokenKind::Word(_), // a
TokenKind::Space(1), //
TokenKind::Word(_), // string
]
))
}
Expand All @@ -202,21 +160,21 @@ mod tests {
TokenKind::Unlintable, // authors_slice.join
TokenKind::Punctuation(Punctuation::Comma),
TokenKind::Space(1),
TokenKind::Unlintable, // Ident
TokenKind::Unlintable, // last
TokenKind::Punctuation(Punctuation::Comma),
TokenKind::Space(1),
TokenKind::Word(_), // and
TokenKind::Space(1),
TokenKind::Space(2),
TokenKind::Word(_),
TokenKind::Word(_), // bob
]
))
}

#[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();
Expand All @@ -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();
Expand All @@ -259,9 +217,9 @@ mod tests {

#[test]
fn label_unlintable() {
let source = r"= Header
<label>
Paragraph";
let source = "= Header
<label>
Paragraph";

let document = Document::new_curated(source, &Typst);
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
Expand Down Expand Up @@ -313,8 +271,8 @@ mod tests {

#[test]
fn smart_apostrophe_newline() {
let source = r#"group’s
writing"#;
let source = "group’s
writing";

let document = Document::new_curated(source, &Typst);
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
Expand Down
5 changes: 3 additions & 2 deletions harper-typst/tests/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_document_with_spelling_mistakes.typ, 4);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
title: "Default Title",
authors: ("Author 1", "Author 2"),
abstract: [*This is content*],
body,
) = {
set document(date: none)
set par(justify: true)
set page(
header: context {
if counter(page).get().first() > 1 [
Expand All @@ -31,7 +34,7 @@
#let count = authors.len()
#let authors_slice = authors.slice(0, calc.min(count, 3))
_#if count > 3 {
// et al. isn't parsed properly, but this isn't the fault of the typst
// et al. isn't parsed properly, but this isn't the fault of the Typst
// parser
// authors_slice.push("et al.")
authors_slice.join(", ")
Expand All @@ -45,15 +48,16 @@
#abstract
]
]
body
}

#show: doc => [
#titleblock(
title: "A fluid dynamic model for glacier flow",
authors: ("Grant Lemons", "John Doe", "Jane Doe"),
abstract: lorem(80)
abstract: lorem(80),
doc,
)
#doc
]

= Introduction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
title: "Defalt Title",
authors: ("Author 1", "Author 2"),
abstract: [*This is contnt*],
body,
) = {
set document(date: none)
set par(justify: true)
set page(
header: context {
if counter(page).get().first() > 1 [
Expand All @@ -31,7 +34,7 @@
#let count = authors.len()
#let authors_slice = authors.slice(0, calc.min(count, 3))
_#if count > 3 {
// et al. isn't parsed properly, but this isn't the fault of the typst
// et al. isn't parsed properly, but this isn't the fault of the Typst
// parser
// authors_slice.push("et al.")
authors_slice.join(", ")
Expand All @@ -45,15 +48,16 @@
#abstract
]
]
body
}

#show: doc => [
#titleblock(
title: "A fluid dynamic model for glaier flow",
authors: ("Grant Lemons", "John Doe", "Jane Doe"),
abstract: lorem(80)
abstract: lorem(80),
doc,
)
#doc
]

= Introduction
Expand Down
55 changes: 55 additions & 0 deletions harper-typst/tests/test_sources/simplified_document.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#let template(
title: "Default Title",
authors: ("Author 1", "Author 2"),
abstract: [*This is content*],
body,
) = {
set document(date: none)
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,
)[
#text(17pt, strong(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)
Loading