aboutsummaryrefslogtreecommitdiff
path: root/tests/test_spans.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_spans.rs')
-rw-r--r--tests/test_spans.rs33
1 files changed, 33 insertions, 0 deletions
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 = "<!-- Why are you looking at the source code? -->";
+ 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###"
+ <!-- Why are you looking at the source code? -->
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ "###);
+}
+
+#[test]
+fn comment_bogus_data_span() {
+ let html = "<! Why are you looking at the source code? -->";
+ 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###"
+ <! Why are you looking at the source code? -->
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ "###);
+}
+
fn annotate_errors(html: &'static str) -> String {
let mut labels = Vec::new();
for token in tokenizer(html) {