Skip to content

Commit

Permalink
Add test for async
Browse files Browse the repository at this point in the history
  • Loading branch information
999eagle committed Jul 14, 2022
1 parent 543890d commit 6b35382
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ required-features = ["serialize"]
[[test]]
name = "serde-migrated"
required-features = ["serialize"]

[[test]]
name = "async_test"
required-features = ["async"]
43 changes: 43 additions & 0 deletions tests/async_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::path::PathBuf;

use quick_xml::events::Event::*;
use quick_xml::Reader;

#[tokio::test]
async fn test_sample() {
let src: &[u8] = include_bytes!("documents/sample_rss.xml");
let mut reader = Reader::from_async_reader(src);
let mut buf = Vec::new();
let mut count = 0;
loop {
match reader.read_event_into_async(&mut buf).await.unwrap() {
Start(_) => count += 1,
Decl(e) => println!("{:?}", e.version()),
Eof => break,
_ => (),
}
buf.clear();
}
println!("{}", count);
}

#[cfg(feature = "async-fs")]
#[tokio::test]
async fn test_read_file() {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let mut reader = Reader::from_file_async(path.join("tests/documents/sample_rss.xml"))
.await
.unwrap();
let mut buf = Vec::new();
let mut count = 0;
loop {
match reader.read_event_into_async(&mut buf).await.unwrap() {
Start(_) => count += 1,
Decl(e) => println!("{:?}", e.version()),
Eof => break,
_ => (),
}
buf.clear();
}
println!("{}", count);
}

0 comments on commit 6b35382

Please sign in to comment.