Skip to content

Commit 9df6f20

Browse files
committed
Add test for async
1 parent caa423c commit 9df6f20

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,7 @@ required-features = ["serialize"]
136136
[[test]]
137137
name = "serde-migrated"
138138
required-features = ["serialize"]
139+
140+
[[test]]
141+
name = "async_test"
142+
required-features = ["async"]

tests/async_test.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::path::PathBuf;
2+
3+
use quick_xml::events::Event::*;
4+
use quick_xml::Reader;
5+
6+
#[tokio::test]
7+
async fn test_sample() {
8+
let src: &[u8] = include_bytes!("documents/sample_rss.xml");
9+
let mut reader = Reader::from_async_reader(src);
10+
let mut buf = Vec::new();
11+
let mut count = 0;
12+
loop {
13+
match reader.read_event_into_async(&mut buf).await.unwrap() {
14+
Start(_) => count += 1,
15+
Decl(e) => println!("{:?}", e.version()),
16+
Eof => break,
17+
_ => (),
18+
}
19+
buf.clear();
20+
}
21+
println!("{}", count);
22+
}
23+
24+
#[cfg(feature = "async-fs")]
25+
#[tokio::test]
26+
async fn test_read_file() {
27+
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
28+
let mut reader = Reader::from_file_async(path.join("tests/documents/sample_rss.xml"))
29+
.await
30+
.unwrap();
31+
let mut buf = Vec::new();
32+
let mut count = 0;
33+
loop {
34+
match reader.read_event_into_async(&mut buf).await.unwrap() {
35+
Start(_) => count += 1,
36+
Decl(e) => println!("{:?}", e.version()),
37+
Eof => break,
38+
_ => (),
39+
}
40+
buf.clear();
41+
}
42+
println!("{}", count);
43+
}

0 commit comments

Comments
 (0)