aboutsummaryrefslogtreecommitdiff
path: root/tests/test_spans.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-08-17 17:25:32 +0200
committerMartin Fischer <martin@push-f.com>2023-08-19 13:41:55 +0200
commit378662fa52bbc3e9e4a210f649093dcdadf51afa (patch)
tree44168be8588b8c17fc920839bc93595ea0152aea /tests/test_spans.rs
parente34083e64b764df076c1ef9ec6bf1102b9fbf748 (diff)
feat!: add span and offsets to Doctype
Diffstat (limited to 'tests/test_spans.rs')
-rw-r--r--tests/test_spans.rs31
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) {