diff --git a/tests/ref/arrays.png b/tests/ref/arrays.png
index 4a95278c0..8fda7cf6b 100644
Binary files a/tests/ref/arrays.png and b/tests/ref/arrays.png differ
diff --git a/tests/ref/basic-markup.png b/tests/ref/basics.png
similarity index 100%
rename from tests/ref/basic-markup.png
rename to tests/ref/basics.png
diff --git a/tests/ref/dictionaries.png b/tests/ref/dictionaries.png
index a34b45e07..42cb431d6 100644
Binary files a/tests/ref/dictionaries.png and b/tests/ref/dictionaries.png differ
diff --git a/tests/ref/escaping.png b/tests/ref/escaping.png
index fedd3e588..06c0310dc 100644
Binary files a/tests/ref/escaping.png and b/tests/ref/escaping.png differ
diff --git a/tests/ref/func-h-and-v.png b/tests/ref/func-hv.png
similarity index 100%
rename from tests/ref/func-h-and-v.png
rename to tests/ref/func-hv.png
diff --git a/tests/typ/arrays.typ b/tests/typ/arrays.typ
index adab2ad93..0b8fb866a 100644
--- a/tests/typ/arrays.typ
+++ b/tests/typ/arrays.typ
@@ -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)}
diff --git a/tests/typ/basic-markup.typ b/tests/typ/basics.typ
similarity index 100%
rename from tests/typ/basic-markup.typ
rename to tests/typ/basics.typ
diff --git a/tests/typ/comments.typ b/tests/typ/comments.typ
index 0dfb4b8ef..56906d0ca 100644
--- a/tests/typ/comments.typ
+++ b/tests/typ/comments.typ
@@ -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.
diff --git a/tests/typ/dictionaries.typ b/tests/typ/dictionaries.typ
index 51e3eb3c2..c729b92c5 100644
--- a/tests/typ/dictionaries.typ
+++ b/tests/typ/dictionaries.typ
@@ -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::)}
diff --git a/tests/typ/escaping.typ b/tests/typ/escaping.typ
index a562dcc0c..cb663612a 100644
--- a/tests/typ/escaping.typ
+++ b/tests/typ/escaping.typ
@@ -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\}
diff --git a/tests/typ/func-font.typ b/tests/typ/func-font.typ
index c73e3a1a6..8199ecb43 100644
--- a/tests/typ/func-font.typ
+++ b/tests/typ/func-font.typ
@@ -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"]
diff --git a/tests/typ/func-h-and-v.typ b/tests/typ/func-hv.typ
similarity index 83%
rename from tests/typ/func-h-and-v.typ
rename to tests/typ/func-hv.typ
index 7b8843c83..f930bc129 100644
--- a/tests/typ/func-h-and-v.typ
+++ b/tests/typ/func-hv.typ
@@ -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
diff --git a/tests/typ/func-image.typ b/tests/typ/func-image.typ
index 78a644c04..b0ca03577 100644
--- a/tests/typ/func-image.typ
+++ b/tests/typ/func-image.typ
@@ -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"]
diff --git a/tests/typ/func-page.typ b/tests/typ/func-page.typ
index 6b9382b9a..465a3469e 100644
--- a/tests/typ/func-page.typ
+++ b/tests/typ/func-page.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]
diff --git a/tests/typ/func-rgb.typ b/tests/typ/func-rgb.typ
index e88b19bf1..d29c29409 100644
--- a/tests/typ/func-rgb.typ
+++ b/tests/typ/func-rgb.typ
@@ -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]
diff --git a/tests/typ/headings.typ b/tests/typ/headings.typ
index 3a1157462..de98eddb9 100644
--- a/tests/typ/headings.typ
+++ b/tests/typ/headings.typ
@@ -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
---
diff --git a/tests/typeset.rs b/tests/typeset.rs
index 2b342c5bc..6f077ed15 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -183,7 +183,8 @@ fn test(
}
fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec) {
- 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) {
(ok, frames)
}
-fn parse_metadata(src: &str, i: usize) -> (&str, bool, LineMap, SpanVec) {
+fn parse_metadata(src: &str, map: &LineMap) -> (bool, SpanVec) {
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, map: &LineMap) {