summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/parse/tests.rs17
-rw-r--r--src/parse/tokens.rs15
-rw-r--r--tests/ref/escaping.pngbin0 -> 4320 bytes
-rw-r--r--tests/ref/headings.pngbin7991 -> 8197 bytes
-rw-r--r--tests/typ/escaping.typ32
-rw-r--r--tests/typ/headings.typ4
-rw-r--r--tests/typeset.rs4
7 files changed, 45 insertions, 27 deletions
diff --git a/src/parse/tests.rs b/src/parse/tests.rs
index f8b9dcbb..9a0a4ce6 100644
--- a/src/parse/tests.rs
+++ b/src/parse/tests.rs
@@ -252,23 +252,6 @@ fn test_parse_raw() {
}
#[test]
-fn test_parse_escape_sequences() {
- // Basic, mostly tested in tokenizer.
- t!(r"\[" Text("["));
- t!(r"\u{1F3D5}" nodes: [S(0..9, Text("🏕"))], spans: true);
-
- // Bad value.
- t!(r"\u{FFFFFF}"
- nodes: [Text(r"\u{FFFFFF}")],
- errors: [S(0..10, "invalid unicode escape sequence")]);
-
- // No closing brace.
- t!(r"\u{41*"
- nodes: [Text("A"), Strong],
- errors: [S(5..5, "expected closing brace")]);
-}
-
-#[test]
fn test_parse_groups() {
// Test paren group.
t!("{({1) + 3}"
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index 7741d27f..85fc4978 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -179,7 +179,7 @@ impl<'s> Tokens<'s> {
// Parenthesis.
'[' | ']' | '{' | '}' => true,
// Markup.
- '*' | '_' | '#' | '~' | '`' => true,
+ '*' | '_' | '#' | '~' | '`' | '$' => true,
// Escaping.
'\\' => true,
_ => false,
@@ -279,7 +279,7 @@ impl<'s> Tokens<'s> {
// Parenthesis.
'[' | ']' | '{' | '}' |
// Markup.
- '*' | '_' | '~' | '#' | '`' => {
+ '*' | '_' | '#' | '~' | '`' | '$' => {
let start = self.s.index();
self.s.eat_assert(c);
Token::Text(&self.s.eaten_from(start))
@@ -447,19 +447,19 @@ mod tests {
use Token::{Ident, *};
use TokenMode::{Code, Markup};
- fn Raw(text: &str, backticks: usize, terminated: bool) -> Token {
+ const fn Raw(text: &str, backticks: usize, terminated: bool) -> Token {
Token::Raw(TokenRaw { text, backticks, terminated })
}
- fn Math(formula: &str, inline: bool, terminated: bool) -> Token {
+ const fn Math(formula: &str, inline: bool, terminated: bool) -> Token {
Token::Math(TokenMath { formula, inline, terminated })
}
- fn UnicodeEscape(sequence: &str, terminated: bool) -> Token {
+ const fn UnicodeEscape(sequence: &str, terminated: bool) -> Token {
Token::UnicodeEscape(TokenUnicodeEscape { sequence, terminated })
}
- fn Str(string: &str, terminated: bool) -> Token {
+ const fn Str(string: &str, terminated: bool) -> Token {
Token::Str(TokenStr { string, terminated })
}
@@ -505,7 +505,7 @@ mod tests {
('/', None, "//", LineComment("")),
('/', None, "/**/", BlockComment("")),
('/', Some(Markup), "*", Star),
- ('/', Some(Markup), "_", Underscore),
+ ('/', Some(Markup), "$ $", Math(" ", true, true)),
('/', Some(Markup), r"\\", Text(r"\")),
('/', Some(Markup), "#let", Let),
('/', Some(Code), "(", LeftParen),
@@ -740,6 +740,7 @@ mod tests {
t!(Markup: r"\#" => Text("#"));
t!(Markup: r"\~" => Text("~"));
t!(Markup: r"\`" => Text("`"));
+ t!(Markup: r"\$" => Text("$"));
// Test unescapable symbols.
t!(Markup[" /"]: r"\a" => Text(r"\"), Text("a"));
diff --git a/tests/ref/escaping.png b/tests/ref/escaping.png
new file mode 100644
index 00000000..fedd3e58
--- /dev/null
+++ b/tests/ref/escaping.png
Binary files differ
diff --git a/tests/ref/headings.png b/tests/ref/headings.png
index b16e38a6..3deecf8f 100644
--- a/tests/ref/headings.png
+++ b/tests/ref/headings.png
Binary files differ
diff --git a/tests/typ/escaping.typ b/tests/typ/escaping.typ
new file mode 100644
index 00000000..a562dcc0
--- /dev/null
+++ b/tests/typ/escaping.typ
@@ -0,0 +1,32 @@
+// Test basic symbol escapes.
+
+// Escapable
+\\ \/ \[ \] \{ \} \* \_ \# \~ \` \$
+
+// No need to escape.
+( ) = ;
+
+// Unescapable.
+\a \: \; \( \)
+
+// Escaped comments.
+\//
+\/\* \*\/
+\/* \*/
+
+---
+// Test unicode escapes.
+//
+// error: 5:1-5:11 invalid unicode escape sequence
+// error: 8:6-8:6 expected closing brace
+
+\u{1F3D5} == 🏕
+
+// Bad sequence.
+\u{FFFFFF}
+
+// Missing closing brace.
+\u{41*Bold*
+
+// Escaped escape sequence.
+\\u\{ABC\}
diff --git a/tests/typ/headings.typ b/tests/typ/headings.typ
index 88c76ad3..3a115746 100644
--- a/tests/typ/headings.typ
+++ b/tests/typ/headings.typ
@@ -17,12 +17,14 @@
---
// Is no heading.
//
-// error: 4:1-4:6 unexpected invalid token
+// error: 8:1-8:6 unexpected invalid token
\# No heading
Text with # hashtag
+Nr#1
+
#nope
---
diff --git a/tests/typeset.rs b/tests/typeset.rs
index f3c41151..2b342c5b 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -213,14 +213,14 @@ fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec<Frame>) {
ok = false;
for diag in &diags {
- if ref_diags.binary_search(diag).is_err() {
+ if !ref_diags.contains(diag) {
print!(" Unexpected | ");
print_diag(diag, &map);
}
}
for diag in &ref_diags {
- if diags.binary_search(diag).is_err() {
+ if !diags.contains(diag) {
print!(" Missing | ");
print_diag(diag, &map);
}