diff options
author | Martin Fischer <martin@push-f.com> | 2023-08-17 15:21:32 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-08-19 11:41:55 +0200 |
commit | 4d9cf7171836625b61dcfe675bdf9452766166c0 (patch) | |
tree | 90bc623a08b945439b6a5077bdfdf54de7eacc37 /tests/test_spans.rs | |
parent | c169e78f120ea9be451f337306b8bff6c1fb4955 (diff) |
feat!: add offset to comments
Diffstat (limited to 'tests/test_spans.rs')
-rw-r--r-- | tests/test_spans.rs | 33 |
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) { |