diff --git a/src/parse/tests.rs b/src/parse/tests.rs index f8b9dcbb1..9a0a4ce6d 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -251,23 +251,6 @@ fn test_parse_raw() { errors: [S(8..8, "expected backtick(s)")]); } -#[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. diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs index 7741d27f8..85fc49780 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 000000000..fedd3e588 Binary files /dev/null and b/tests/ref/escaping.png differ diff --git a/tests/ref/headings.png b/tests/ref/headings.png index b16e38a6b..3deecf8f3 100644 Binary files a/tests/ref/headings.png and b/tests/ref/headings.png differ diff --git a/tests/typ/escaping.typ b/tests/typ/escaping.typ new file mode 100644 index 000000000..a562dcc0c --- /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 88c76ad38..3a1157462 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 f3c411519..2b342c5bc 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -213,14 +213,14 @@ fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec) { 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); }