From a1c9a0dcddab3f91b6adf35b9e37da0f1ab87d94 Mon Sep 17 00:00:00 2001 From: Sophie Tauchert Date: Wed, 13 Jul 2022 17:14:19 +0200 Subject: [PATCH] Add test for async --- Cargo.toml | 4 ++++ tests/async_test.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/async_test.rs diff --git a/Cargo.toml b/Cargo.toml index c88d0aaa..46e66ea5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,3 +136,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); +}