diff options
author | Martin Fischer <martin@push-f.com> | 2023-09-04 09:15:30 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-09-28 07:26:44 +0200 |
commit | 9dd2ac1c95c949066e341837650c3211769342c3 (patch) | |
tree | 63511dd21605a085168040d2c727eae939c41140 /tests/test_spans.rs | |
parent | f434e817fad59bc4b4f03c65c19a035f415aee1a (diff) |
refactor: make parser helper fn generic over reader
Diffstat (limited to 'tests/test_spans.rs')
-rw-r--r-- | tests/test_spans.rs | 23 |
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 { |