From 8b9e53f8309fafc63efd564e2b363ac151468e46 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 09:14:10 -0500 Subject: [PATCH] feat: add `Notes` struct and `Note` type Add `Notes` struct and `None` type to represent the possible notes that W|A might return regarding a query. Add test for `Notes` struct deserialization. --- src/model.in.rs | 13 +++++++++++++ src/model.rs | 6 ++++++ tests/sample-data/notes.xml | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 tests/sample-data/notes.xml diff --git a/src/model.in.rs b/src/model.in.rs index 29a2238..11c115e 100644 --- a/src/model.in.rs +++ b/src/model.in.rs @@ -251,6 +251,7 @@ pub struct Pod { //pub error: Option, pub sounds: Option, pub definitions: Option, + pub notes: Option, } /// A series of `State` attributes. @@ -336,6 +337,18 @@ pub struct Definition { pub desc: String, } +/// A series of `Note` attributes. +#[derive(Clone, Debug, Deserialize, Eq, PartialEq)] +pub struct Notes { + // Attributes + pub count: u32, + + pub note: Vec, +} + +/// A note made by Wolfram|Alpha regarding a query. +pub type Note = String; + /// A subelement of `Pod`. #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] pub struct Subpod { diff --git a/src/model.rs b/src/model.rs index 1326fd2..8b43ca9 100644 --- a/src/model.rs +++ b/src/model.rs @@ -38,6 +38,7 @@ mod tests { Img, Infos, LanguageMsg, + Notes, Plaintext, Pod, QueryResult, @@ -69,6 +70,11 @@ mod tests { from_str::(&read_sample_data_from_path("tests/sample-data/query_result_6.xml")).unwrap(); } + #[test] + fn test_notes_deserializer() { + from_str::(&read_sample_data_from_path("tests/sample-data/notes.xml")).unwrap(); + } + #[test] fn test_languagemsg_deserializer() { from_str::(&read_sample_data_from_path("tests/sample-data/languagemsg.xml")).unwrap(); diff --git a/tests/sample-data/notes.xml b/tests/sample-data/notes.xml new file mode 100644 index 0000000..27058dc --- /dev/null +++ b/tests/sample-data/notes.xml @@ -0,0 +1,3 @@ + + QR Code is a registered trademark of Denso Wave Inc. +