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)")]);
|
||||
}
|
||||
|
||||
#[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.
|
||||
|
@ -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"));
|
||||
|
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.
|
||||
//
|
||||
// error: 4:1-4:6 unexpected invalid token
|
||||
// error: 8:1-8:6 unexpected invalid token
|
||||
|
||||
\# No heading
|
||||
|
||||
Text with # hashtag
|
||||
|
||||
Nr#1
|
||||
|
||||
#nope
|
||||
|
||||
---
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user