diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/files/test.html | 4 | ||||
| -rw-r--r-- | tests/files/test.out | 38 | ||||
| -rw-r--r-- | tests/spans.rs | 10 | 
3 files changed, 34 insertions, 18 deletions
| diff --git a/tests/files/test.html b/tests/files/test.html index 0dcbdbf..14493b7 100644 --- a/tests/files/test.html +++ b/tests/files/test.html @@ -5,3 +5,7 @@ Here is a tag: <strong >very cool</strong>  Tags can have attributes: <div id = foo >...</div>  Attribute values can be quoted: <input name = 'age' type = "number"> + +This is malformed < test + +Characters can be escaped but don't forget the semicolon: ¶ diff --git a/tests/files/test.out b/tests/files/test.out index 7127ebc..f5acb3e 100644 --- a/tests/files/test.out +++ b/tests/files/test.out @@ -1,17 +1,23 @@  note: -  ┌─ test.html:3:17 -  │ -3 │ Here is a tag: <strong >very cool</strong> -  │                 ^^^^^^             ^^^^^^ EndTag -  │                 │ -  │                 StartTag -4 │ -5 │ Tags can have attributes: <div id = foo >...</div> -  │                                ^^   ^^^ attribute value -  │                                │ -  │                                attribute name -6 │ -7 │ Attribute values can be quoted: <input name = 'age' type = "number"> -  │                                                ^^^          ^^^^^^ in double quotes -  │                                                │ -  │                                                in single quotes +   ┌─ test.html:3:17 +   │ + 3 │ Here is a tag: <strong >very cool</strong> +   │                 ^^^^^^             ^^^^^^ EndTag +   │                 │ +   │                 StartTag + 4 │ + 5 │ Tags can have attributes: <div id = foo >...</div> +   │                                ^^   ^^^ attribute value +   │                                │ +   │                                attribute name + 6 │ + 7 │ Attribute values can be quoted: <input name = 'age' type = "number"> +   │                                                ^^^          ^^^^^^ in double quotes +   │                                                │ +   │                                                in single quotes + 8 │ + 9 │ This is malformed < test +   │                    ^ unexpected character: saw ' ' in state TagOpen +10 │ +11 │ Characters can be escaped but don't forget the semicolon: ¶ +   │                                                               ^ semicolon missing after character reference 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(); | 
