From 9478050792ca8922bb02d6b57ec31dbdd55c7b13 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 9 Jun 2020 17:01:08 +0200 Subject: [PATCH] Remove stripped module --- src/lib.rs | 1 - src/stripped.rs | 143 +------------------------------------------ tests/stripped.rs.bk | 138 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 143 deletions(-) create mode 100644 tests/stripped.rs.bk diff --git a/src/lib.rs b/src/lib.rs index da7912e8..da267f61 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -155,7 +155,6 @@ pub mod room; pub mod room_key; pub mod room_key_request; pub mod sticker; -// pub mod stripped; pub mod tag; pub mod typing; diff --git a/src/stripped.rs b/src/stripped.rs index 2555aec5..d331060d 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -307,145 +307,4 @@ mod raw { } #[cfg(test)] -mod tests { - use std::convert::TryFrom; - - use js_int::UInt; - use ruma_identifiers::UserId; - use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; - - use super::{AnyStrippedStateEvent, StrippedRoomName, StrippedRoomTopic}; - use crate::{ - room::{join_rules::JoinRule, topic::TopicEventContent}, - EventJson, EventType, - }; - - #[test] - fn serialize_stripped_state_event() { - let content = StrippedRoomTopic { - content: TopicEventContent { - topic: "Testing room".to_string(), - }, - state_key: "".to_string(), - event_type: EventType::RoomTopic, - sender: UserId::try_from("@example:localhost").unwrap(), - }; - - let event = AnyStrippedStateEvent::RoomTopic(content); - - let json_data = json!({ - "content": { - "topic": "Testing room" - }, - "type": "m.room.topic", - "state_key": "", - "sender": "@example:localhost" - }); - - assert_eq!(to_json_value(&event).unwrap(), json_data); - } - - #[test] - fn deserialize_stripped_state_events() { - let name_event = json!({ - "type": "m.room.name", - "state_key": "", - "sender": "@example:localhost", - "content": { "name": "Ruma" } - }); - - let join_rules_event = json!({ - "type": "m.room.join_rules", - "state_key": "", - "sender": "@example:localhost", - "content": { "join_rule": "public" } - }); - - let avatar_event = json!({ - "type": "m.room.avatar", - "state_key": "", - "sender": "@example:localhost", - "content": { - "info": { - "h": 128, - "w": 128, - "mimetype": "image/jpeg", - "size": 1024, - "thumbnail_info": { - "h": 16, - "w": 16, - "mimetype": "image/jpeg", - "size": 32 - }, - "thumbnail_url": "https://example.com/image-thumbnail.jpg" - }, - "thumbnail_info": { - "h": 16, - "w": 16, - "mimetype": "image/jpeg", - "size": 32 - }, - "thumbnail_url": "https://example.com/image-thumbnail.jpg", - "url": "https://example.com/image.jpg" - } - }); - - match from_json_value::>(name_event.clone()) - .unwrap() - .deserialize() - .unwrap() - { - AnyStrippedStateEvent::RoomName(event) => { - assert_eq!(event.content.name, Some("Ruma".to_string())); - assert_eq!(event.event_type, EventType::RoomName); - assert_eq!(event.state_key, ""); - assert_eq!(event.sender.to_string(), "@example:localhost"); - } - _ => unreachable!(), - }; - - // Ensure `StrippedStateContent` can be parsed, not just `StrippedState`. - assert!(from_json_value::>(name_event) - .unwrap() - .deserialize() - .is_ok()); - - match from_json_value::>(join_rules_event) - .unwrap() - .deserialize() - .unwrap() - { - AnyStrippedStateEvent::RoomJoinRules(event) => { - assert_eq!(event.content.join_rule, JoinRule::Public); - assert_eq!(event.event_type, EventType::RoomJoinRules); - assert_eq!(event.state_key, ""); - assert_eq!(event.sender.to_string(), "@example:localhost"); - } - _ => unreachable!(), - }; - - match from_json_value::>(avatar_event) - .unwrap() - .deserialize() - .unwrap() - { - AnyStrippedStateEvent::RoomAvatar(event) => { - let image_info = event.content.info.unwrap(); - - assert_eq!(image_info.height.unwrap(), UInt::try_from(128).unwrap()); - assert_eq!(image_info.width.unwrap(), UInt::try_from(128).unwrap()); - assert_eq!(image_info.mimetype.unwrap(), "image/jpeg"); - assert_eq!(image_info.size.unwrap(), UInt::try_from(1024).unwrap()); - assert_eq!( - image_info.thumbnail_info.unwrap().size.unwrap(), - UInt::try_from(32).unwrap() - ); - assert_eq!(event.content.url, "https://example.com/image.jpg"); - assert_eq!(event.event_type, EventType::RoomAvatar); - assert_eq!(event.state_key, ""); - assert_eq!(event.sender.to_string(), "@example:localhost"); - } - _ => unreachable!(), - }; - } -} +mod tests {} diff --git a/tests/stripped.rs.bk b/tests/stripped.rs.bk new file mode 100644 index 00000000..389eb05b --- /dev/null +++ b/tests/stripped.rs.bk @@ -0,0 +1,138 @@ +use std::convert::TryFrom; + +use js_int::UInt; +use ruma_events::{ + room::{join_rules::JoinRule, topic::TopicEventContent}, + AnyStrippedStateEvent, EventJson, EventType, +}; +use ruma_identifiers::UserId; +use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; + +#[test] +fn serialize_stripped_state_event() { + let content = StrippedRoomTopic { + content: TopicEventContent { + topic: "Testing room".to_string(), + }, + state_key: "".to_string(), + event_type: EventType::RoomTopic, + sender: UserId::try_from("@example:localhost").unwrap(), + }; + + let event = AnyStrippedStateEvent::RoomTopic(content); + + let json_data = json!({ + "content": { + "topic": "Testing room" + }, + "type": "m.room.topic", + "state_key": "", + "sender": "@example:localhost" + }); + + assert_eq!(to_json_value(&event).unwrap(), json_data); +} + +#[test] +fn deserialize_stripped_state_events() { + let name_event = json!({ + "type": "m.room.name", + "state_key": "", + "sender": "@example:localhost", + "content": { "name": "Ruma" } + }); + + let join_rules_event = json!({ + "type": "m.room.join_rules", + "state_key": "", + "sender": "@example:localhost", + "content": { "join_rule": "public" } + }); + + let avatar_event = json!({ + "type": "m.room.avatar", + "state_key": "", + "sender": "@example:localhost", + "content": { + "info": { + "h": 128, + "w": 128, + "mimetype": "image/jpeg", + "size": 1024, + "thumbnail_info": { + "h": 16, + "w": 16, + "mimetype": "image/jpeg", + "size": 32 + }, + "thumbnail_url": "https://example.com/image-thumbnail.jpg" + }, + "thumbnail_info": { + "h": 16, + "w": 16, + "mimetype": "image/jpeg", + "size": 32 + }, + "thumbnail_url": "https://example.com/image-thumbnail.jpg", + "url": "https://example.com/image.jpg" + } + }); + + match from_json_value::>(name_event.clone()) + .unwrap() + .deserialize() + .unwrap() + { + AnyStrippedStateEvent::RoomName(event) => { + assert_eq!(event.content.name, Some("Ruma".to_string())); + assert_eq!(event.event_type, EventType::RoomName); + assert_eq!(event.state_key, ""); + assert_eq!(event.sender.to_string(), "@example:localhost"); + } + _ => unreachable!(), + }; + + // Ensure `StrippedStateContent` can be parsed, not just `StrippedState`. + assert!(from_json_value::>(name_event) + .unwrap() + .deserialize() + .is_ok()); + + match from_json_value::>(join_rules_event) + .unwrap() + .deserialize() + .unwrap() + { + AnyStrippedStateEvent::RoomJoinRules(event) => { + assert_eq!(event.content.join_rule, JoinRule::Public); + assert_eq!(event.event_type, EventType::RoomJoinRules); + assert_eq!(event.state_key, ""); + assert_eq!(event.sender.to_string(), "@example:localhost"); + } + _ => unreachable!(), + }; + + match from_json_value::>(avatar_event) + .unwrap() + .deserialize() + .unwrap() + { + AnyStrippedStateEvent::RoomAvatar(event) => { + let image_info = event.content.info.unwrap(); + + assert_eq!(image_info.height.unwrap(), UInt::try_from(128).unwrap()); + assert_eq!(image_info.width.unwrap(), UInt::try_from(128).unwrap()); + assert_eq!(image_info.mimetype.unwrap(), "image/jpeg"); + assert_eq!(image_info.size.unwrap(), UInt::try_from(1024).unwrap()); + assert_eq!( + image_info.thumbnail_info.unwrap().size.unwrap(), + UInt::try_from(32).unwrap() + ); + assert_eq!(event.content.url, "https://example.com/image.jpg"); + assert_eq!(event.event_type, EventType::RoomAvatar); + assert_eq!(event.state_key, ""); + assert_eq!(event.sender.to_string(), "@example:localhost"); + } + _ => unreachable!(), + }; +}