Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
failures (2): ---- issue514::no_mismatch stdout ---- thread 'issue514::no_mismatch' panicked at 'called `Result::unwrap()` on an `Err` value: EndEventMismatch { expected: "html", found: "some-tag" }', tests\issues.rs:34:40 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- issue514::mismatch stdout ---- thread 'issue514::mismatch' panicked at 'assertion failed: `(left == right)` Diff < left / right > : <html >some-tag ', tests\issues.rs:59:17
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! Regression tests found in various issues | ||
//! | ||
//! Name each test as `issue<GH number>` | ||
|
||
use quick_xml::events::{BytesStart, Event}; | ||
use quick_xml::reader::Reader; | ||
use quick_xml::Error; | ||
|
||
/// Regression test for https://github.com/tafia/quick-xml/issues/514 | ||
mod issue514 { | ||
use super::*; | ||
use pretty_assertions::assert_eq; | ||
|
||
/// Check that there is no unexpected error | ||
#[test] | ||
fn no_mismatch() { | ||
let mut reader = Reader::from_str("<some-tag><html>...</html></some-tag>"); | ||
|
||
let outer_start = BytesStart::new("some-tag"); | ||
let outer_end = outer_start.to_end().into_owned(); | ||
|
||
let html_start = BytesStart::new("html"); | ||
let html_end = html_start.to_end().into_owned(); | ||
|
||
assert_eq!(reader.read_event().unwrap(), Event::Start(outer_start)); | ||
assert_eq!(reader.read_event().unwrap(), Event::Start(html_start)); | ||
|
||
reader.check_end_names(false); | ||
|
||
assert_eq!(reader.read_text(html_end.name()).unwrap(), "..."); | ||
|
||
reader.check_end_names(true); | ||
|
||
assert_eq!(reader.read_event().unwrap(), Event::End(outer_end)); | ||
assert_eq!(reader.read_event().unwrap(), Event::Eof); | ||
} | ||
|
||
/// Canary check that legitimate error is reported | ||
#[test] | ||
fn mismatch() { | ||
let mut reader = Reader::from_str("<some-tag><html>...</html></other-tag>"); | ||
|
||
let outer_start = BytesStart::new("some-tag"); | ||
|
||
let html_start = BytesStart::new("html"); | ||
let html_end = html_start.to_end().into_owned(); | ||
|
||
assert_eq!(reader.read_event().unwrap(), Event::Start(outer_start)); | ||
assert_eq!(reader.read_event().unwrap(), Event::Start(html_start)); | ||
|
||
reader.check_end_names(false); | ||
|
||
assert_eq!(reader.read_text(html_end.name()).unwrap(), "..."); | ||
|
||
reader.check_end_names(true); | ||
|
||
match reader.read_event() { | ||
Err(Error::EndEventMismatch { expected, found }) => { | ||
assert_eq!(expected, "some-tag"); | ||
assert_eq!(found, "other-tag"); | ||
} | ||
x => panic!( | ||
r#"Expected `Err(EndEventMismatch("some-tag", "other-tag")))`, but found {:?}"#, | ||
x | ||
), | ||
} | ||
assert_eq!(reader.read_event().unwrap(), Event::Eof); | ||
} | ||
} |