Skip to content

Commit 567d514

Browse files
Merge pull request #391 from grantlemons/typst-fixes
Typst Test Fixes
2 parents 019699d + 1e6cb14 commit 567d514

File tree

5 files changed

+99
-77
lines changed

5 files changed

+99
-77
lines changed

harper-typst/src/lib.rs

Lines changed: 27 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,48 +41,6 @@ mod tests {
4141
use super::Typst;
4242
use harper_core::{Document, NounData, Punctuation, TokenKind, WordMetadata};
4343

44-
#[test]
45-
fn contraction() {
46-
let document = Document::new_curated("doesn't", &Typst);
47-
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
48-
dbg!(&token_kinds);
49-
50-
assert_eq!(token_kinds.len(), 1);
51-
assert!(!token_kinds.into_iter().any(|t| {
52-
matches!(
53-
t,
54-
TokenKind::Word(WordMetadata {
55-
noun: Some(NounData {
56-
is_possessive: Some(true),
57-
..
58-
}),
59-
..
60-
})
61-
)
62-
}))
63-
}
64-
65-
#[test]
66-
fn possessive() {
67-
let document = Document::new_curated("person's", &Typst);
68-
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
69-
dbg!(&token_kinds);
70-
71-
assert_eq!(token_kinds.len(), 1);
72-
assert!(token_kinds.into_iter().all(|t| {
73-
matches!(
74-
t,
75-
TokenKind::Word(WordMetadata {
76-
noun: Some(NounData {
77-
is_possessive: Some(true),
78-
..
79-
}),
80-
..
81-
})
82-
)
83-
}))
84-
}
85-
8644
#[test]
8745
fn number() {
8846
let source = "12 is larger than 11, but much less than 11!";
@@ -141,9 +99,9 @@ mod tests {
14199
#[test]
142100
fn dict_parsing() {
143101
let source = r#"#let dict = (
144-
name: "Typst",
145-
born: 2019,
146-
)"#;
102+
name: "Typst",
103+
born: 2019,
104+
)"#;
147105

148106
let document = Document::new_curated(source, &Typst);
149107
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
@@ -156,11 +114,11 @@ mod tests {
156114
assert!(matches!(
157115
token_kinds.as_slice(),
158116
&[
159-
TokenKind::Unlintable, // Ident
160-
TokenKind::Unlintable, // Key 1
161-
TokenKind::Word(_), // Value 1
162-
TokenKind::Unlintable, // Key 2
163-
TokenKind::Unlintable, // Value 2
117+
TokenKind::Unlintable, // dict
118+
TokenKind::Unlintable, // name (key 1)
119+
TokenKind::Word(_), // Typst (value 1)
120+
TokenKind::Unlintable, // born (key 2)
121+
TokenKind::Unlintable, // 2019 (value 2)
164122
]
165123
))
166124
}
@@ -176,14 +134,14 @@ mod tests {
176134
assert!(matches!(
177135
&token_kinds.as_slice(),
178136
&[
179-
TokenKind::Unlintable,
180-
TokenKind::Word(_), // This
181-
TokenKind::Space(1),
182-
TokenKind::Word(_), // Is
183-
TokenKind::Space(1),
184-
TokenKind::Word(_), // A
185-
TokenKind::Space(1),
186-
TokenKind::Word(_), // String
137+
TokenKind::Unlintable, // ident
138+
TokenKind::Word(_), // This
139+
TokenKind::Space(1), //
140+
TokenKind::Word(_), // is
141+
TokenKind::Space(1), //
142+
TokenKind::Word(_), // a
143+
TokenKind::Space(1), //
144+
TokenKind::Word(_), // string
187145
]
188146
))
189147
}
@@ -202,21 +160,21 @@ mod tests {
202160
TokenKind::Unlintable, // authors_slice.join
203161
TokenKind::Punctuation(Punctuation::Comma),
204162
TokenKind::Space(1),
205-
TokenKind::Unlintable, // Ident
163+
TokenKind::Unlintable, // last
206164
TokenKind::Punctuation(Punctuation::Comma),
207165
TokenKind::Space(1),
208166
TokenKind::Word(_), // and
209167
TokenKind::Space(1),
210168
TokenKind::Space(2),
211-
TokenKind::Word(_),
169+
TokenKind::Word(_), // bob
212170
]
213171
))
214172
}
215173

