From f0a5a4345574a1faf6d729a3c624afca93a030ba Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Wed, 5 Aug 2020 16:00:27 -0400 Subject: [PATCH] Move lifetime tests into their own file --- ruma-api/tests/outgoing.rs | 28 ------ ruma-api/tests/ruma_api_lifetime.rs | 139 ++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 ruma-api/tests/ruma_api_lifetime.rs diff --git a/ruma-api/tests/outgoing.rs b/ruma-api/tests/outgoing.rs index d467f78c..39be4170 100644 --- a/ruma-api/tests/outgoing.rs +++ b/ruma-api/tests/outgoing.rs @@ -26,34 +26,6 @@ pub struct IncomingOtherThing { t: Vec, } -use ruma_api::ruma_api; - -ruma_api! { - metadata: { - description: "Does something.", - method: GET, - name: "no_fields", - path: "/_matrix/my/endpoint/:thing", - rate_limited: false, - requires_authentication: false, - } - - request: { - #[ruma_api(query)] - pub abc: &'a str, - #[ruma_api(path)] - pub thing: &'a str, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: &'a str, - } - - response: { - pub body: &'a str, - pub thing: OtherThing<'a>, - pub stuff: &'a [u8], - } -} - #[derive(Outgoing)] #[incoming_no_deserialize] pub struct FakeRequest<'a, T> { diff --git a/ruma-api/tests/ruma_api_lifetime.rs b/ruma-api/tests/ruma_api_lifetime.rs new file mode 100644 index 00000000..37ce053e --- /dev/null +++ b/ruma-api/tests/ruma_api_lifetime.rs @@ -0,0 +1,139 @@ +use ruma_identifiers::{RoomAliasId, RoomId}; + +mod empty_response { + use super::*; + + ruma_api::ruma_api! { + metadata: { + description: "Add an alias to a room.", + method: PUT, + name: "create_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, + } + + request: { + /// The room alias to set. + #[ruma_api(path)] + pub room_alias: &'a RoomAliasId, + + /// The room ID to set. + pub room_id: &'a RoomId, + } + + response: {} + + } +} + +mod nested_types { + use super::*; + + ruma_api::ruma_api! { + metadata: { + description: "Add an alias to a room.", + method: PUT, + name: "create_alias", + path: "/_matrix/client/r0/directory/room/:room_alias", + rate_limited: false, + requires_authentication: true, + } + + request: { + /// The room alias to set. + pub room_alias: &'a [Option<&'a RoomAliasId>], + + /// The room ID to set. + pub room_id: &'b [Option>], + } + + response: {} + + } +} + +mod full_request_response { + #[allow(unused)] + #[derive(Copy, Clone, Debug, serde::Deserialize, serde::Serialize)] + pub struct OtherThing<'t> { + some: &'t str, + t: &'t [u8], + } + + #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] + pub struct IncomingOtherThing { + some: String, + t: Vec, + } + + ruma_api::ruma_api! { + metadata: { + description: "Does something.", + method: GET, + name: "no_fields", + path: "/_matrix/my/endpoint/:thing", + rate_limited: false, + requires_authentication: false, + } + + request: { + #[ruma_api(query)] + pub abc: &'a str, + #[ruma_api(path)] + pub thing: &'a str, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: &'a str, + } + + response: { + #[ruma_api(body)] + pub thing: OtherThing<'a>, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: &'a str, + } + } +} + +mod full_request_response_with_query_map { + #[allow(unused)] + #[derive(Copy, Clone, Debug, serde::Deserialize, serde::Serialize)] + pub struct OtherThing<'t> { + some: &'t str, + t: &'t [u8], + } + + #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] + pub struct IncomingOtherThing { + some: String, + t: Vec, + } + + ruma_api::ruma_api! { + metadata: { + description: "Does something.", + method: GET, + name: "no_fields", + path: "/_matrix/my/endpoint/:thing", + rate_limited: false, + requires_authentication: false, + } + + request: { + #[ruma_api(query_map)] + // pub abc: &'a [(&'a str, &'a str)], + pub abc: &'a [(String, String)], + #[ruma_api(path)] + pub thing: &'a str, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: &'a str, + } + + response: { + #[ruma_api(body)] + pub thing: OtherThing<'a>, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: &'a str, + } + } +}