LibraryItem deserializing test refactored
@@ -7,8 +7,22 @@ use serde_test::{assert_tokens, Token};
#[test]
fn deserialize_library_item() {
- let library_item = [
- Token::Seq { len: Some(1) },
+ assert_tokens(
+ &LibraryItem {
+ id: "id1".to_owned(),
+ name: "name".to_owned(),
+ type_: "type".to_owned(),
+ poster: Some("poster".to_owned()),
+ poster_shape: PosterShape::Square,
+ removed: true,
+ temp: true,
+ ctime: Some(Utc.ymd(2020, 1, 1).and_hms_milli(0, 0, 0, 0)),
+ mtime: Utc.ymd(2020, 1, 1).and_hms_milli(0, 0, 0, 0),
+ state: LibraryItemState::default(),
+ behavior_hints: LibraryItemBehaviorHints::default(),
+ },
+ &[
+ vec![
Token::Struct {
name: "LibraryItem",
len: 11,
@@ -37,27 +51,12 @@ fn deserialize_library_item() {
Token::Str("_mtime"),
Token::Str("2020-01-01T00:00:00Z"),
Token::Str("state"),
+ ],
+ LibraryItemState::default_token(),
+ vec![Token::Str("behaviorHints")],
+ LibraryItemBehaviorHints::default_token(),
+ vec![Token::StructEnd],
]
- .iter()
- .chain(LibraryItemState::default_token().iter())
- .chain([Token::Str("behaviorHints")].iter())
- .chain(LibraryItemBehaviorHints::default_token().iter())
- .chain([Token::StructEnd, Token::SeqEnd].iter())
- .cloned()
- .collect::<Vec<Token>>();
- let mut vec = Vec::new();
- vec.push(LibraryItem {
- id: "id1".to_owned(),
- name: "name".to_owned(),
- type_: "type".to_owned(),
- poster: Some("poster".to_owned()),
- poster_shape: PosterShape::Square,
- removed: true,
- temp: true,
- ctime: Some(Utc.ymd(2020, 1, 1).and_hms_milli(0, 0, 0, 0)),
- mtime: Utc.ymd(2020, 1, 1).and_hms_milli(0, 0, 0, 0),
- state: LibraryItemState::default(),
- behavior_hints: LibraryItemBehaviorHints::default(),
- });
- assert_tokens(&vec, &library_item);
+ .concat(),
+ );
}
