From f9639d724e1a6f1e8edaeafa78c2c3d8b43640a3 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 30 Nov 2021 19:11:19 +0100 Subject: spans: add spans to Token::Error --- tests/span-tests/demo.html | 10 ++++++++++ tests/span-tests/demo.out | 46 ++++++++++++++++++++++++++++------------------ tests/test_html5lib.rs | 4 ++-- tests/test_spans.rs | 4 +++- 4 files changed, 43 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/span-tests/demo.html b/tests/span-tests/demo.html index c635846..07c305b 100644 --- a/tests/span-tests/demo.html +++ b/tests/span-tests/demo.html @@ -3,3 +3,13 @@ this is a tag:

test

tags can have attributes:
Attribute values can be quoted: + +But you cannot put attributes everywhere: + +Please mind the gap: < test + +The pirate says &arrrrr; + +Does this open two pages? click me + +Do you start or do you end? diff --git a/tests/span-tests/demo.out b/tests/span-tests/demo.out index ad9cfb8..37ab8be 100644 --- a/tests/span-tests/demo.out +++ b/tests/span-tests/demo.out @@ -1,19 +1,29 @@ note: - ┌─ test.html:1:1 - │ -1 │ this is a tag:

test

- │ ^^ ^^ end tag - │ │ - │ start tag -2 │ -3 │ tags can have attributes:
- │ ^^ ^^^^^^ attr value - │ │ - │ attr name -4 │ -5 │ Attribute values can be quoted: - │ ^^^^ ^^^ ^^^^ ^^^^^^ attr value - │ │ │ │ - │ │ │ attr name - │ │ attr value - │ attr name + ┌─ test.html:1:17 + │ + 1 │ this is a tag:

test

+ │ ^^ ^^ end tag + │ │ + │ start tag + · + 5 │ Attribute values can be quoted: + │ ^^^^ ^^^ ^^^^ ^^^^^^ attr value + │ │ │ │ + │ │ │ attr name + │ │ attr value + │ attr name + 6 │ + 7 │ But you cannot put attributes everywhere: + │ ^^^^ end-tag-with-attributes + 8 │ + 9 │ Please mind the gap: < test + │ ^ invalid-first-character-of-tag-name +10 │ +11 │ The pirate says &arrrrr; + │ ^ unknown-named-character-reference +12 │ +13 │ Does this open two pages? click me + │ ^^^^ duplicate-attribute +14 │ +15 │ Do you start or do you end? + │ ^ end-tag-with-trailing-solidus diff --git a/tests/test_html5lib.rs b/tests/test_html5lib.rs index 662f3c5..cd3785f 100644 --- a/tests/test_html5lib.rs +++ b/tests/test_html5lib.rs @@ -296,9 +296,9 @@ fn run_test_inner( for token in tokenizer { let token = token.unwrap(); - if let Token::Error(e) = token { + if let Token::Error { error, .. } = token { actual_errors.push(ParseError { - code: ParseErrorInner(e), + code: ParseErrorInner(error), }); } else { actual_tokens.push(token); diff --git a/tests/test_spans.rs b/tests/test_spans.rs index 9cc745c..aeb4a94 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -31,7 +31,7 @@ fn test() { if let Token::StartTag(tag) = token { if tag.name == "h1" { labels.push(Label::primary(file_id, tag.name_span).with_message("start tag")); - } else { + } else if tag.name == "input" { for attr in tag.attributes.values() { labels.push( Label::primary(file_id, attr.name_span.clone()).with_message("attr name"), @@ -45,6 +45,8 @@ fn test() { if tag.name == "h1" { labels.push(Label::primary(file_id, tag.name_span).with_message("end tag")); } + } else if let Token::Error { error, span } = token { + labels.push(Label::primary(file_id, span).with_message(error.to_string())); } } -- cgit v1.2.3