From d380f2696f45c766375b6352ca985735329740cb Mon Sep 17 00:00:00 2001 From: P0lunin Date: Sun, 15 Sep 2019 14:40:46 +0300 Subject: [PATCH] added docs and tests --- src/core/types/animation.rs | 52 +++++++++++++++++++++++++++++++++++- src/core/types/photo_size.rs | 25 +++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/core/types/animation.rs b/src/core/types/animation.rs index 09fccf40..4a60e4c5 100644 --- a/src/core/types/animation.rs +++ b/src/core/types/animation.rs @@ -1,13 +1,63 @@ use crate::core::types::PhotoSize; #[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +/// This object represents an animation file (GIF or H.264/MPEG-4 AVC video +/// without sound). pub struct Animation { + /// Identifier for this file pub file_id: String, + /// Video width as defined by sender pub width: u32, + /// Video height as defined by sender pub height: u32, + /// Duration of the video in seconds as defined by sender pub duration: u32, - pub thumb: PhotoSize, + /// Optional. Animation thumbnail as defined by sender + pub thumb: Option, + /// Optional. Original animation filename as defined by sender pub file_name: Option, + /// Optional. MIME type of the file as defined by sender pub mime_type: Option, + /// Optional. File size pub file_size: Option } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize() { + let json = r#"{ + "file_id":"id", + "width":320, + "height":320, + "duration":59, + "thumb":{ + "file_id":"id", + "width":320, + "height":320, + "file_size":3452 + }, + "file_name":"some", + "mime_type":"gif", + "file_size":6500}"#; + let expected = Animation { + file_id: "id".to_string(), + width: 320, + height: 320, + duration: 59, + thumb: Some(PhotoSize { + file_id: "id".to_string(), + width: 320, + height: 320, + file_size: Some(3452) + }), + file_name: Some("some".to_string()), + mime_type: Some("gif".to_string()), + file_size: Some(6500) + }; + let actual = serde_json::from_str::(json).unwrap(); + assert_eq!(actual, expected) + } +} diff --git a/src/core/types/photo_size.rs b/src/core/types/photo_size.rs index 9f8d6cf3..8df34596 100644 --- a/src/core/types/photo_size.rs +++ b/src/core/types/photo_size.rs @@ -1,7 +1,32 @@ #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] +/// This object represents one size of a photo or a [`Document`] / +/// [`Sticker`] thumbnail. pub struct PhotoSize { + /// Identifier for this file pub file_id: String, + /// Photo width pub width: i32, + /// Photo height pub height: i32, + /// Optional. File size pub file_size: Option, } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize() { + let json = r#"{"file_id":"id","width":320,"height":320, + "file_size":3452}"#; + let expected = PhotoSize { + file_id: "id".to_string(), + width: 320, + height: 320, + file_size: Some(3452) + }; + let actual = serde_json::from_str::(json).unwrap(); + assert_eq!(actual, expected); + } +}