diff options
author | Martin Fischer <martin@push-f.com> | 2023-08-17 17:25:32 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-08-19 13:41:55 +0200 |
commit | 378662fa52bbc3e9e4a210f649093dcdadf51afa (patch) | |
tree | 44168be8588b8c17fc920839bc93595ea0152aea /tests | |
parent | e34083e64b764df076c1ef9ec6bf1102b9fbf748 (diff) |
feat!: add span and offsets to Doctype
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_spans.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_spans.rs b/tests/test_spans.rs index 6bd9378..70bcf6e 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -167,6 +167,37 @@ fn comment_bogus_data_span() { "###); } +#[test] +fn doctype_span() { + let html = r#"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >"#; + let Token::Doctype(doctype) = tokenizer(html).next().unwrap() else { + panic!("expected doctype"); + }; + let labels = vec![(doctype.span, "")]; + assert_snapshot!(annotate(html, labels), @r###" + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + "###); +} + +#[test] +fn doctype_id_spans() { + let html = r#"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">"#; + let Token::Doctype(doctype) = tokenizer(html).next().unwrap() else { + panic!("expected doctype"); + }; + let labels = vec![ + (doctype.public_id_span().unwrap(), "public id"), + (doctype.system_id_span().unwrap(), "system id"), + ]; + assert_snapshot!(annotate(html, labels), @r###" + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> + ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ system id + │ + public id + "###); +} + fn annotate_errors(html: &'static str) -> String { let mut labels = Vec::new(); for token in tokenizer(html) { |