forked from tafia/quick-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissues.rs
107 lines (85 loc) · 3.3 KB
/
issues.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Regression tests found in various issues.
//!
//! Name each module / test as `issue<GH number>` and keep sorted by issue number
use std::sync::mpsc;
use quick_xml::events::{BytesStart, Event};
use quick_xml::name::QName;
use quick_xml::reader::Reader;
use quick_xml::Error;
/// Regression test for https://github.com/tafia/quick-xml/issues/115
#[test]
fn issue115() {
let mut r = Reader::from_str("<tag1 attr1='line 1\nline 2'></tag1>");
match r.read_event() {
Ok(Event::Start(e)) if e.name() == QName(b"tag1") => {
let v = e.attributes().map(|a| a.unwrap().value).collect::<Vec<_>>();
assert_eq!(v[0].clone().into_owned(), b"line 1\nline 2");
}
_ => (),
}
}
/// Regression test for https://github.com/tafia/quick-xml/issues/360
#[test]
fn issue360() {
let (tx, rx) = mpsc::channel::<Event>();
std::thread::spawn(move || {
let mut r = Reader::from_str("<tag1 attr1='line 1\nline 2'></tag1>");
loop {
let event = r.read_event().unwrap();
if event == Event::Eof {
tx.send(event).unwrap();
break;
} else {
tx.send(event).unwrap();
}
}
});
for event in rx.iter() {
println!("{:?}", event);
}
}
/// 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);
}
}