Skip to content

Commit

Permalink
feat: add Notes struct and Note type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
indiv0 committed Dec 17, 2016
1 parent c5876c7 commit 8b9e53f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/model.in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub struct Pod {
//pub error: Option<Error>,
pub sounds: Option<Sounds>,
pub definitions: Option<Definitions>,
pub notes: Option<Notes>,
}

/// A series of `State` attributes.
Expand Down Expand Up @@ -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<Note>,
}

/// 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 {
Expand Down
6 changes: 6 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod tests {
Img,
Infos,
LanguageMsg,
Notes,
Plaintext,
Pod,
QueryResult,
Expand Down Expand Up @@ -69,6 +70,11 @@ mod tests {
from_str::<QueryResult>(&read_sample_data_from_path("tests/sample-data/query_result_6.xml")).unwrap();
}

#[test]
fn test_notes_deserializer() {
from_str::<Notes>(&read_sample_data_from_path("tests/sample-data/notes.xml")).unwrap();
}

#[test]
fn test_languagemsg_deserializer() {
from_str::<LanguageMsg>(&read_sample_data_from_path("tests/sample-data/languagemsg.xml")).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions tests/sample-data/notes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<notes count='1'>
<note>QR Code is a registered trademark of Denso Wave Inc.</note>
</notes>

0 comments on commit 8b9e53f

Please sign in to comment.