Skip to content

Commit 0c2936c

Browse files
committed
Check buffer_position() after resume parsing after ill-formed error
failures (66): ill_formed::double_hyphen_in_comment2::ns_reader::async_tokio ill_formed::double_hyphen_in_comment2::ns_reader::borrowed ill_formed::double_hyphen_in_comment2::ns_reader::buffered ill_formed::double_hyphen_in_comment2::reader::async_tokio ill_formed::double_hyphen_in_comment2::reader::borrowed ill_formed::double_hyphen_in_comment2::reader::buffered ill_formed::double_hyphen_in_comment3::ns_reader::async_tokio ill_formed::double_hyphen_in_comment3::ns_reader::borrowed ill_formed::double_hyphen_in_comment3::ns_reader::buffered ill_formed::double_hyphen_in_comment3::reader::async_tokio ill_formed::double_hyphen_in_comment3::reader::borrowed ill_formed::double_hyphen_in_comment3::reader::buffered ill_formed::double_hyphen_in_comment4::ns_reader::async_tokio ill_formed::double_hyphen_in_comment4::ns_reader::borrowed ill_formed::double_hyphen_in_comment4::ns_reader::buffered ill_formed::double_hyphen_in_comment4::reader::async_tokio ill_formed::double_hyphen_in_comment4::reader::borrowed ill_formed::double_hyphen_in_comment4::reader::buffered ill_formed::mismatched_end_tag2::ns_reader::async_tokio ill_formed::mismatched_end_tag2::ns_reader::borrowed ill_formed::mismatched_end_tag2::ns_reader::buffered ill_formed::mismatched_end_tag2::reader::async_tokio ill_formed::mismatched_end_tag2::reader::borrowed ill_formed::mismatched_end_tag2::reader::buffered ill_formed::mismatched_end_tag3::ns_reader::async_tokio ill_formed::mismatched_end_tag3::ns_reader::borrowed ill_formed::mismatched_end_tag3::ns_reader::buffered ill_formed::mismatched_end_tag3::reader::async_tokio ill_formed::mismatched_end_tag3::reader::borrowed ill_formed::mismatched_end_tag3::reader::buffered ill_formed::mismatched_end_tag4::ns_reader::async_tokio ill_formed::mismatched_end_tag4::ns_reader::borrowed ill_formed::mismatched_end_tag4::ns_reader::buffered ill_formed::mismatched_end_tag4::reader::async_tokio ill_formed::mismatched_end_tag4::reader::borrowed ill_formed::mismatched_end_tag4::reader::buffered ill_formed::missing_doctype_name1::ns_reader::async_tokio ill_formed::missing_doctype_name1::ns_reader::borrowed ill_formed::missing_doctype_name1::ns_reader::buffered ill_formed::missing_doctype_name1::reader::async_tokio ill_formed::missing_doctype_name1::reader::borrowed ill_formed::missing_doctype_name1::reader::buffered ill_formed::missing_doctype_name2::ns_reader::async_tokio ill_formed::missing_doctype_name2::ns_reader::borrowed ill_formed::missing_doctype_name2::ns_reader::buffered ill_formed::missing_doctype_name2::reader::async_tokio ill_formed::missing_doctype_name2::reader::borrowed ill_formed::missing_doctype_name2::reader::buffered ill_formed::unmatched_end_tag1::ns_reader::async_tokio ill_formed::unmatched_end_tag1::ns_reader::borrowed ill_formed::unmatched_end_tag1::ns_reader::buffered ill_formed::unmatched_end_tag1::reader::async_tokio ill_formed::unmatched_end_tag1::reader::borrowed ill_formed::unmatched_end_tag1::reader::buffered ill_formed::unmatched_end_tag2::ns_reader::async_tokio ill_formed::unmatched_end_tag2::ns_reader::borrowed ill_formed::unmatched_end_tag2::ns_reader::buffered ill_formed::unmatched_end_tag2::reader::async_tokio ill_formed::unmatched_end_tag2::reader::borrowed ill_formed::unmatched_end_tag2::reader::buffered ill_formed::unmatched_end_tag3::ns_reader::async_tokio ill_formed::unmatched_end_tag3::ns_reader::borrowed ill_formed::unmatched_end_tag3::ns_reader::buffered ill_formed::unmatched_end_tag3::reader::async_tokio ill_formed::unmatched_end_tag3::reader::borrowed ill_formed::unmatched_end_tag3::reader::buffered
1 parent 5d49266 commit 0c2936c

File tree

1 file changed

+84
-12
lines changed

1 file changed

+84
-12
lines changed

