From 4d9cf7171836625b61dcfe675bdf9452766166c0 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 17 Aug 2023 15:21:32 +0200 Subject: feat!: add offset to comments --- tests/test_spans.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/test_spans.rs b/tests/test_spans.rs index b41b1b9..21882a3 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -105,6 +105,39 @@ fn attribute_value_span() { "###); } +#[test] +fn comment_proper_data_span() { + let html = ""; + let Token::Comment(comment) = tokenizer(html).next().unwrap() else { + panic!("expected comment"); + }; + // FIXME: this span is wrong (starts one byte too soon) + assert_eq!(comment.data, html[1..][comment.data_span()]); + let labels = vec![(comment.data_span(), "")]; + assert_snapshot!(annotate(html, labels), @r###" + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + "###); +} + +#[test] +fn comment_bogus_data_span() { + let html = ""; + let Token::Comment(comment) = tokenizer(html) + .filter(|t| !matches!(t, Token::Error { .. })) + .next() + .unwrap() + else { + panic!("expected comment"); + }; + assert_eq!(comment.data, html[comment.data_span()]); + let labels = vec![(comment.data_span(), "")]; + assert_snapshot!(annotate(html, labels), @r###" + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + "###); +} + fn annotate_errors(html: &'static str) -> String { let mut labels = Vec::new(); for token in tokenizer(html) { -- cgit v1.2.3