216174
#[test]
217175
fn header_parsing() {
218-
let source = r"= Header
219-
Paragraph";
176+
let source = "= Header
177+
Paragraph";
220178

221179
let document = Document::new_curated(source, &Typst);
222180
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
@@ -239,9 +197,9 @@ mod tests {
239197

240198
#[test]
241199
fn parbreak() {
242-
let source = r"Paragraph
200+
let source = "Paragraph
243201
244-
Paragraph";
202+
Paragraph";
245203

246204
let document = Document::new_curated(source, &Typst);
247205
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();
@@ -259,9 +217,9 @@ mod tests {
259217

260218
#[test]
261219
fn label_unlintable() {
262-
let source = r"= Header
263-
<label>
264-
Paragraph";
220+
let source = "= Header
221+
<label>
222+
Paragraph";
265223

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

314272
#[test]
315273
fn smart_apostrophe_newline() {
316-
let source = r#"group’s
317-
writing"#;
274+
let source = "group’s
275+
writing";
318276

319277
let document = Document::new_curated(source, &Typst);
320278
let token_kinds = document.tokens().map(|t| t.kind).collect_vec();

harper-typst/tests/run_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ macro_rules! create_test {
3737
};
3838
}
3939

40-
create_test!(complex_typst.typ, 0);
41-
create_test!(typst_spelling_mistakes.typ, 4);
40+
create_test!(complex_document.typ, 0);
41+
create_test!(simplified_document.typ, 0);
42+
create_test!(complex_document_with_spelling_mistakes.typ, 4);

harper-typst/tests/test_sources/complex_typst.typ renamed to harper-typst/tests/test_sources/complex_document.typ

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
title: "Default Title",
88
authors: ("Author 1", "Author 2"),
99
abstract: [*This is content*],
10+
body,
1011
) = {
12+
set document(date: none)
13+
set par(justify: true)
1114
set page(
1215
header: context {
1316
if counter(page).get().first() > 1 [
@@ -31,7 +34,7 @@
3134
#let count = authors.len()
3235
#let authors_slice = authors.slice(0, calc.min(count, 3))
3336
_#if count > 3 {
34-
// et al. isn't parsed properly, but this isn't the fault of the typst
37+
// et al. isn't parsed properly, but this isn't the fault of the Typst
3538
// parser
3639
// authors_slice.push("et al.")
3740
authors_slice.join(", ")
@@ -45,15 +48,16 @@
4548
#abstract
4649
]
4750
]
51+
body
4852
}
4953

5054
#show: doc => [
5155
#titleblock(
5256
title: "A fluid dynamic model for glacier flow",
5357
authors: ("Grant Lemons", "John Doe", "Jane Doe"),
54-
abstract: lorem(80)
58+
abstract: lorem(80),
59+
doc,
5560
)
56-
#doc
5761
]
5862

5963
= Introduction

harper-typst/tests/test_sources/typst_spelling_mistakes.typ renamed to harper-typst/tests/test_sources/complex_document_with_spelling_mistakes.typ

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
title: "Defalt Title",
88
authors: ("Author 1", "Author 2"),
99
abstract: [*This is contnt*],
10+
body,
1011
) = {
12+
set document(date: none)
13+
set par(justify: true)
1114
set page(
1215
header: context {
1316
if counter(page).get().first() > 1 [
@@ -31,7 +34,7 @@
3134
#let count = authors.len()
3235
#let authors_slice = authors.slice(0, calc.min(count, 3))
3336
_#if count > 3 {
34-
// et al. isn't parsed properly, but this isn't the fault of the typst
37+
// et al. isn't parsed properly, but this isn't the fault of the Typst
3538
// parser
3639
// authors_slice.push("et al.")
3740
authors_slice.join(", ")
@@ -45,15 +48,16 @@
4548
#abstract
4649
]
4750
]
51+
body
4852
}
4953

5054
#show: doc => [
5155
#titleblock(
5256
title: "A fluid dynamic model for glaier flow",
5357
authors: ("Grant Lemons", "John Doe", "Jane Doe"),
54-
abstract: lorem(80)
58+
abstract: lorem(80),
59+
doc,
5560
)
56-
#doc
5761
]
5862

5963
= Introduction
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#let template(
2+
title: "Default Title",
3+
authors: ("Author 1", "Author 2"),
4+
abstract: [*This is content*],
5+
body,
6+
) = {
7+
set document(date: none)
8+
set par(justify: true)
9+
set page(
10+
paper: "us-letter",
11+
columns: 2,
12+
number-align: top,
13+
numbering: (..n) => if n.pos().first() > 1 {
14+
n.pos().map(str).join(" of ") + h(1fr) + title
15+
},
16+
)
17+
18+
place(
19+
top + center,
20+
float: true,
21+
scope: "parent",
22+
clearance: 2em,
23+
)[
24+
#text(17pt, strong(title))
25+
26+
#let authors-line = if authors.len() > 3 {
27+
// "et al." isn't parsed properly, but this isn't the fault of the Typst
28+
// parser.
29+
// authors-max3.push("et al.")
30+
authors => authors.join(", ")
31+
} else {
32+
authors => authors.join(", ", last: ", and ")
33+
}
34+
#emph(authors-line(authors.slice(0, calc.min(authors.len(), 3))))
35+
36+
#par(justify: false)[
37+
*Abstract* \
38+
#abstract
39+
]
40+
]
41+
42+
body
43+
}
44+
45+
#show: template.with(
46+
title: "A fluid dynamic model for glacier flow",
47+
authors: ("Grant Lemons", "John Doe", "Jane Doe"),
48+
abstract: lorem(80),
49+
)
50+
51+
= Introduction
52+
#lorem(300)
53+
54+
= Related Work
55+
#lorem(200)

0 commit comments

Comments
 (0)