From 378662fa52bbc3e9e4a210f649093dcdadf51afa Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 17 Aug 2023 17:25:32 +0200 Subject: feat!: add span and offsets to Doctype --- tests/test_spans.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') 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#""#; + let Token::Doctype(doctype) = tokenizer(html).next().unwrap() else { + panic!("expected doctype"); + }; + let labels = vec![(doctype.span, "")]; + assert_snapshot!(annotate(html, labels), @r###" + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + "###); +} + +#[test] +fn doctype_id_spans() { + let html = r#""#; + 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###" + + ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ system id + │ + public id + "###); +} + fn annotate_errors(html: &'static str) -> String { let mut labels = Vec::new(); for token in tokenizer(html) { -- cgit v1.2.3