diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-30 18:32:30 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-05 02:52:36 +0100 |
commit | 76408590349f7f132c1dfeb9db3fb1dea964227c (patch) | |
tree | 2e88df0b737ec3225937630c758502400753f87b /tests | |
parent | c29558e8d165df1d3fc1cb32079da9e40f957dc6 (diff) |
spans: support attribute names
Diffstat (limited to 'tests')
-rw-r--r-- | tests/span-tests/demo.html | 2 | ||||
-rw-r--r-- | tests/span-tests/demo.out | 12 | ||||
-rw-r--r-- | tests/test_html5lib.rs | 28 | ||||
-rw-r--r-- | tests/test_spans.rs | 17 |
4 files changed, 50 insertions, 9 deletions
diff --git a/tests/span-tests/demo.html b/tests/span-tests/demo.html index 900f74c..53bbab2 100644 --- a/tests/span-tests/demo.html +++ b/tests/span-tests/demo.html @@ -1 +1,3 @@ this is a tag: <h1>test</h1> + +tags can have attributes: <div id = foobar> diff --git a/tests/span-tests/demo.out b/tests/span-tests/demo.out index 98d6766..2b69ce5 100644 --- a/tests/span-tests/demo.out +++ b/tests/span-tests/demo.out @@ -1,7 +1,11 @@ note: - ┌─ test.html:1:17 + ┌─ test.html:1:1 │ 1 │ this is a tag: <h1>test</h1> - │ ^^ ^^ end tag - │ │ - │ start tag + │ ^^^^^^ ^^ ^^ end tag + │ │ │ + │ │ start tag + │ attr value +2 │ +3 │ tags can have attributes: <div id = foobar> + │ ^^ attr name diff --git a/tests/test_html5lib.rs b/tests/test_html5lib.rs index 5668217..662f3c5 100644 --- a/tests/test_html5lib.rs +++ b/tests/test_html5lib.rs @@ -1,5 +1,5 @@ use html5gum::{ - Doctype, EndTag, Error, InternalState as State, Reader, StartTag, Token, Tokenizer, + Attribute, Doctype, EndTag, Error, InternalState as State, Reader, StartTag, Token, Tokenizer, }; use pretty_assertions::assert_eq; use serde::{de::Error as _, Deserialize}; @@ -79,14 +79,36 @@ impl<'de> Deserialize<'de> for ExpectedOutputTokens { OutputToken::StartTag(_, name, attributes) => Token::StartTag(StartTag { self_closing: false, name, - attributes, + attributes: attributes + .into_iter() + .map(|(k, v)| { + ( + k, + Attribute { + value: v, + ..Default::default() + }, + ) + }) + .collect(), name_span: (), }), OutputToken::StartTag2(_, name, attributes, self_closing) => { Token::StartTag(StartTag { self_closing, name, - attributes, + attributes: attributes + .into_iter() + .map(|(k, v)| { + ( + k, + Attribute { + value: v, + ..Default::default() + }, + ) + }) + .collect(), name_span: (), }) } diff --git a/tests/test_spans.rs b/tests/test_spans.rs index a3d1c96..9cc745c 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -29,9 +29,22 @@ fn test() { .infallible() { if let Token::StartTag(tag) = token { - labels.push(Label::primary(file_id, tag.name_span).with_message("start tag")); + if tag.name == "h1" { + labels.push(Label::primary(file_id, tag.name_span).with_message("start tag")); + } else { + for attr in tag.attributes.values() { + labels.push( + Label::primary(file_id, attr.name_span.clone()).with_message("attr name"), + ); + labels.push( + Label::primary(file_id, attr.value_span.clone()).with_message("attr value"), + ); + } + } } else if let Token::EndTag(tag) = token { - labels.push(Label::primary(file_id, tag.name_span).with_message("end tag")); + if tag.name == "h1" { + labels.push(Label::primary(file_id, tag.name_span).with_message("end tag")); + } } } |