tests/reader-errors.rs

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ mod ill_formed {
425425

426426
#[test]
427427
fn borrowed() {
428-
let mut reader = Reader::from_str(concat!($xml, "<x/>"));
428+
let xml = concat!($xml, "<x/>");
429+
let mut reader = Reader::from_str(xml);
429430
reader.config_mut().enable_all_checks(true);
430431
match reader.read_event() {
431432
Err(Error::IllFormed(cause)) => assert_eq!(
@@ -440,12 +441,18 @@ mod ill_formed {
440441
),
441442
Event::Empty(BytesStart::new("x"))
442443
);
444+
assert_eq!(
445+
reader.buffer_position(),
446+
xml.len(),
447+
".buffer_position() is incorrect in the end"
448+
);
443449
}
444450

445451
#[test]
446452
fn buffered() {
453+
let xml = concat!($xml, "<x/>");
447454
let mut buf = Vec::new();
448-
let mut reader = Reader::from_str(concat!($xml, "<x/>"));
455+
let mut reader = Reader::from_str(xml);
449456
reader.config_mut().enable_all_checks(true);
450457
match reader.read_event_into(&mut buf) {
451458
Err(Error::IllFormed(cause)) => assert_eq!(
@@ -460,13 +467,19 @@ mod ill_formed {
460467
),
461468
Event::Empty(BytesStart::new("x"))
462469
);
470+
assert_eq!(
471+
reader.buffer_position(),
472+
xml.len(),
473+
".buffer_position() is incorrect in the end"
474+
);
463475
}
464476

465477
#[cfg(feature = "async-tokio")]
466478
#[tokio::test]
467479
async fn async_tokio() {
480+
let xml = concat!($xml, "<x/>");
468481
let mut buf = Vec::new();
469-
let mut reader = Reader::from_str(concat!($xml, "<x/>"));
482+
let mut reader = Reader::from_str(xml);
470483
reader.config_mut().enable_all_checks(true);
471484
match reader.read_event_into_async(&mut buf).await {
472485
Err(Error::IllFormed(cause)) => assert_eq!(
@@ -481,6 +494,11 @@ mod ill_formed {
481494
),
482495
Event::Empty(BytesStart::new("x"))
483496
);
497+
assert_eq!(
498+
reader.buffer_position(),
499+
xml.len(),
500+
".buffer_position() is incorrect in the end"
501+
);
484502
}
485503
}
486504

@@ -490,7 +508,8 @@ mod ill_formed {
490508

491509
#[test]
492510
fn borrowed() {
493-
let mut reader = NsReader::from_str(concat!($xml, "<x/>"));
511+
let xml = concat!($xml, "<x/>");
512+
let mut reader = NsReader::from_str(xml);
494513
reader.config_mut().enable_all_checks(true);
495514
match reader.read_resolved_event() {
496515
Err(Error::IllFormed(cause)) => assert_eq!(
@@ -508,12 +527,18 @@ mod ill_formed {
508527
.1,
509528
Event::Empty(BytesStart::new("x"))
510529
);
530+
assert_eq!(
531+
reader.buffer_position(),
532+
xml.len(),
533+
".buffer_position() is incorrect in the end"
534+
);
511535
}
512536

513537
#[test]
514538
fn buffered() {
539+
let xml = concat!($xml, "<x/>");
515540
let mut buf = Vec::new();
516-
let mut reader = NsReader::from_str(concat!($xml, "<x/>"));
541+
let mut reader = NsReader::from_str(xml);
517542
reader.config_mut().enable_all_checks(true);
518543
match reader.read_resolved_event_into(&mut buf) {
519544
Err(Error::IllFormed(cause)) => assert_eq!(
@@ -531,13 +556,19 @@ mod ill_formed {
531556
.1,
532557
Event::Empty(BytesStart::new("x"))
533558
);
559+
assert_eq!(
560+
reader.buffer_position(),
561+
xml.len(),
562+
".buffer_position() is incorrect in the end"
563+
);
534564
}
535565

536566
#[cfg(feature = "async-tokio")]
537567
#[tokio::test]
538568
async fn async_tokio() {
569+
let xml = concat!($xml, "<x/>");
539570
let mut buf = Vec::new();
540-
let mut reader = NsReader::from_str(concat!($xml, "<x/>"));
571+
let mut reader = NsReader::from_str(xml);
541572
reader.config_mut().enable_all_checks(true);
542573
match reader.read_resolved_event_into_async(&mut buf).await {
543574
Err(Error::IllFormed(cause)) => assert_eq!(
@@ -556,6 +587,11 @@ mod ill_formed {
556587
.1,
557588
Event::Empty(BytesStart::new("x"))
558589
);
590+
assert_eq!(
591+
reader.buffer_position(),
592+
xml.len(),
593+
".buffer_position() is incorrect in the end"
594+
);
559595
}
560596
}
561597
}
@@ -574,7 +610,8 @@ mod ill_formed {
574610

575611
#[test]
576612
fn borrowed() {
577-
let mut reader = Reader::from_str(concat!($xml, "<x/>"));
613+
let xml = concat!($xml, "<x/>");
614+
let mut reader = Reader::from_str(xml);
578615
reader.config_mut().enable_all_checks(true);
579616
reader.read_event().expect("first .read_event()");
580617
match reader.read_event() {
@@ -590,12 +627,18 @@ mod ill_formed {
590627
),
591628
Event::Empty(BytesStart::new("x"))
592629
);
630+
assert_eq!(
631+
reader.buffer_position(),
632+
xml.len(),
633+
".buffer_position() is incorrect in the end"
634+
);
593635
}
594636

595637
#[test]
596638
fn buffered() {
639+
let xml = concat!($xml, "<x/>");
597640
let mut buf = Vec::new();
598-
let mut reader = Reader::from_str(concat!($xml, "<x/>"));
641+
let mut reader = Reader::from_str(xml);
599642
reader.config_mut().enable_all_checks(true);
600643
reader
601644
.read_event_into(&mut buf)
@@ -613,13 +656,19 @@ mod ill_formed {
613656
),
614657
Event::Empty(BytesStart::new("x"))
615658
);
659+
assert_eq!(
660+
reader.buffer_position(),
661+
xml.len(),
662+
".buffer_position() is incorrect in the end"
663+
);
616664
}
617665

618666
#[cfg(feature = "async-tokio")]
619667
#[tokio::test]
620668
async fn async_tokio() {
669+
let xml = concat!($xml, "<x/>");
621670
let mut buf = Vec::new();
622-
let mut reader = Reader::from_str(concat!($xml, "<x/>"));
671+
let mut reader = Reader::from_str(xml);
623672
reader.config_mut().enable_all_checks(true);
624673
reader
625674
.read_event_into_async(&mut buf)
@@ -638,6 +687,11 @@ mod ill_formed {
638687
),
639688
Event::Empty(BytesStart::new("x"))
640689
);
690+
assert_eq!(
691+
reader.buffer_position(),
692+
xml.len(),
693+
".buffer_position() is incorrect in the end"
694+
);
641695
}
642696
}
643697

@@ -647,7 +701,8 @@ mod ill_formed {
647701

648702
#[test]
649703
fn borrowed() {
650-
let mut reader = NsReader::from_str(concat!($xml, "<x/>"));
704+
let xml = concat!($xml, "<x/>");
705+
let mut reader = NsReader::from_str(xml);
651706
reader.config_mut().enable_all_checks(true);
652707
reader.read_event().expect("first .read_resolved_event()");
653708
match reader.read_resolved_event() {
@@ -666,12 +721,18 @@ mod ill_formed {
666721
.1,
667722
Event::Empty(BytesStart::new("x"))
668723
);
724+
assert_eq!(
725+
reader.buffer_position(),
726+
xml.len(),
727+
".buffer_position() is incorrect in the end"
728+
);
669729
}
670730

671731
#[test]
672732
fn buffered() {
733+
let xml = concat!($xml, "<x/>");
673734
let mut buf = Vec::new();
674-
let mut reader = NsReader::from_str(concat!($xml, "<x/>"));
735+
let mut reader = NsReader::from_str(xml);
675736
reader.config_mut().enable_all_checks(true);
676737
reader
677738
.read_resolved_event_into(&mut buf)
@@ -692,13 +753,19 @@ mod ill_formed {
692753
.1,
693754
Event::Empty(BytesStart::new("x"))
694755
);
756+
assert_eq!(
757+
reader.buffer_position(),
758+
xml.len(),
759+
".buffer_position() is incorrect in the end"
760+
);
695761
}
696762

697763
#[cfg(feature = "async-tokio")]
698764
#[tokio::test]
699765
async fn async_tokio() {
766+
let xml = concat!($xml, "<x/>");
700767
let mut buf = Vec::new();
701-
let mut reader = NsReader::from_str(concat!($xml, "<x/>"));
768+
let mut reader = NsReader::from_str(xml);
702769
reader.config_mut().enable_all_checks(true);
703770
reader
704771
.read_resolved_event_into_async(&mut buf)
@@ -721,6 +788,11 @@ mod ill_formed {
721788
.1,
722789
Event::Empty(BytesStart::new("x"))
723790
);
791+
assert_eq!(
792+
reader.buffer_position(),
793+
xml.len(),
794+
".buffer_position() is incorrect in the end"
795+
);
724796
}
725797
}
726798
}

0 commit comments

Comments
 (0)