aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_spans.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/tests/test_spans.rs b/tests/test_spans.rs
index 0b0e156..4de0714 100644
--- a/tests/test_spans.rs
+++ b/tests/test_spans.rs
@@ -6,12 +6,19 @@ use codespan_reporting::{
files::SimpleFiles,
term::{self, termcolor::Buffer},
};
-use html5tokenizer::{offset::PosTrackingReader, NaiveParser, Token};
+use html5tokenizer::{
+ offset::PosTrackingReader,
+ reader::{IntoReader, Reader},
+ NaiveParser, Token,
+};
use insta::assert_snapshot;
use similar_asserts::assert_eq;
-fn parser(html: &'static str) -> impl Iterator<Item = Token<usize>> {
- NaiveParser::new(PosTrackingReader::new(html)).flatten()
+fn parser<R>(reader: impl IntoReader<'static, Reader = R>) -> impl Iterator<Item = Token<usize>>
+where
+ R: Reader,
+{
+ NaiveParser::new(PosTrackingReader::new(reader)).flatten()
}
/// Just a convenient type alias for labeler closures calling `tokens.next()`
@@ -250,7 +257,7 @@ fn comment_data_span() {
"###);
for (idx, case) in cases.iter().enumerate() {
- let Token::Comment(comment) = parser(case)
+ let Token::Comment(comment) = parser(*case)
.filter(|t| !matches!(t, Token::Error { .. }))
.next()
.unwrap()
@@ -535,12 +542,8 @@ fn assert_char_encoding_independence<S: AsRef<str> + Clone>(
html: &'static str,
labeler: impl Fn(TokenIter) -> Vec<(Range<usize>, S)>,
) {
- let utf8_tokens = NaiveParser::new(PosTrackingReader::new(html)).flatten();
- let string_reader = html5tokenizer::reader::IntoReader::into_reader(html);
- let utf16_tokens =
- NaiveParser::new(PosTrackingReader::new(Utf16Reader(string_reader))).flatten();
- let utf8_labels = labeler(Box::new(utf8_tokens));
- let utf16_labels = labeler(Box::new(utf16_tokens));
+ let utf8_labels = labeler(Box::new(parser(html)));
+ let utf16_labels = labeler(Box::new(parser(Utf16Reader(html.into_reader()))));
for (idx, (span, _)) in utf16_labels.into_iter().enumerate() {
let expected_utf16_span = Range {