From 854e55cd8577baa24a2f3bd00e4ed8687e150f36 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 30 Aug 2023 09:42:36 +0200 Subject: fix: most error spans mistakenly being empty With codespan_reporting an empty span shows up exactly like a one-byte span, which is why I didn't notice this mistake earlier. --- tests/test_spans.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_spans.rs b/tests/test_spans.rs index e839f53..28342ea 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -213,9 +213,20 @@ fn doctype_id_spans() { fn annotate_errors(html: &'static str) -> String { let mut labels = Vec::new(); for token in tokenizer(html) { - if let Token::Error { error, span } = token { - labels.push((span, error.code())); + let Token::Error { error, span } = token else { + continue; + }; + + if span.start == span.end { + if span.start != html.len() { + panic!("empty error spans are only allowed at the very end of the source (for eof errors)"); + } + } else { + assert!(span.start < span.end); + assert!(span.end <= html.len()); } + + labels.push((span, error.code())); } annotate(html, labels) } -- cgit v1.2.3