mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Move escaping tests to integration and extend them 🚚
This commit is contained in:
parent
274e008e2c
commit
1cd687b681
@ -251,23 +251,6 @@ fn test_parse_raw() {
|
|||||||
errors: [S(8..8, "expected backtick(s)")]);
|
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]
|
#[test]
|
||||||
fn test_parse_groups() {
|
fn test_parse_groups() {
|
||||||
// Test paren group.
|
// Test paren group.
|
||||||
|
@ -179,7 +179,7 @@ impl<'s> Tokens<'s> {
|
|||||||
// Parenthesis.
|
// Parenthesis.
|
||||||
'[' | ']' | '{' | '}' => true,
|
'[' | ']' | '{' | '}' => true,
|
||||||
// Markup.
|
// Markup.
|
||||||
'*' | '_' | '#' | '~' | '`' => true,
|
'*' | '_' | '#' | '~' | '`' | '$' => true,
|
||||||
// Escaping.
|
// Escaping.
|
||||||
'\\' => true,
|
'\\' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
@ -279,7 +279,7 @@ impl<'s> Tokens<'s> {
|
|||||||
// Parenthesis.
|
// Parenthesis.
|
||||||
'[' | ']' | '{' | '}' |
|
'[' | ']' | '{' | '}' |
|
||||||
// Markup.
|
// Markup.
|
||||||
'*' | '_' | '~' | '#' | '`' => {
|
'*' | '_' | '#' | '~' | '`' | '$' => {
|
||||||
let start = self.s.index();
|
let start = self.s.index();
|
||||||
self.s.eat_assert(c);
|
self.s.eat_assert(c);
|
||||||
Token::Text(&self.s.eaten_from(start))
|
Token::Text(&self.s.eaten_from(start))
|
||||||
@ -447,19 +447,19 @@ mod tests {
|
|||||||
use Token::{Ident, *};
|
use Token::{Ident, *};
|
||||||
use TokenMode::{Code, Markup};
|
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 })
|
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 })
|
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 })
|
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 })
|
Token::Str(TokenStr { string, terminated })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,7 +505,7 @@ mod tests {
|
|||||||
('/', None, "//", LineComment("")),
|
('/', None, "//", LineComment("")),
|
||||||
('/', None, "/**/", BlockComment("")),
|
('/', None, "/**/", BlockComment("")),
|
||||||
('/', Some(Markup), "*", Star),
|
('/', Some(Markup), "*", Star),
|
||||||
('/', Some(Markup), "_", Underscore),
|
('/', Some(Markup), "$ $", Math(" ", true, true)),
|
||||||
('/', Some(Markup), r"\\", Text(r"\")),
|
('/', Some(Markup), r"\\", Text(r"\")),
|
||||||
('/', Some(Markup), "#let", Let),
|
('/', Some(Markup), "#let", Let),
|
||||||
('/', Some(Code), "(", LeftParen),
|
('/', 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("~"));
|
||||||
t!(Markup: r"\`" => Text("`"));
|
t!(Markup: r"\`" => Text("`"));
|
||||||
|
t!(Markup: r"\$" => Text("$"));
|
||||||
|
|
||||||
// Test unescapable symbols.
|
// Test unescapable symbols.
|
||||||
t!(Markup[" /"]: r"\a" => Text(r"\"), Text("a"));
|
t!(Markup[" /"]: r"\a" => Text(r"\"), Text("a"));
|
||||||
|
BIN
tests/ref/escaping.png
Normal file
BIN
tests/ref/escaping.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 8.0 KiB |
32
tests/typ/escaping.typ
Normal file
32
tests/typ/escaping.typ
Normal file
@ -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\}
|
@ -17,12 +17,14 @@
|
|||||||
---
|
---
|
||||||
// Is no heading.
|
// Is no heading.
|
||||||
//
|
//
|
||||||
// error: 4:1-4:6 unexpected invalid token
|
// error: 8:1-8:6 unexpected invalid token
|
||||||
|
|
||||||
\# No heading
|
\# No heading
|
||||||
|
|
||||||
Text with # hashtag
|
Text with # hashtag
|
||||||
|
|
||||||
|
Nr#1
|
||||||
|
|
||||||
#nope
|
#nope
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -213,14 +213,14 @@ fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec<Frame>) {
|
|||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
for diag in &diags {
|
for diag in &diags {
|
||||||
if ref_diags.binary_search(diag).is_err() {
|
if !ref_diags.contains(diag) {
|
||||||
print!(" Unexpected | ");
|
print!(" Unexpected | ");
|
||||||
print_diag(diag, &map);
|
print_diag(diag, &map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for diag in &ref_diags {
|
for diag in &ref_diags {
|
||||||
if diags.binary_search(diag).is_err() {
|
if !diags.contains(diag) {
|
||||||
print!(" Missing | ");
|
print!(" Missing | ");
|
||||||
print_diag(diag, &map);
|
print_diag(diag, &map);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user