add async feature #1

Merged
b4tman merged 62 commits from async into master 2023-08-18 06:29:46 +00:00
Showing only changes of commit 270af2c373 - Show all commits

View File

@ -248,6 +248,48 @@ pub mod convert_async {
})
}
}
#[cfg(test)]
mod test {
use crate::questions::test::convert_common::sample_batch;
use super::*;
use futures_util::{pin_mut, StreamExt};
use insta::assert_yaml_snapshot;
#[tokio::test]
async fn test_convert_stream() {
let source = futures::stream::once(async {
(
String::from("test.json"),
Ok::<SourceQuestionsBatch, serde_json::Error>(sample_batch()),
)
});
pin_mut!(source);
let converter = QuestionsConverterAsync::from(source);
let converter = converter.convert();
let converted: Vec<_> = converter.collect().await;
assert_yaml_snapshot!(converted, @r#"
---
- id: Вопрос 1
description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2
answer: "42"
batch_info:
filename: test.json
description: Тестовый
date: 00-000-2000
- id: Вопрос 2
description: Зимой и летом одним цветом
answer: ёлка
batch_info:
filename: test.json
description: Тестовый
date: 00-000-2000
"#);
}
}
}
#[cfg(feature = "convert_async")]
pub use convert_async::QuestionsConverterAsync;