Skip to content

Commit 5cf2ed4

Browse files
committed
Add tests for Reader::read_event_buffered to ensure that proper events generated for corresponding inputs
failures: reader::test::borrowed::read_event_buffered::cdata reader::test::borrowed::read_event_buffered::comment reader::test::borrowed::read_event_buffered::declaration reader::test::borrowed::read_event_buffered::doctype reader::test::borrowed::read_event_buffered::empty reader::test::borrowed::read_event_buffered::end reader::test::borrowed::read_event_buffered::processing_instruction reader::test::borrowed::read_event_buffered::start reader::test::buffered::read_event_buffered::cdata reader::test::buffered::read_event_buffered::comment reader::test::buffered::read_event_buffered::declaration reader::test::buffered::read_event_buffered::doctype reader::test::buffered::read_event_buffered::empty reader::test::buffered::read_event_buffered::end reader::test::buffered::read_event_buffered::processing_instruction reader::test::buffered::read_event_buffered::start
1 parent e701c4d commit 5cf2ed4

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@
6161
- [#387]: Added a bunch of tests for sequences deserialization
6262
- [#393]: Added more tests for namespace resolver
6363
- [#393]: Added tests for reserved names (started with "xml"i) -- see <https://www.w3.org/TR/xml-names11/#xmlReserved>
64+
- [#363]: Add tests for `Reader::read_event_buffered` to ensure that proper events generated for corresponding inputs
6465

6566
[#8]: https://github.com/Mingun/fast-xml/pull/8
6667
[#9]: https://github.com/Mingun/fast-xml/pull/9
68+
[#363]: https://github.com/tafia/quick-xml/issues/363
6769
[#387]: https://github.com/tafia/quick-xml/pull/387
6870
[#391]: https://github.com/tafia/quick-xml/pull/391
6971
[#393]: https://github.com/tafia/quick-xml/pull/393

src/reader.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,116 @@ mod test {
22442244
}
22452245
}
22462246
}
2247+
2248+
/// Ensures, that no empty `Text` events are generated
2249+
mod read_event_buffered {
2250+
use crate::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Event};
2251+
use crate::reader::Reader;
2252+
use pretty_assertions::assert_eq;
2253+
2254+
#[test]
2255+
fn declaration() {
2256+
let mut reader = Reader::from_str("<?xml ?>");
2257+
2258+
assert_eq!(
2259+
reader.read_event_buffered($buf).unwrap(),
2260+
Event::Decl(BytesDecl::from_start(BytesStart::borrowed(b"xml ", 3)))
2261+
);
2262+
}
2263+
2264+
#[test]
2265+
fn doctype() {
2266+
let mut reader = Reader::from_str("<!DOCTYPE x>");
2267+
2268+
assert_eq!(
2269+
reader.read_event_buffered($buf).unwrap(),
2270+
Event::DocType(BytesText::from_escaped(b"x".as_ref()))
2271+
);
2272+
}
2273+
2274+
#[test]
2275+
fn processing_instruction() {
2276+
let mut reader = Reader::from_str("<?xml-stylesheet?>");
2277+
2278+
assert_eq!(
2279+
reader.read_event_buffered($buf).unwrap(),
2280+
Event::PI(BytesText::from_escaped(b"xml-stylesheet".as_ref()))
2281+
);
2282+
}
2283+
2284+
#[test]
2285+
fn start() {
2286+
let mut reader = Reader::from_str("<tag>");
2287+
2288+
assert_eq!(
2289+
reader.read_event_buffered($buf).unwrap(),
2290+
Event::Start(BytesStart::borrowed_name(b"tag"))
2291+
);
2292+
}
2293+
2294+
#[test]
2295+
fn end() {
2296+
let mut reader = Reader::from_str("</tag>");
2297+
// Because we expect invalid XML, do not check that
2298+
// the end name paired with the start name
2299+
reader.check_end_names(false);
2300+
2301+
assert_eq!(
2302+
reader.read_event_buffered($buf).unwrap(),
2303+
Event::End(BytesEnd::borrowed(b"tag"))
2304+
);
2305+
}
2306+
2307+
#[test]
2308+
fn empty() {
2309+
let mut reader = Reader::from_str("<tag/>");
2310+
2311+
assert_eq!(
2312+
reader.read_event_buffered($buf).unwrap(),
2313+
Event::Empty(BytesStart::borrowed_name(b"tag"))
2314+
);
2315+
}
2316+
2317+
#[test]
2318+
fn text() {
2319+
let mut reader = Reader::from_str("text");
2320+
2321+
assert_eq!(
2322+
reader.read_event_buffered($buf).unwrap(),
2323+
Event::Text(BytesText::from_escaped(b"text".as_ref()))
2324+
);
2325+
}
2326+
2327+
#[test]
2328+
fn cdata() {
2329+
let mut reader = Reader::from_str("<![CDATA[]]>");
2330+
2331+
assert_eq!(
2332+
reader.read_event_buffered($buf).unwrap(),
2333+
Event::CData(BytesCData::from_str(""))
2334+
);
2335+
}
2336+
2337+
#[test]
2338+
fn comment() {
2339+
let mut reader = Reader::from_str("<!---->");
2340+
2341+
assert_eq!(
2342+
reader.read_event_buffered($buf).unwrap(),
2343+
Event::Comment(BytesText::from_escaped(b"".as_ref()))
2344+
);
2345+
}
2346+
2347+
#[test]
2348+
fn eof() {
2349+
let mut reader = Reader::from_str("");
2350+
2351+
assert_eq!(
2352+
reader.read_event_buffered($buf).unwrap(),
2353+
Event::Eof
2354+
);
2355+
}
2356+
}
22472357
};
22482358
}
22492359

0 commit comments

Comments
 (0)