diff --git a/lib/src/source.rs b/lib/src/source.rs index a996e04..f5bbbde 100644 --- a/lib/src/source.rs +++ b/lib/src/source.rs @@ -358,3 +358,81 @@ pub mod reader_async { } #[cfg(any(feature = "convert_async", feature = "source_async"))] pub use reader_async::{ReadSourceQuestionsBatchesAsync, SourceQuestionsZipReaderAsync}; + +#[cfg(test)] +mod test { + use super::*; + use insta::assert_yaml_snapshot; + use serde_json::json; + + #[test] + fn test_batch_ser() { + let batch = 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() + }; + + assert_yaml_snapshot!(batch, @r#" + --- + description: Тестовый + date: 00-000-2000 + questions: + - id: Вопрос 1 + description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 + answer: "42" + - id: Вопрос 2 + description: Зимой и летом одним цветом + answer: ёлка + + "#); + } + #[test] + fn test_batch_de() { + let batch_from_json: Result = serde_json::from_value(json!({ + "Чемпионат": "Тестовый", + "Дата": "00-000-2000", + "Вопросы": [ + { + "id": "Вопрос 1", + "Вопрос": "Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2", + "Ответ": "42", + }, + { + "id": "Вопрос 2", + "Вопрос": "Зимой и летом одним цветом", + "Ответ": "ёлка", + }, + ] + })); + assert!(batch_from_json.is_ok()); + + assert_yaml_snapshot!(batch_from_json.unwrap(), @r#" + --- + description: Тестовый + date: 00-000-2000 + questions: + - id: Вопрос 1 + description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 + answer: "42" + - id: Вопрос 2 + description: Зимой и летом одним цветом + answer: ёлка + + "#); + } +}