Simpler diagnostic localization in tests ♻
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
@ -13,25 +13,21 @@
|
||||
, #003
|
||||
,)}
|
||||
|
||||
---
|
||||
// Test errors.
|
||||
//
|
||||
// error: 2:3-2:3 expected closing paren
|
||||
// error: 4:4-4:6 expected expression, found end of block comment
|
||||
// error: 4:4-4:4 expected comma
|
||||
// error: 6:6-6:8 expected expression, found invalid token
|
||||
// error: 8:3-8:4 expected expression, found comma
|
||||
// error: 10:5-10:5 expected expression
|
||||
// error: 12:6-12:10 expected expression, found named pair
|
||||
|
||||
// Error: 1:3-1:3 expected closing paren
|
||||
{(}
|
||||
|
||||
// Error: 2:4-2:6 expected expression, found end of block comment
|
||||
// Error: 1:4-1:4 expected comma
|
||||
{(1*/2)}
|
||||
|
||||
// Error: 1:6-1:8 expected expression, found invalid token
|
||||
{(1, 1u 2)}
|
||||
|
||||
// Error: 1:3-1:4 expected expression, found comma
|
||||
{(,1)}
|
||||
|
||||
// Error: 1:5-1:5 expected expression
|
||||
{(a:)}
|
||||
|
||||
// Error: 1:6-1:10 expected expression, found named pair
|
||||
{(1, b: 2)}
|
||||
|
@ -1,22 +1,17 @@
|
||||
// Test interaction with words, spacing and expressions.
|
||||
|
||||
// Test whether line comment acts as spacing.
|
||||
A// you
|
||||
B
|
||||
|
||||
// Test whether block comment acts as spacing.
|
||||
C/*
|
||||
/* */
|
||||
*/D
|
||||
|
||||
// Test in expressions.
|
||||
[dump /*1*/ a: "b" //
|
||||
, 1]
|
||||
|
||||
---
|
||||
// Test error.
|
||||
//
|
||||
// ref: false
|
||||
// error: 3:7-3:9 unexpected end of block comment
|
||||
|
||||
// No start of block comment.
|
||||
// Error: 1:7-1:9 unexpected end of block comment
|
||||
/* */ */
|
||||
|
||||
// Unterminated block comment is okay.
|
||||
|
@ -4,15 +4,11 @@
|
||||
// Two pairs.
|
||||
{(one: 1, two: 2)}
|
||||
|
||||
---
|
||||
// Test errors.
|
||||
//
|
||||
// error: 2:9-2:10 expected named pair, found expression
|
||||
// error: 4:4-4:5 expected named pair, found expression
|
||||
// error: 4:5-4:5 expected comma
|
||||
// error: 4:12-4:16 expected identifier
|
||||
// error: 4:17-4:18 expected expression, found colon
|
||||
|
||||
// Error: 1:9-1:10 expected named pair, found expression
|
||||
{(a: 1, b)}
|
||||
|
||||
// Error: 4:4-4:5 expected named pair, found expression
|
||||
// Error: 3:5-3:5 expected comma
|
||||
// Error: 2:12-2:16 expected identifier
|
||||
// Error: 1:17-1:18 expected expression, found colon
|
||||
{(:1 b:[], true::)}
|
||||
|
@ -1,6 +1,4 @@
|
||||
// Test basic symbol escapes.
|
||||
|
||||
// Escapable
|
||||
// Escapable symbols.
|
||||
\\ \/ \[ \] \{ \} \* \_ \# \~ \` \$
|
||||
|
||||
// No need to escape.
|
||||
@ -12,21 +10,16 @@
|
||||
// Escaped comments.
|
||||
\//
|
||||
\/\* \*\/
|
||||
\/* \*/
|
||||
|
||||
---
|
||||
// Test unicode escapes.
|
||||
//
|
||||
// error: 5:1-5:11 invalid unicode escape sequence
|
||||
// error: 8:6-8:6 expected closing brace
|
||||
\/* \*/ *
|
||||
|
||||
// Test unicode escape sequence.
|
||||
\u{1F3D5} == 🏕
|
||||
|
||||
// Bad sequence.
|
||||
// Escaped escape sequence.
|
||||
\u{41} vs. \\u\{41\}
|
||||
|
||||
// Error: 1:1-1:11 invalid unicode escape sequence
|
||||
\u{FFFFFF}
|
||||
|
||||
// Missing closing brace.
|
||||
// Error: 1:6-1:6 expected closing brace
|
||||
\u{41*Bold*
|
||||
|
||||
// Escaped escape sequence.
|
||||
\\u\{ABC\}
|
||||
|
@ -43,23 +43,18 @@ New sans-serif. 🚀
|
||||
|
||||
---
|
||||
// Test error cases.
|
||||
//
|
||||
// ref: false
|
||||
// error: 3:7-3:12 unexpected argument
|
||||
// error: 6:14-6:18 expected font style, found font weight
|
||||
// error: 6:28-6:34 expected font weight, found string
|
||||
// error: 6:43-6:44 expected font family or array of font families, found integer
|
||||
// warning: 9:15-9:19 must be between 100 and 900
|
||||
// error: 12:7-12:27 unexpected argument
|
||||
// Ref: false
|
||||
|
||||
// Not one of the valid things for positional arguments.
|
||||
// Error: 1:7-1:12 unexpected argument
|
||||
[font false]
|
||||
|
||||
// Wrong types.
|
||||
// Error: 3:14-3:18 expected font style, found font weight
|
||||
// Error: 2:28-2:34 expected font weight, found string
|
||||
// Error: 1:43-1:44 expected font family or array of font families, found integer
|
||||
[font style: bold, weight: "thin", serif: 0]
|
||||
|
||||
// Weight out of range.
|
||||
// Warning: 1:15-1:19 must be between 100 and 900
|
||||
[font weight: 2700]
|
||||
|
||||
// Non-existing argument.
|
||||
// Error: 1:7-1:27 unexpected argument
|
||||
[font something: "invalid"]
|
||||
|
@ -19,10 +19,6 @@ Relative [h 100%] spacing
|
||||
3 [v 1cm] 4 [v -1cm] 5
|
||||
]
|
||||
|
||||
---
|
||||
// Test error cases.
|
||||
//
|
||||
// error: 3:11-3:11 missing argument: spacing
|
||||
|
||||
// Missing spacing.
|
||||
// Error: 1:11-1:11 missing argument: spacing
|
||||
Totally [h] ignored
|
@ -35,12 +35,10 @@
|
||||
---
|
||||
// Test error cases.
|
||||
//
|
||||
// ref: false
|
||||
// error: 3:8-3:29 failed to load image
|
||||
// error: 6:8-6:29 failed to load image
|
||||
// Ref: false
|
||||
|
||||
// File does not exist.
|
||||
// Error: 1:8-1:29 failed to load image
|
||||
[image "path/does/not/exist"]
|
||||
|
||||
// File exists, but is no image.
|
||||
// Error: 1:8-1:29 failed to load image
|
||||
[image "typ/image-error.typ"]
|
||||
|
@ -47,12 +47,10 @@ Right to left!
|
||||
---
|
||||
// Test error cases.
|
||||
//
|
||||
// ref: false
|
||||
// error: 3:7-3:18 unknown variable
|
||||
// error: 6:17-6:20 aligned axis
|
||||
// Ref: false
|
||||
|
||||
// Invalid paper.
|
||||
// Error: 1:7-1:18 unknown variable
|
||||
[page nonexistant]
|
||||
|
||||
// Aligned axes.
|
||||
// Error: 1:17-1:20 aligned axis
|
||||
[page main-dir: ltr]
|
||||
|
@ -1,11 +1,4 @@
|
||||
// Test the `rgb` function.
|
||||
//
|
||||
// warning: 9:6-9:9 must be between 0.0 and 1.0
|
||||
// warning: 9:11-9:15 must be between 0.0 and 1.0
|
||||
// error: 12:6-12:10 missing argument: blue component
|
||||
// error: 15:5-15:5 missing argument: red component
|
||||
// error: 15:5-15:5 missing argument: green component
|
||||
// error: 15:5-15:5 missing argument: blue component
|
||||
|
||||
// Check the output.
|
||||
[rgb 0.0, 0.3, 0.7]
|
||||
@ -13,11 +6,14 @@
|
||||
// Alpha channel.
|
||||
[rgb 1.0, 0.0, 0.0, 0.5]
|
||||
|
||||
// Value smaller than 0.0 and larger than 1.0
|
||||
// Warning: 2:6-2:9 must be between 0.0 and 1.0
|
||||
// Warning: 1:11-1:15 must be between 0.0 and 1.0
|
||||
[rgb -30, 15.5, 0.5]
|
||||
|
||||
// Missing blue component.
|
||||
// Error: 1:6-1:10 missing argument: blue component
|
||||
[rgb 0, 1]
|
||||
|
||||
// Missing all components.
|
||||
// Error: 3:5-3:5 missing argument: red component
|
||||
// Error: 2:5-2:5 missing argument: green component
|
||||
// Error: 1:5-1:5 missing argument: blue component
|
||||
[rgb]
|
||||
|
@ -1,10 +1,10 @@
|
||||
// Number of hashtags.
|
||||
//
|
||||
// warning: 5:1-5:8 section depth should not exceed 6
|
||||
|
||||
# One
|
||||
### Three
|
||||
###### Six
|
||||
|
||||
// Warning: 1:1-1:8 section depth should not exceed 6
|
||||
####### Seven
|
||||
|
||||
---
|
||||
@ -16,8 +16,6 @@
|
||||
|
||||
---
|
||||
// Is no heading.
|
||||
//
|
||||
// error: 8:1-8:6 unexpected invalid token
|
||||
|
||||
\# No heading
|
||||
|
||||
@ -25,6 +23,7 @@ Text with # hashtag
|
||||
|
||||
Nr#1
|
||||
|
||||
// Error: 1:1-1:6 unexpected invalid token
|
||||
#nope
|
||||
|
||||
---
|
||||
|
@ -183,7 +183,8 @@ fn test(
|
||||
}
|
||||
|
||||
fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec<Frame>) {
|
||||
let (src, compare_ref, map, ref_diags) = parse_metadata(&src, i);
|
||||
let map = LineMap::new(src);
|
||||
let (compare_ref, ref_diags) = parse_metadata(src, &map);
|
||||
|
||||
let mut state = State::default();
|
||||
state.page.size = Size::uniform(Length::pt(120.0));
|
||||
@ -230,58 +231,40 @@ fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec<Frame>) {
|
||||
(ok, frames)
|
||||
}
|
||||
|
||||
fn parse_metadata(src: &str, i: usize) -> (&str, bool, LineMap, SpanVec<Diag>) {
|
||||
fn parse_metadata(src: &str, map: &LineMap) -> (bool, SpanVec<Diag>) {
|
||||
let mut diags = vec![];
|
||||
let mut compare_ref = true;
|
||||
|
||||
let mut s = Scanner::new(src);
|
||||
for k in 0 .. {
|
||||
// Allow a newline directly after "---" (that is, if i > 0 and k == 0).
|
||||
if !(i > 0 && k == 0) && !s.rest().starts_with("//") {
|
||||
break;
|
||||
}
|
||||
for (i, line) in src.lines().enumerate() {
|
||||
compare_ref &= !line.starts_with("// Ref: false");
|
||||
|
||||
let line = s.eat_until(typst::parse::is_newline);
|
||||
s.eat_merging_crlf();
|
||||
|
||||
compare_ref &= !line.starts_with("// ref: false");
|
||||
|
||||
let (level, rest) = if let Some(rest) = line.strip_prefix("// warning: ") {
|
||||
let (level, rest) = if let Some(rest) = line.strip_prefix("// Warning: ") {
|
||||
(Level::Warning, rest)
|
||||
} else if let Some(rest) = line.strip_prefix("// error: ") {
|
||||
} else if let Some(rest) = line.strip_prefix("// Error: ") {
|
||||
(Level::Error, rest)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
diags.push((level, rest));
|
||||
fn num(s: &mut Scanner) -> u32 {
|
||||
s.eat_while(|c| c.is_numeric()).parse().unwrap()
|
||||
}
|
||||
|
||||
let pos = |s: &mut Scanner| -> Pos {
|
||||
let (delta, _, column) = (num(s), s.eat_assert(':'), num(s));
|
||||
let line = i as u32 + 1 + delta;
|
||||
map.pos(Location { line, column }).unwrap()
|
||||
};
|
||||
|
||||
let mut s = Scanner::new(rest);
|
||||
let (start, _, end) = (pos(&mut s), s.eat_assert('-'), pos(&mut s));
|
||||
|
||||
diags.push(Diag::new(level, s.rest().trim()).with_span(start .. end));
|
||||
}
|
||||
|
||||
let src = s.rest();
|
||||
let map = LineMap::new(src);
|
||||
|
||||
let mut diags: Vec<_> = diags
|
||||
.into_iter()
|
||||
.map(|(level, rest)| {
|
||||
fn pos(s: &mut Scanner, map: &LineMap) -> Pos {
|
||||
let (line, _, column) = (num(s), s.eat_assert(':'), num(s));
|
||||
map.pos(Location { line, column }).unwrap()
|
||||
}
|
||||
|
||||
fn num(s: &mut Scanner) -> u32 {
|
||||
s.eat_while(|c| c.is_numeric()).parse().unwrap()
|
||||
}
|
||||
|
||||
let mut s = Scanner::new(rest);
|
||||
let (start, _, end) =
|
||||
(pos(&mut s, &map), s.eat_assert('-'), pos(&mut s, &map));
|
||||
Diag::new(level, s.rest().trim()).with_span(start .. end)
|
||||
})
|
||||
.collect();
|
||||
|
||||
diags.sort_by_key(|d| d.span);
|
||||
|
||||
(src, compare_ref, map, diags)
|
||||
(compare_ref, diags)
|
||||
}
|
||||
|
||||
fn print_diag(diag: &Spanned<Diag>, map: &LineMap) {
|
||||
|