questions: add sync convert test
This commit is contained in:
parent
8e87e5e17b
commit
ff6af8389d
@ -157,6 +157,42 @@ pub mod convert {
|
|||||||
Box::new(iter)
|
Box::new(iter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::questions::test::convert_common::sample_batch;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use insta::assert_yaml_snapshot;
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_convert() {
|
||||||
|
let mut source = iter::once((
|
||||||
|
String::from("test.json"),
|
||||||
|
Ok::<SourceQuestionsBatch, serde_json::Error>(sample_batch()),
|
||||||
|
));
|
||||||
|
let converted: Vec<_> = source.convert().collect();
|
||||||
|
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")]
|
#[cfg(feature = "convert")]
|
||||||
pub use convert::QuestionsConverter;
|
pub use convert::QuestionsConverter;
|
||||||
@ -222,6 +258,33 @@ mod test {
|
|||||||
use insta::assert_yaml_snapshot;
|
use insta::assert_yaml_snapshot;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
#[cfg(any(feature = "convert", feature = "convert_async"))]
|
||||||
|
pub mod convert_common {
|
||||||
|
use crate::source::{SourceQuestion, SourceQuestionsBatch};
|
||||||
|
|
||||||
|
pub fn sample_batch() -> SourceQuestionsBatch {
|
||||||
|
SourceQuestionsBatch {
|
||||||
|
description: "Тестовый".into(),
|
||||||
|
date: "00-000-2000".into(),
|
||||||
|
questions: vec![
|
||||||
|
SourceQuestion {
|
||||||
|
id: "Вопрос 1".into(),
|
||||||
|
description: "Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2".into(),
|
||||||
|
answer: "42".into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
SourceQuestion {
|
||||||
|
id: "Вопрос 2".into(),
|
||||||
|
description: "Зимой и летом одним цветом".into(),
|
||||||
|
answer: "ёлка".into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sample_question() -> Question {
|
pub fn sample_question() -> Question {
|
||||||
Question {
|
Question {
|
||||||
id: "Вопрос 1".into(),
|
id: "Вопрос 1".into(),
|
||||||
|
Loading…
Reference in New Issue
Block a user