Repository: ruma/ruma
Pull request #50 (2020-06-13 11:00:20)

Add back ruma-events/tests/stripped.rs by updating existing file


Patch:
diff --git a/ruma-api-macros/src/lib.rs b/ruma-api-macros/src/lib.rs
index b8e39bde..cad8e4a9 100644
--- a/ruma-api-macros/src/lib.rs
+++ b/ruma-api-macros/src/lib.rs
@@ -6,6 +6,9 @@
 //! `ruma_api!` macro is only documented in ruma-api, not here.
 
 #![allow(clippy::cognitive_complexity)]
+// Remove this once https://github.com/rust-lang/rust/issues/54883 becomes stable
+#![allow(clippy::unnested_or_patterns)]
+#![allow(clippy::unknown_clippy_lints)]
 #![recursion_limit = "256"]
 
 extern crate proc_macro;
diff --git a/ruma-client-api/src/r0/membership/get_member_events.rs b/ruma-client-api/src/r0/membership/get_member_events.rs
index 4ca6686c..b23fa277 100644
--- a/ruma-client-api/src/r0/membership/get_member_events.rs
+++ b/ruma-client-api/src/r0/membership/get_member_events.rs
@@ -64,3 +64,39 @@ pub enum MembershipEventFilter {
     /// The user has been banned.
     Ban,
 }
+
+#[cfg(test)]
+mod tests {
+    use std::convert::TryInto;
+
+    use matches::assert_matches;
+
+    use super::{MembershipEventFilter, Request};
+
+    #[test]
+    fn deserialization() {
+        let uri = http::Uri::builder()
+            .scheme("https")
+            .authority("example.org")
+            .path_and_query(
+                "/_matrix/client/r0/rooms/!dummy%3Aexample.org/members\
+                 ?not_membership=leave\
+                 &at=1026",
+            )
+            .build()
+            .unwrap();
+
+        let req: Result<Request, _> =
+            http::Request::builder().uri(uri).body(Vec::<u8>::new()).unwrap().try_into();
+
+        assert_matches!(
+            req,
+            Ok(Request {
+                room_id,
+                at: Some(at),
+                membership: None,
+                not_membership: Some(MembershipEventFilter::Leave),
+            }) if room_id == "!dummy:example.org" && at == "1026"
+        );
+    }
+}
diff --git a/ruma-client-api/src/r0/message/create_message_event.rs b/ruma-client-api/src/r0/message/create_message_event.rs
index 2a7a31b5..d223bc65 100644
--- a/ruma-client-api/src/r0/message/create_message_event.rs
+++ b/ruma-client-api/src/r0/message/create_message_event.rs
@@ -1,4 +1,4 @@
-//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid)
+//! [PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid)
 
 use ruma_api::ruma_api;
 use ruma_events::EventType;
