diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-30 10:56:59 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-30 11:22:35 +0100 |
commit | 915530c02029f8bd4444930ed949e14f09afab03 (patch) | |
tree | 6f58b9728386dc5c1709137bc0a250640a7ce572 /tests/spans.rs | |
parent | 414e5838618123cb00216a7426b898aab88ee45a (diff) |
report spans for errors
Diffstat (limited to 'tests/spans.rs')
-rw-r--r-- | tests/spans.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/spans.rs b/tests/spans.rs index bfa42f6..5615853 100644 --- a/tests/spans.rs +++ b/tests/spans.rs @@ -1,5 +1,5 @@ #![cfg(feature = "spans")] -use std::include_str; +use std::{include_str, ops::Range}; use codespan_reporting::{ self, @@ -8,18 +8,21 @@ use codespan_reporting::{ term::{self, termcolor::Buffer}, }; use html5tokenizer::{ - BufferQueue, Tag, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts, + error::Error, BufferQueue, Tag, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts, }; #[derive(Default)] struct TagSink { tags: Vec<Tag>, + errors: Vec<(Error, Range<usize>)>, } impl TokenSink for TagSink { fn process_token(&mut self, token: Token, _line_number: u64) -> TokenSinkResult { if let Token::TagToken(tag) = token { self.tags.push(tag); + } else if let Token::ParseError { error, span } = token { + self.errors.push((error, span)); } TokenSinkResult::Continue } @@ -61,6 +64,9 @@ fn test() { Label::primary(file_id, tags[4].attrs[1].value_span.clone()) .with_message("in double quotes"), ); + for (error, span) in tok.sink.errors { + labels.push(Label::primary(file_id, span).with_message(format!("{}", error))); + } let diagnostic = Diagnostic::note().with_labels(labels); let mut writer = Buffer::no_color(); |