diff --git a/Cargo.toml b/Cargo.toml index 02ba05d4..95d9d3f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,3 +129,7 @@ required-features = ["serialize"] [[test]] name = "serde-migrated" required-features = ["serialize"] + +[[test]] +name = "async_test" +required-features = ["async"] diff --git a/tests/async_test.rs b/tests/async_test.rs new file mode 100644 index 00000000..031bb145 --- /dev/null +++ b/tests/async_test.rs @@ -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); +}