use crate::StreamElement;
use super::*;
fn check_stream(stream_text: &str, expected: &[&str]) {
let mut parser = StreamParser::new();
let mut current: usize = 0;
let mut ended: bool = false;
let mut elements = parser.elements(&stream_text.as_bytes());
while let Some(element) = elements.next() {
assert!(!ended);
match element.unwrap() {
StreamElement::Element(document) => {
assert_eq!(document.to_string(), expected[current]);
current += 1;
}
StreamElement::End => {
assert!(!ended);
ended = true;
assert_eq!(current, expected.len());
}
}
}
assert!(ended);
}
#[test]
fn stream_elements() {
check_stream(
"<stream:stream xmlns:stream='http://etherx.jabber.org/streams'\
version='1.0'\
from='example.com'\
to='user@example.com'>\
<message to='user@example.com'>\
<body>Hello!</body>\
</message>\
</stream:stream>",
&[
"<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\" from=\"example.com\" to=\"user@example.com\"/>",
"<message to=\"user@example.com\"><body>Hello!</body></message>",
],
);
}