-
Notifications
You must be signed in to change notification settings - Fork 223
/
async_test.rs
43 lines (40 loc) · 1.14 KB
/
async_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
}