@@ -41,8 +41,6 @@ ruma_api! {
 
     response {
         /// A unique identifier for the event.
-        // This is not declared required in r0.6.0, but that was a bug that has now been fixed:
-        // https://github.com/matrix-org/matrix-doc/pull/2525
         pub event_id: EventId,
     }
 
diff --git a/ruma-client-api/src/r0/state/create_state_event_for_empty_key.rs b/ruma-client-api/src/r0/state/create_state_event_for_empty_key.rs
index 1fe4083a..e1cf1e87 100644
--- a/ruma-client-api/src/r0/state/create_state_event_for_empty_key.rs
+++ b/ruma-client-api/src/r0/state/create_state_event_for_empty_key.rs
@@ -1,4 +1,4 @@
-//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-state-eventtype)
+//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-state-eventtype)
 
 use ruma_api::ruma_api;
 use ruma_events::EventType;
@@ -33,8 +33,6 @@ ruma_api! {
 
     response {
         /// A unique identifier for the event.
-        // This is not declared required in r0.6.0, but that was a bug that has now been fixed:
-        // https://github.com/matrix-org/matrix-doc/pull/2525
         pub event_id: EventId,
     }
 
diff --git a/ruma-client-api/src/r0/state/create_state_event_for_key.rs b/ruma-client-api/src/r0/state/create_state_event_for_key.rs
index 6f546666..e6c96883 100644
--- a/ruma-client-api/src/r0/state/create_state_event_for_key.rs
+++ b/ruma-client-api/src/r0/state/create_state_event_for_key.rs
@@ -1,4 +1,4 @@
-//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
+//! [PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}](https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey)
 
 use ruma_api::ruma_api;
 use ruma_events::EventType;
@@ -37,8 +37,6 @@ ruma_api! {
 
     response {
         /// A unique identifier for the event.
-        // This is not declared required in r0.6.0, but that was a bug that has now been fixed:
-        // https://github.com/matrix-org/matrix-doc/pull/2525
         pub event_id: EventId,
     }
 
diff --git a/ruma-events-macros/src/lib.rs b/ruma-events-macros/src/lib.rs
index d07d5830..84b4a5e1 100644
--- a/ruma-events-macros/src/lib.rs
+++ b/ruma-events-macros/src/lib.rs
@@ -2,6 +2,7 @@
 //! [ruma-events](https://github.com/ruma/ruma-events) events.
 //!
 //! See the documentation for the individual macros for usage details.
+
 #![deny(missing_copy_implementations, missing_debug_implementations, missing_docs)]
 
 extern crate proc_macro;
diff --git a/ruma-events/src/lib.rs b/ruma-events/src/lib.rs
index 93a71b0f..02e7ce13 100644
--- a/ruma-events/src/lib.rs
+++ b/ruma-events/src/lib.rs
@@ -113,6 +113,9 @@
 #![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
 // Since we support Rust 1.36.0, we can't apply this suggestion yet
 #![allow(clippy::use_self)]
+// Remove this once https://github.com/rust-lang/rust/issues/54883 becomes stable
+#![allow(clippy::unnested_or_patterns)]
+#![allow(clippy::unknown_clippy_lints)]
 
 use std::fmt::Debug;
 


Test patch:
diff --git a/ruma-events/tests/stripped.rs.bk b/ruma-events/tests/stripped.rs
similarity index 66%
rename from ruma-events/tests/stripped.rs.bk
rename to ruma-events/tests/stripped.rs
index 389eb05b..353bb1b9 100644
--- a/ruma-events/tests/stripped.rs.bk
+++ b/ruma-events/tests/stripped.rs
@@ -3,24 +3,21 @@ use std::convert::TryFrom;
 use js_int::UInt;
 use ruma_events::{
     room::{join_rules::JoinRule, topic::TopicEventContent},
-    AnyStrippedStateEvent, EventJson, EventType,
+    AnyStateEventContent, AnyStrippedStateEventStub,
 };
 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 {
+    let event = AnyStrippedStateEventStub {
+        content: AnyStateEventContent::RoomTopic(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"
@@ -78,47 +75,30 @@ fn deserialize_stripped_state_events() {
         }
     });
 
-    match from_json_value::<EventJson<_>>(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);
+    let event = from_json_value::<AnyStrippedStateEventStub>(name_event).unwrap();
+    match event.content {
+        AnyStateEventContent::RoomName(content) => {
+            assert_eq!(content.name(), Some("Ruma"));
             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::<EventJson<StrippedRoomName>>(name_event)
-        .unwrap()
-        .deserialize()
-        .is_ok());
-
-    match from_json_value::<EventJson<_>>(join_rules_event)
-        .unwrap()
-        .deserialize()
-        .unwrap()
-    {
-        AnyStrippedStateEvent::RoomJoinRules(event) => {
-            assert_eq!(event.content.join_rule, JoinRule::Public);
-            assert_eq!(event.event_type, EventType::RoomJoinRules);
+    let event = from_json_value::<AnyStrippedStateEventStub>(join_rules_event).unwrap();
+    match event.content {
+        AnyStateEventContent::RoomJoinRules(content) => {
+            assert_eq!(content.join_rule, JoinRule::Public);
             assert_eq!(event.state_key, "");
             assert_eq!(event.sender.to_string(), "@example:localhost");
         }
         _ => unreachable!(),
-    };
+    }
 
-    match from_json_value::<EventJson<_>>(avatar_event)
-        .unwrap()
-        .deserialize()
-        .unwrap()
-    {
-        AnyStrippedStateEvent::RoomAvatar(event) => {
-            let image_info = event.content.info.unwrap();
+    let event = from_json_value::<AnyStrippedStateEventStub>(avatar_event).unwrap();
+    match event.content {
+        AnyStateEventContent::RoomAvatar(content) => {
+            let image_info = 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());
@@ -128,11 +108,10 @@ fn deserialize_stripped_state_events() {
                 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!(content.url, "https://example.com/image.jpg");
             assert_eq!(event.state_key, "");
             assert_eq!(event.sender.to_string(), "@example:localhost");
         }
         _ => unreachable!(),
-    };
+    }
 }