Replace assert_matches by assert_matches2
This commit is contained in:
parent
a8670e7fdf
commit
ba5bf8cfce
@ -5,7 +5,7 @@ default-members = ["crates/*"]
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
assert_matches = "1.5.0"
|
assert_matches2 = "0.1.0"
|
||||||
assign = "1.1.1"
|
assign = "1.1.1"
|
||||||
base64 = "0.21.0"
|
base64 = "0.21.0"
|
||||||
criterion = "0.5.0"
|
criterion = "0.5.0"
|
||||||
|
@ -29,5 +29,5 @@ serde = { workspace = true }
|
|||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = { workspace = true }
|
assert_matches2 = { workspace = true }
|
||||||
serde_yaml = "0.9.14"
|
serde_yaml = "0.9.14"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_appservice_api::Registration;
|
use ruma_appservice_api::Registration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -58,9 +58,6 @@ fn config_with_optional_url() {
|
|||||||
aliases: []
|
aliases: []
|
||||||
rooms: []
|
rooms: []
|
||||||
"#;
|
"#;
|
||||||
let url = assert_matches!(
|
assert_matches!(serde_yaml::from_str(registration_config).unwrap(), Registration { url, .. });
|
||||||
serde_yaml::from_str(registration_config).unwrap(),
|
|
||||||
Registration { url, .. } => url
|
|
||||||
);
|
|
||||||
assert_eq!(url, "null");
|
assert_eq!(url, "null");
|
||||||
}
|
}
|
||||||
|
@ -55,4 +55,4 @@ serde_html_form = { workspace = true }
|
|||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = { workspace = true }
|
assert_matches2 = { workspace = true }
|
||||||
|
@ -296,7 +296,7 @@ impl Default for ThirdPartyIdChangesCapability {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use super::Capabilities;
|
use super::Capabilities;
|
||||||
|
@ -537,7 +537,7 @@ mod tests {
|
|||||||
#[cfg(feature = "unstable-msc2967")]
|
#[cfg(feature = "unstable-msc2967")]
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_insufficient_scope() {
|
fn deserialize_insufficient_scope() {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::api::EndpointError;
|
use ruma_common::api::EndpointError;
|
||||||
|
|
||||||
use super::{AuthenticateError, Error, ErrorBody};
|
use super::{AuthenticateError, Error, ErrorBody};
|
||||||
@ -559,14 +559,10 @@ mod tests {
|
|||||||
let error = Error::from_http_response(response);
|
let error = Error::from_http_response(response);
|
||||||
|
|
||||||
assert_eq!(error.status_code, http::StatusCode::UNAUTHORIZED);
|
assert_eq!(error.status_code, http::StatusCode::UNAUTHORIZED);
|
||||||
let (kind, message) =
|
assert_matches!(error.body, ErrorBody::Standard { kind, message });
|
||||||
assert_matches!(error.body, ErrorBody::Standard { kind, message } => (kind, message));
|
|
||||||
assert_eq!(kind, ErrorKind::Forbidden);
|
assert_eq!(kind, ErrorKind::Forbidden);
|
||||||
assert_eq!(message, "Insufficient privilege");
|
assert_eq!(message, "Insufficient privilege");
|
||||||
let scope = assert_matches::assert_matches!(
|
assert_matches!(error.authenticate, Some(AuthenticateError::InsufficientScope { scope }));
|
||||||
error.authenticate,
|
|
||||||
Some(AuthenticateError::InsufficientScope { scope }) => scope
|
|
||||||
);
|
|
||||||
assert_eq!(scope, "something_privileged");
|
assert_eq!(scope, "something_privileged");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,6 @@ can_be_empty!(RoomFilter);
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -421,7 +420,7 @@ mod tests {
|
|||||||
"contains_url": true,
|
"contains_url": true,
|
||||||
});
|
});
|
||||||
|
|
||||||
let filter: RoomEventFilter = assert_matches!(from_json_value(obj), Ok(f) => f);
|
let filter: RoomEventFilter = from_json_value(obj).unwrap();
|
||||||
|
|
||||||
assert_eq!(filter.types, Some(vec!["m.room.message".to_owned()]));
|
assert_eq!(filter.types, Some(vec!["m.room.message".to_owned()]));
|
||||||
assert_eq!(filter.not_types, vec![""; 0]);
|
assert_eq!(filter.not_types, vec![""; 0]);
|
||||||
|
@ -76,7 +76,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_value as from_json_value, json,
|
from_value as from_json_value, json,
|
||||||
value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue},
|
value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue},
|
||||||
|
@ -82,7 +82,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::thirdparty::Medium;
|
use ruma_common::thirdparty::Medium;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
@ -94,10 +94,7 @@ pub mod v3 {
|
|||||||
from_json_value::<InvitationRecipient>(json!({ "user_id": "@carl:example.org" }))
|
from_json_value::<InvitationRecipient>(json!({ "user_id": "@carl:example.org" }))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let user_id = assert_matches!(
|
assert_matches!(incoming, InvitationRecipient::UserId { user_id });
|
||||||
incoming,
|
|
||||||
InvitationRecipient::UserId { user_id } => user_id
|
|
||||||
);
|
|
||||||
assert_eq!(user_id, "@carl:example.org");
|
assert_eq!(user_id, "@carl:example.org");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,10 +108,7 @@ pub mod v3 {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let third_party_id = assert_matches!(
|
assert_matches!(incoming, InvitationRecipient::ThirdPartyId(third_party_id));
|
||||||
incoming,
|
|
||||||
InvitationRecipient::ThirdPartyId(id) => id
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(third_party_id.id_server, "example.org");
|
assert_eq!(third_party_id.id_server, "example.org");
|
||||||
assert_eq!(third_party_id.id_access_token, "abcdefghijklmnop");
|
assert_eq!(third_party_id.id_access_token, "abcdefghijklmnop");
|
||||||
|
@ -79,7 +79,7 @@ impl<'de> Deserialize<'de> for PusherKind {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::{push::HttpPusherData, serde::JsonObject};
|
use ruma_common::{push::HttpPusherData, serde::JsonObject};
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
@ -148,11 +148,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let data = assert_matches!(
|
assert_matches!(from_json_value(json).unwrap(), PusherKind::Http(data));
|
||||||
from_json_value(json).unwrap(),
|
|
||||||
PusherKind::Http(data) => data
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(data.url, "http://localhost");
|
assert_eq!(data.url, "http://localhost");
|
||||||
assert_eq!(data.format, None);
|
assert_eq!(data.format, None);
|
||||||
}
|
}
|
||||||
@ -164,9 +160,7 @@ mod tests {
|
|||||||
"data": {}
|
"data": {}
|
||||||
});
|
});
|
||||||
|
|
||||||
let custom =
|
assert_matches!(from_json_value(json).unwrap(), PusherKind::_Custom(custom));
|
||||||
assert_matches!(from_json_value(json).unwrap(), PusherKind::_Custom(custom) => custom);
|
|
||||||
|
|
||||||
assert_eq!(custom.kind, "my.custom.kind");
|
assert_eq!(custom.kind, "my.custom.kind");
|
||||||
assert!(custom.data.is_empty());
|
assert!(custom.data.is_empty());
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ impl<'de> Deserialize<'de> for PusherAction {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::PusherAction;
|
use super::PusherAction;
|
||||||
@ -130,11 +130,7 @@ mod tests {
|
|||||||
"data": {}
|
"data": {}
|
||||||
});
|
});
|
||||||
|
|
||||||
let post_data = assert_matches!(
|
assert_matches!(from_json_value(json).unwrap(), PusherAction::Post(post_data));
|
||||||
from_json_value(json).unwrap(),
|
|
||||||
PusherAction::Post(post_data) => post_data
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(!post_data.append);
|
assert!(!post_data.append);
|
||||||
|
|
||||||
let pusher = post_data.pusher;
|
let pusher = post_data.pusher;
|
||||||
@ -155,11 +151,7 @@ mod tests {
|
|||||||
"kind": null,
|
"kind": null,
|
||||||
});
|
});
|
||||||
|
|
||||||
let ids = assert_matches!(
|
assert_matches!(from_json_value(json).unwrap(), PusherAction::Delete(ids));
|
||||||
from_json_value(json).unwrap(),
|
|
||||||
PusherAction::Delete(ids) => ids
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(ids.pushkey, "abcdef");
|
assert_eq!(ids.pushkey, "abcdef");
|
||||||
assert_eq!(ids.app_id, "my.matrix.app");
|
assert_eq!(ids.app_id, "my.matrix.app");
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::mxc_uri;
|
use ruma_common::mxc_uri;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
@ -341,7 +341,7 @@ pub mod v3 {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(wrapper.flows.len(), 1);
|
assert_eq!(wrapper.flows.len(), 1);
|
||||||
assert_matches!(wrapper.flows[0], LoginType::Password(_));
|
assert_matches!(&wrapper.flows[0], LoginType::Password(_));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -356,10 +356,7 @@ pub mod v3 {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(wrapper.flows.len(), 1);
|
assert_eq!(wrapper.flows.len(), 1);
|
||||||
let custom = assert_matches!(
|
assert_matches!(&wrapper.flows[0], LoginType::_Custom(custom));
|
||||||
&wrapper.flows[0],
|
|
||||||
LoginType::_Custom(custom) => custom
|
|
||||||
);
|
|
||||||
assert_eq!(custom.type_, "io.ruma.custom");
|
assert_eq!(custom.type_, "io.ruma.custom");
|
||||||
assert_eq!(custom.data.len(), 1);
|
assert_eq!(custom.data.len(), 1);
|
||||||
assert_eq!(custom.data.get("color"), Some(&JsonValue::from("green")));
|
assert_eq!(custom.data.get("color"), Some(&JsonValue::from("green")));
|
||||||
@ -390,10 +387,7 @@ pub mod v3 {
|
|||||||
assert_eq!(wrapper.flows.len(), 1);
|
assert_eq!(wrapper.flows.len(), 1);
|
||||||
let flow = &wrapper.flows[0];
|
let flow = &wrapper.flows[0];
|
||||||
|
|
||||||
let identity_providers = assert_matches!(
|
assert_matches!(flow, LoginType::Sso(SsoLoginType { identity_providers }));
|
||||||
flow,
|
|
||||||
LoginType::Sso(SsoLoginType { identity_providers }) => identity_providers
|
|
||||||
);
|
|
||||||
assert_eq!(identity_providers.len(), 2);
|
assert_eq!(identity_providers.len(), 2);
|
||||||
|
|
||||||
let provider = &identity_providers[0];
|
let provider = &identity_providers[0];
|
||||||
|
@ -356,7 +356,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
use super::{LoginInfo, Token};
|
use super::{LoginInfo, Token};
|
||||||
@ -364,7 +364,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_login_type() {
|
fn deserialize_login_type() {
|
||||||
let login = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value(json!({
|
from_json_value(json!({
|
||||||
"type": "m.login.password",
|
"type": "m.login.password",
|
||||||
"identifier": {
|
"identifier": {
|
||||||
@ -374,22 +374,19 @@ pub mod v3 {
|
|||||||
"password": "ilovebananas"
|
"password": "ilovebananas"
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
LoginInfo::Password(login) => login
|
LoginInfo::Password(login)
|
||||||
);
|
|
||||||
let user = assert_matches!(
|
|
||||||
login.identifier,
|
|
||||||
UserIdentifier::UserIdOrLocalpart(user) => user
|
|
||||||
);
|
);
|
||||||
|
assert_matches!(login.identifier, UserIdentifier::UserIdOrLocalpart(user));
|
||||||
assert_eq!(user, "cheeky_monkey");
|
assert_eq!(user, "cheeky_monkey");
|
||||||
assert_eq!(login.password, "ilovebananas");
|
assert_eq!(login.password, "ilovebananas");
|
||||||
|
|
||||||
let token = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value(json!({
|
from_json_value(json!({
|
||||||
"type": "m.login.token",
|
"type": "m.login.token",
|
||||||
"token": "1234567890abcdef"
|
"token": "1234567890abcdef"
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
LoginInfo::Token(Token { token }) => token
|
LoginInfo::Token(Token { token })
|
||||||
);
|
);
|
||||||
assert_eq!(token, "1234567890abcdef");
|
assert_eq!(token, "1234567890abcdef");
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ mod client_tests {
|
|||||||
mod server_tests {
|
mod server_tests {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::{api::IncomingRequest as _, presence::PresenceState};
|
use ruma_common::{api::IncomingRequest as _, presence::PresenceState};
|
||||||
|
|
||||||
use super::{Filter, Request};
|
use super::{Filter, Request};
|
||||||
@ -684,7 +684,7 @@ mod server_tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let id = assert_matches!(req.filter, Some(Filter::FilterId(id)) => id);
|
assert_matches!(req.filter, Some(Filter::FilterId(id)));
|
||||||
assert_eq!(id, "myfilter");
|
assert_eq!(id, "myfilter");
|
||||||
assert_eq!(req.since.as_deref(), Some("myts"));
|
assert_eq!(req.since.as_deref(), Some("myts"));
|
||||||
assert!(!req.full_state);
|
assert!(!req.full_state);
|
||||||
@ -733,7 +733,7 @@ mod server_tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let id = assert_matches!(req.filter, Some(Filter::FilterId(id)) => id);
|
assert_matches!(req.filter, Some(Filter::FilterId(id)));
|
||||||
assert_eq!(id, "EOKFFmdZYF");
|
assert_eq!(id, "EOKFFmdZYF");
|
||||||
assert_eq!(req.since, None);
|
assert_eq!(req.since, None);
|
||||||
assert!(!req.full_state);
|
assert!(!req.full_state);
|
||||||
|
@ -105,7 +105,7 @@ impl<'de> Deserialize<'de> for UserIdentifier {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::uiaa::UserIdentifier;
|
use crate::uiaa::UserIdentifier;
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -168,10 +168,7 @@ mod tests {
|
|||||||
"type": "m.id.user",
|
"type": "m.id.user",
|
||||||
"user": "@user:notareal.hs",
|
"user": "@user:notareal.hs",
|
||||||
});
|
});
|
||||||
let user = assert_matches!(
|
assert_matches!(from_json_value(json), Ok(UserIdentifier::UserIdOrLocalpart(user)));
|
||||||
from_json_value(json),
|
|
||||||
Ok(UserIdentifier::UserIdOrLocalpart(user)) => user
|
|
||||||
);
|
|
||||||
assert_eq!(user, "@user:notareal.hs");
|
assert_eq!(user, "@user:notareal.hs");
|
||||||
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
@ -179,10 +176,7 @@ mod tests {
|
|||||||
"country": "33",
|
"country": "33",
|
||||||
"phone": "0102030405",
|
"phone": "0102030405",
|
||||||
});
|
});
|
||||||
let (country, phone) = assert_matches!(
|
assert_matches!(from_json_value(json), Ok(UserIdentifier::PhoneNumber { country, phone }));
|
||||||
from_json_value(json),
|
|
||||||
Ok(UserIdentifier::PhoneNumber { country, phone }) => (country, phone)
|
|
||||||
);
|
|
||||||
assert_eq!(country, "33");
|
assert_eq!(country, "33");
|
||||||
assert_eq!(phone, "0102030405");
|
assert_eq!(phone, "0102030405");
|
||||||
|
|
||||||
@ -191,10 +185,7 @@ mod tests {
|
|||||||
"medium": "email",
|
"medium": "email",
|
||||||
"address": "me@myprovider.net",
|
"address": "me@myprovider.net",
|
||||||
});
|
});
|
||||||
let address = assert_matches!(
|
assert_matches!(from_json_value(json), Ok(UserIdentifier::Email { address }));
|
||||||
from_json_value(json),
|
|
||||||
Ok(UserIdentifier::Email { address }) => address
|
|
||||||
);
|
|
||||||
assert_eq!(address, "me@myprovider.net");
|
assert_eq!(address, "me@myprovider.net");
|
||||||
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
@ -202,10 +193,7 @@ mod tests {
|
|||||||
"medium": "msisdn",
|
"medium": "msisdn",
|
||||||
"address": "330102030405",
|
"address": "330102030405",
|
||||||
});
|
});
|
||||||
let number = assert_matches!(
|
assert_matches!(from_json_value(json), Ok(UserIdentifier::Msisdn { number }));
|
||||||
from_json_value(json),
|
|
||||||
Ok(UserIdentifier::Msisdn { number }) => number
|
|
||||||
);
|
|
||||||
assert_eq!(number, "330102030405");
|
assert_eq!(number, "330102030405");
|
||||||
|
|
||||||
let json = json!({
|
let json = json!({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(any(feature = "client", feature = "server"))]
|
#![cfg(any(feature = "client", feature = "server"))]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use ruma_client_api::{
|
use ruma_client_api::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
@ -14,13 +14,13 @@ use serde_json::{
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_user_identifier() {
|
fn deserialize_user_identifier() {
|
||||||
let id = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value(json!({
|
from_json_value(json!({
|
||||||
"type": "m.id.user",
|
"type": "m.id.user",
|
||||||
"user": "cheeky_monkey"
|
"user": "cheeky_monkey"
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
UserIdentifier::UserIdOrLocalpart(id) => id
|
UserIdentifier::UserIdOrLocalpart(id)
|
||||||
);
|
);
|
||||||
assert_eq!(id, "cheeky_monkey");
|
assert_eq!(id, "cheeky_monkey");
|
||||||
}
|
}
|
||||||
@ -50,10 +50,7 @@ fn deserialize_auth_data_registration_token() {
|
|||||||
"session": "session",
|
"session": "session",
|
||||||
});
|
});
|
||||||
|
|
||||||
let data = assert_matches!(
|
assert_matches!(from_json_value(json), Ok(AuthData::RegistrationToken(data)));
|
||||||
from_json_value(json),
|
|
||||||
Ok(AuthData::RegistrationToken(data)) => data
|
|
||||||
);
|
|
||||||
assert_eq!(data.token, "mytoken");
|
assert_eq!(data.token, "mytoken");
|
||||||
assert_eq!(data.session.as_deref(), Some("session"));
|
assert_eq!(data.session.as_deref(), Some("session"));
|
||||||
}
|
}
|
||||||
@ -70,10 +67,7 @@ fn serialize_auth_data_fallback() {
|
|||||||
fn deserialize_auth_data_fallback() {
|
fn deserialize_auth_data_fallback() {
|
||||||
let json = json!({ "session": "opaque_session_id" });
|
let json = json!({ "session": "opaque_session_id" });
|
||||||
|
|
||||||
let data = assert_matches!(
|
assert_matches!(from_json_value(json).unwrap(), AuthData::FallbackAcknowledgement(data));
|
||||||
from_json_value(json).unwrap(),
|
|
||||||
AuthData::FallbackAcknowledgement(data) => data
|
|
||||||
);
|
|
||||||
assert_eq!(data.session, "opaque_session_id");
|
assert_eq!(data.session, "opaque_session_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +197,9 @@ fn try_uiaa_response_from_http_response() {
|
|||||||
.body(json.as_bytes())
|
.body(json.as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let info = assert_matches!(
|
assert_matches!(
|
||||||
UiaaResponse::from_http_response(http_response),
|
UiaaResponse::from_http_response(http_response),
|
||||||
UiaaResponse::AuthResponse(info) => info
|
UiaaResponse::AuthResponse(info)
|
||||||
);
|
);
|
||||||
assert_eq!(info.completed, vec![AuthType::ReCaptcha]);
|
assert_eq!(info.completed, vec![AuthType::ReCaptcha]);
|
||||||
assert_eq!(info.flows.len(), 2);
|
assert_eq!(info.flows.len(), 2);
|
||||||
|
@ -104,7 +104,7 @@ criterion = { workspace = true, optional = true }
|
|||||||
js-sys = { version = "0.3", optional = true }
|
js-sys = { version = "0.3", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = { workspace = true }
|
assert_matches2 = { workspace = true }
|
||||||
assign = { workspace = true }
|
assign = { workspace = true }
|
||||||
http = { workspace = true }
|
http = { workspace = true }
|
||||||
maplit = { workspace = true }
|
maplit = { workspace = true }
|
||||||
|
@ -699,7 +699,7 @@ impl Display for MatrixVersion {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use http::Method;
|
use http::Method;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -225,7 +225,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{Filter, RoomNetwork, RoomTypeFilter};
|
use super::{Filter, RoomNetwork, RoomTypeFilter};
|
||||||
@ -326,7 +326,7 @@ mod tests {
|
|||||||
assert_eq!(filter.room_types.len(), 3);
|
assert_eq!(filter.room_types.len(), 3);
|
||||||
assert_eq!(filter.room_types[0], RoomTypeFilter::Default);
|
assert_eq!(filter.room_types[0], RoomTypeFilter::Default);
|
||||||
assert_eq!(filter.room_types[1], RoomTypeFilter::Space);
|
assert_eq!(filter.room_types[1], RoomTypeFilter::Space);
|
||||||
assert_matches!(filter.room_types[2], RoomTypeFilter::_Custom(_));
|
assert_matches!(&filter.room_types[2], RoomTypeFilter::_Custom(_));
|
||||||
assert_eq!(filter.room_types[2].as_str(), Some("custom_type"));
|
assert_eq!(filter.room_types[2].as_str(), Some("custom_type"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
//!
|
//!
|
||||||
//! // The downside of this event is we cannot use it with event enums,
|
//! // The downside of this event is we cannot use it with event enums,
|
||||||
//! // but could be deserialized from a `Raw<_>` that has failed to deserialize.
|
//! // but could be deserialized from a `Raw<_>` that has failed to deserialize.
|
||||||
//! assert_matches::assert_matches!(
|
//! assert!(matches!(
|
||||||
//! serde_json::from_value::<OriginalSyncMessageLikeEvent<ReactionEventContent>>(json),
|
//! serde_json::from_value::<OriginalSyncMessageLikeEvent<ReactionEventContent>>(json),
|
||||||
//! Ok(OriginalSyncMessageLikeEvent {
|
//! Ok(OriginalSyncMessageLikeEvent {
|
||||||
//! content: ReactionEventContent {
|
//! content: ReactionEventContent {
|
||||||
@ -99,7 +99,7 @@
|
|||||||
//! },
|
//! },
|
||||||
//! ..
|
//! ..
|
||||||
//! }) if key == "👍"
|
//! }) if key == "👍"
|
||||||
//! );
|
//! ));
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use serde::{de::IgnoredAny, Deserialize, Serializer};
|
use serde::{de::IgnoredAny, Deserialize, Serializer};
|
||||||
|
@ -51,7 +51,7 @@ impl IgnoredUser {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::IgnoredUserListEventContent;
|
use super::IgnoredUserListEventContent;
|
||||||
@ -82,9 +82,9 @@ mod tests {
|
|||||||
"type": "m.ignored_user_list"
|
"type": "m.ignored_user_list"
|
||||||
});
|
});
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyGlobalAccountDataEvent>(json),
|
from_json_value::<AnyGlobalAccountDataEvent>(json),
|
||||||
Ok(AnyGlobalAccountDataEvent::IgnoredUserList(ev)) => ev
|
Ok(AnyGlobalAccountDataEvent::IgnoredUserList(ev))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ev.content.ignored_users.keys().collect::<Vec<_>>(),
|
ev.content.ignored_users.keys().collect::<Vec<_>>(),
|
||||||
|
@ -163,7 +163,7 @@ impl From<SasV1ContentInit> for SasV1Content {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
||||||
};
|
};
|
||||||
@ -270,10 +270,7 @@ mod tests {
|
|||||||
let content = from_json_value::<ToDeviceKeyVerificationAcceptEventContent>(json).unwrap();
|
let content = from_json_value::<ToDeviceKeyVerificationAcceptEventContent>(json).unwrap();
|
||||||
assert_eq!(content.transaction_id, "456");
|
assert_eq!(content.transaction_id, "456");
|
||||||
|
|
||||||
let sas = assert_matches!(
|
assert_matches!(content.method, AcceptMethod::SasV1(sas));
|
||||||
content.method,
|
|
||||||
AcceptMethod::SasV1(sas) => sas
|
|
||||||
);
|
|
||||||
assert_eq!(sas.commitment.encode(), "aGVsbG8");
|
assert_eq!(sas.commitment.encode(), "aGVsbG8");
|
||||||
assert_eq!(sas.hash, HashAlgorithm::Sha256);
|
assert_eq!(sas.hash, HashAlgorithm::Sha256);
|
||||||
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
|
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
|
||||||
@ -299,10 +296,7 @@ mod tests {
|
|||||||
assert_eq!(ev.content.transaction_id, "456");
|
assert_eq!(ev.content.transaction_id, "456");
|
||||||
assert_eq!(ev.sender, "@example:localhost");
|
assert_eq!(ev.sender, "@example:localhost");
|
||||||
|
|
||||||
let sas = assert_matches!(
|
assert_matches!(ev.content.method, AcceptMethod::SasV1(sas));
|
||||||
ev.content.method,
|
|
||||||
AcceptMethod::SasV1(sas) => sas
|
|
||||||
);
|
|
||||||
assert_eq!(sas.commitment.encode(), "aGVsbG8");
|
assert_eq!(sas.commitment.encode(), "aGVsbG8");
|
||||||
assert_eq!(sas.hash, HashAlgorithm::Sha256);
|
assert_eq!(sas.hash, HashAlgorithm::Sha256);
|
||||||
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
|
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
|
||||||
@ -325,10 +319,7 @@ mod tests {
|
|||||||
assert_eq!(ev.content.transaction_id, "456");
|
assert_eq!(ev.content.transaction_id, "456");
|
||||||
assert_eq!(ev.sender, "@example:localhost");
|
assert_eq!(ev.sender, "@example:localhost");
|
||||||
|
|
||||||
let custom = assert_matches!(
|
assert_matches!(ev.content.method, AcceptMethod::_Custom(custom));
|
||||||
ev.content.method,
|
|
||||||
AcceptMethod::_Custom(custom) => custom
|
|
||||||
);
|
|
||||||
assert_eq!(custom.method, "m.sas.custom");
|
assert_eq!(custom.method, "m.sas.custom");
|
||||||
assert_eq!(custom.data.get("test"), Some(&JsonValue::from("field")));
|
assert_eq!(custom.data.get("test"), Some(&JsonValue::from("field")));
|
||||||
}
|
}
|
||||||
@ -352,10 +343,7 @@ mod tests {
|
|||||||
let content = from_json_value::<KeyVerificationAcceptEventContent>(json).unwrap();
|
let content = from_json_value::<KeyVerificationAcceptEventContent>(json).unwrap();
|
||||||
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
|
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
|
||||||
|
|
||||||
let sas = assert_matches!(
|
assert_matches!(content.method, AcceptMethod::SasV1(sas));
|
||||||
content.method,
|
|
||||||
AcceptMethod::SasV1(sas) => sas
|
|
||||||
);
|
|
||||||
assert_eq!(sas.commitment.encode(), "aGVsbG8");
|
assert_eq!(sas.commitment.encode(), "aGVsbG8");
|
||||||
assert_eq!(sas.hash, HashAlgorithm::Sha256);
|
assert_eq!(sas.hash, HashAlgorithm::Sha256);
|
||||||
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
|
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
|
||||||
|
@ -208,7 +208,7 @@ impl From<SasV1ContentInit> for SasV1Content {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
||||||
};
|
};
|
||||||
@ -364,10 +364,7 @@ mod tests {
|
|||||||
assert_eq!(content.from_device, "123");
|
assert_eq!(content.from_device, "123");
|
||||||
assert_eq!(content.transaction_id, "456");
|
assert_eq!(content.transaction_id, "456");
|
||||||
|
|
||||||
let sas = assert_matches!(
|
assert_matches!(content.method, StartMethod::SasV1(sas));
|
||||||
content.method,
|
|
||||||
StartMethod::SasV1(sas) => sas
|
|
||||||
);
|
|
||||||
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
|
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
|
||||||
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
|
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -396,10 +393,7 @@ mod tests {
|
|||||||
assert_eq!(ev.content.from_device, "123");
|
assert_eq!(ev.content.from_device, "123");
|
||||||
assert_eq!(ev.content.transaction_id, "456");
|
assert_eq!(ev.content.transaction_id, "456");
|
||||||
|
|
||||||
let sas = assert_matches!(
|
assert_matches!(ev.content.method, StartMethod::SasV1(sas));
|
||||||
ev.content.method,
|
|
||||||
StartMethod::SasV1(sas) => sas
|
|
||||||
);
|
|
||||||
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
|
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
|
||||||
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
|
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -425,10 +419,7 @@ mod tests {
|
|||||||
assert_eq!(ev.content.from_device, "123");
|
assert_eq!(ev.content.from_device, "123");
|
||||||
assert_eq!(ev.content.transaction_id, "456");
|
assert_eq!(ev.content.transaction_id, "456");
|
||||||
|
|
||||||
let custom = assert_matches!(
|
assert_matches!(ev.content.method, StartMethod::_Custom(custom));
|
||||||
ev.content.method,
|
|
||||||
StartMethod::_Custom(custom) => custom
|
|
||||||
);
|
|
||||||
assert_eq!(custom.method, "m.sas.custom");
|
assert_eq!(custom.method, "m.sas.custom");
|
||||||
assert_eq!(custom.data.get("test"), Some(&JsonValue::from("field")));
|
assert_eq!(custom.data.get("test"), Some(&JsonValue::from("field")));
|
||||||
|
|
||||||
@ -449,10 +440,7 @@ mod tests {
|
|||||||
assert_eq!(ev.content.from_device, "123");
|
assert_eq!(ev.content.from_device, "123");
|
||||||
assert_eq!(ev.content.transaction_id, "456");
|
assert_eq!(ev.content.transaction_id, "456");
|
||||||
|
|
||||||
let reciprocate = assert_matches!(
|
assert_matches!(ev.content.method, StartMethod::ReciprocateV1(reciprocate));
|
||||||
ev.content.method,
|
|
||||||
StartMethod::ReciprocateV1(reciprocate) => reciprocate
|
|
||||||
);
|
|
||||||
assert_eq!(reciprocate.secret.encode(), "c2VjcmV0Cg");
|
assert_eq!(reciprocate.secret.encode(), "c2VjcmV0Cg");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,10 +464,7 @@ mod tests {
|
|||||||
assert_eq!(content.from_device, "123");
|
assert_eq!(content.from_device, "123");
|
||||||
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
|
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
|
||||||
|
|
||||||
let sas = assert_matches!(
|
assert_matches!(content.method, StartMethod::SasV1(sas));
|
||||||
content.method,
|
|
||||||
StartMethod::SasV1(sas) => sas
|
|
||||||
);
|
|
||||||
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
|
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
|
||||||
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
|
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -502,10 +487,7 @@ mod tests {
|
|||||||
assert_eq!(content.from_device, "123");
|
assert_eq!(content.from_device, "123");
|
||||||
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
|
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
|
||||||
|
|
||||||
let reciprocate = assert_matches!(
|
assert_matches!(content.method, StartMethod::ReciprocateV1(reciprocate));
|
||||||
content.method,
|
|
||||||
StartMethod::ReciprocateV1(reciprocate) => reciprocate
|
|
||||||
);
|
|
||||||
assert_eq!(reciprocate.secret.encode(), "c2VjcmV0Cg");
|
assert_eq!(reciprocate.secret.encode(), "c2VjcmV0Cg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ impl From<Annotation> for ReactionEventContent {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::ReactionEventContent;
|
use super::ReactionEventContent;
|
||||||
@ -52,9 +52,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let relates_to = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<ReactionEventContent>(json),
|
from_json_value::<ReactionEventContent>(json),
|
||||||
Ok(ReactionEventContent { relates_to }) => relates_to
|
Ok(ReactionEventContent { relates_to })
|
||||||
);
|
);
|
||||||
assert_eq!(relates_to.event_id, "$1598361704261elfgc:localhost");
|
assert_eq!(relates_to.event_id, "$1598361704261elfgc:localhost");
|
||||||
assert_eq!(relates_to.key, "🦛");
|
assert_eq!(relates_to.key, "🦛");
|
||||||
|
@ -211,7 +211,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{Receipt, ReceiptThread};
|
use super::{Receipt, ReceiptThread};
|
||||||
@ -251,7 +251,7 @@ mod tests {
|
|||||||
|
|
||||||
let receipt = from_json_value::<Receipt>(json!({ "thread_id": "$abcdef76543" })).unwrap();
|
let receipt = from_json_value::<Receipt>(json!({ "thread_id": "$abcdef76543" })).unwrap();
|
||||||
assert_eq!(receipt.ts, None);
|
assert_eq!(receipt.ts, None);
|
||||||
let event_id = assert_matches!(receipt.thread, ReceiptThread::Thread(event_id) => event_id);
|
assert_matches!(receipt.thread, ReceiptThread::Thread(event_id));
|
||||||
assert_eq!(event_id, "$abcdef76543");
|
assert_eq!(event_id, "$abcdef76543");
|
||||||
|
|
||||||
let receipt = from_json_value::<Receipt>(json!({ "ts": 1_664_702_144_365_u64 })).unwrap();
|
let receipt = from_json_value::<Receipt>(json!({ "ts": 1_664_702_144_365_u64 })).unwrap();
|
||||||
@ -269,7 +269,7 @@ mod tests {
|
|||||||
receipt.ts.unwrap(),
|
receipt.ts.unwrap(),
|
||||||
MilliSecondsSinceUnixEpoch(1_664_702_144_365_u64.try_into().unwrap())
|
MilliSecondsSinceUnixEpoch(1_664_702_144_365_u64.try_into().unwrap())
|
||||||
);
|
);
|
||||||
assert_matches!(receipt.thread, ReceiptThread::_Custom(_));
|
assert_matches!(&receipt.thread, ReceiptThread::_Custom(_));
|
||||||
assert_eq!(receipt.thread.as_str().unwrap(), "io.ruma.unknown");
|
assert_eq!(receipt.thread.as_str().unwrap(), "io.ruma.unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ impl From<JsonWebKeyInit> for JsonWebKey {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ fn default_room_version_id() -> RoomVersionId {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{RoomCreateEventContent, RoomType};
|
use super::{RoomCreateEventContent, RoomType};
|
||||||
|
@ -243,7 +243,7 @@ impl From<MegolmV1AesSha2ContentInit> for MegolmV1AesSha2Content {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
@ -304,19 +304,13 @@ mod tests {
|
|||||||
|
|
||||||
let content: RoomEncryptedEventContent = from_json_value(json_data).unwrap();
|
let content: RoomEncryptedEventContent = from_json_value(json_data).unwrap();
|
||||||
|
|
||||||
let scheme = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(scheme));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(scheme) => scheme
|
|
||||||
);
|
|
||||||
assert_eq!(scheme.ciphertext, "ciphertext");
|
assert_eq!(scheme.ciphertext, "ciphertext");
|
||||||
assert_eq!(scheme.sender_key, "sender_key");
|
assert_eq!(scheme.sender_key, "sender_key");
|
||||||
assert_eq!(scheme.device_id, "device_id");
|
assert_eq!(scheme.device_id, "device_id");
|
||||||
assert_eq!(scheme.session_id, "session_id");
|
assert_eq!(scheme.session_id, "session_id");
|
||||||
|
|
||||||
let in_reply_to = assert_matches!(
|
assert_matches!(content.relates_to, Some(Relation::Reply { in_reply_to }));
|
||||||
content.relates_to,
|
|
||||||
Some(Relation::Reply { in_reply_to }) => in_reply_to
|
|
||||||
);
|
|
||||||
assert_eq!(in_reply_to.event_id, "$h29iv0s8:example.com");
|
assert_eq!(in_reply_to.event_id, "$h29iv0s8:example.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,10 +328,7 @@ mod tests {
|
|||||||
});
|
});
|
||||||
let content: RoomEncryptedEventContent = from_json_value(json_data).unwrap();
|
let content: RoomEncryptedEventContent = from_json_value(json_data).unwrap();
|
||||||
|
|
||||||
let c = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::OlmV1Curve25519AesSha2(c));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::OlmV1Curve25519AesSha2(c) => c
|
|
||||||
);
|
|
||||||
assert_eq!(c.sender_key, "test_key");
|
assert_eq!(c.sender_key, "test_key");
|
||||||
assert_eq!(c.ciphertext.len(), 1);
|
assert_eq!(c.ciphertext.len(), 1);
|
||||||
assert_eq!(c.ciphertext["test_curve_key"].body, "encrypted_body");
|
assert_eq!(c.ciphertext["test_curve_key"].body, "encrypted_body");
|
||||||
|
@ -245,7 +245,7 @@ impl<'de> Deserialize<'de> for AllowRule {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
|
|
||||||
use super::{AllowRule, JoinRule, OriginalSyncRoomJoinRulesEvent, RoomJoinRulesEventContent};
|
use super::{AllowRule, JoinRule, OriginalSyncRoomJoinRulesEvent, RoomJoinRulesEventContent};
|
||||||
use crate::room_id;
|
use crate::room_id;
|
||||||
|
@ -535,7 +535,7 @@ impl CanBeEmpty for RoomMemberUnsigned {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use maplit::btreemap;
|
use maplit::btreemap;
|
||||||
use serde_json::{from_value as from_json_value, json};
|
use serde_json::{from_value as from_json_value, json};
|
||||||
|
@ -29,7 +29,7 @@ impl RoomNameEventContent {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::RoomNameEventContent;
|
use super::RoomNameEventContent;
|
||||||
|
@ -51,7 +51,7 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ mod tests {
|
|||||||
fn deserialize_plain() {
|
fn deserialize_plain() {
|
||||||
let json = json!({ "thumbnail_url": "mxc://notareal.hs/abcdef" });
|
let json = json!({ "thumbnail_url": "mxc://notareal.hs/abcdef" });
|
||||||
|
|
||||||
let url = assert_matches!(
|
assert_matches!(
|
||||||
serde_json::from_value::<ThumbnailSourceTest>(json),
|
serde_json::from_value::<ThumbnailSourceTest>(json),
|
||||||
Ok(ThumbnailSourceTest { source: Some(MediaSource::Plain(url)) }) => url
|
Ok(ThumbnailSourceTest { source: Some(MediaSource::Plain(url)) })
|
||||||
);
|
);
|
||||||
assert_eq!(url, "mxc://notareal.hs/abcdef");
|
assert_eq!(url, "mxc://notareal.hs/abcdef");
|
||||||
}
|
}
|
||||||
@ -98,9 +98,9 @@ mod tests {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let file = assert_matches!(
|
assert_matches!(
|
||||||
serde_json::from_value::<ThumbnailSourceTest>(json),
|
serde_json::from_value::<ThumbnailSourceTest>(json),
|
||||||
Ok(ThumbnailSourceTest { source: Some(MediaSource::Encrypted(file)) }) => file
|
Ok(ThumbnailSourceTest { source: Some(MediaSource::Encrypted(file)) })
|
||||||
);
|
);
|
||||||
assert_eq!(file.url, "mxc://notareal.hs/abcdef");
|
assert_eq!(file.url, "mxc://notareal.hs/abcdef");
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ pub enum SecretName {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{RequestAction, SecretName, ToDeviceSecretRequestEventContent};
|
use super::{RequestAction, SecretName, ToDeviceSecretRequestEventContent};
|
||||||
@ -222,10 +222,7 @@ mod test {
|
|||||||
let content = from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap();
|
let content = from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap();
|
||||||
assert_eq!(content.requesting_device_id, "ABCDEFG");
|
assert_eq!(content.requesting_device_id, "ABCDEFG");
|
||||||
assert_eq!(content.request_id, "randomly_generated_id_9573");
|
assert_eq!(content.request_id, "randomly_generated_id_9573");
|
||||||
let secret = assert_matches!(
|
assert_matches!(content.action, RequestAction::Request(secret));
|
||||||
content.action,
|
|
||||||
RequestAction::Request(secret) => secret
|
|
||||||
);
|
|
||||||
assert_eq!(secret.as_str(), "org.example.some.secret");
|
assert_eq!(secret.as_str(), "org.example.some.secret");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,10 +252,7 @@ mod test {
|
|||||||
let content = from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap();
|
let content = from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap();
|
||||||
assert_eq!(content.requesting_device_id, "XYZxyz");
|
assert_eq!(content.requesting_device_id, "XYZxyz");
|
||||||
assert_eq!(content.request_id, "this_is_a_request_id");
|
assert_eq!(content.request_id, "this_is_a_request_id");
|
||||||
let secret = assert_matches!(
|
assert_matches!(content.action, RequestAction::Request(secret));
|
||||||
content.action,
|
|
||||||
RequestAction::Request(secret) => secret
|
|
||||||
);
|
|
||||||
assert_eq!(secret, SecretName::RecoveryKey);
|
assert_eq!(secret, SecretName::RecoveryKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ pub enum SecretEncryptionAlgorithm {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_value as from_json_value, json, to_value as to_json_value,
|
from_value as from_json_value, json, to_value as to_json_value,
|
||||||
@ -146,12 +146,9 @@ mod tests {
|
|||||||
assert_eq!(content.name.unwrap(), "my_key");
|
assert_eq!(content.name.unwrap(), "my_key");
|
||||||
assert_matches!(content.passphrase, None);
|
assert_matches!(content.passphrase, None);
|
||||||
|
|
||||||
let (iv, mac) = assert_matches!(
|
assert_matches!(
|
||||||
content.algorithm,
|
content.algorithm,
|
||||||
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
|
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
|
||||||
iv,
|
|
||||||
mac,
|
|
||||||
} => (iv, mac)
|
|
||||||
);
|
);
|
||||||
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
||||||
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
||||||
@ -171,12 +168,9 @@ mod tests {
|
|||||||
assert!(content.name.is_none());
|
assert!(content.name.is_none());
|
||||||
assert_matches!(content.passphrase, None);
|
assert_matches!(content.passphrase, None);
|
||||||
|
|
||||||
let (iv, mac) = assert_matches!(
|
assert_matches!(
|
||||||
content.algorithm,
|
content.algorithm,
|
||||||
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
|
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
|
||||||
iv,
|
|
||||||
mac,
|
|
||||||
} => (iv, mac)
|
|
||||||
);
|
);
|
||||||
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
||||||
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
||||||
@ -237,12 +231,9 @@ mod tests {
|
|||||||
assert_eq!(passphrase.iterations, uint!(8));
|
assert_eq!(passphrase.iterations, uint!(8));
|
||||||
assert_eq!(passphrase.bits, uint!(256));
|
assert_eq!(passphrase.bits, uint!(256));
|
||||||
|
|
||||||
let (iv, mac) = assert_matches!(
|
assert_matches!(
|
||||||
content.algorithm,
|
content.algorithm,
|
||||||
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
|
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
|
||||||
iv,
|
|
||||||
mac,
|
|
||||||
} => (iv, mac)
|
|
||||||
);
|
);
|
||||||
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
||||||
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
||||||
@ -287,12 +278,9 @@ mod tests {
|
|||||||
assert_eq!(ev.content.name.unwrap(), "my_key");
|
assert_eq!(ev.content.name.unwrap(), "my_key");
|
||||||
assert_matches!(ev.content.passphrase, None);
|
assert_matches!(ev.content.passphrase, None);
|
||||||
|
|
||||||
let (iv, mac) = assert_matches!(
|
assert_matches!(
|
||||||
ev.content.algorithm,
|
ev.content.algorithm,
|
||||||
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
|
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
|
||||||
iv,
|
|
||||||
mac,
|
|
||||||
} => (iv, mac)
|
|
||||||
);
|
);
|
||||||
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
||||||
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
|
||||||
|
@ -44,7 +44,7 @@ pub enum SecretEncryptedData {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{SecretEncryptedData, SecretEventContent};
|
use super::{SecretEncryptedData, SecretEventContent};
|
||||||
@ -91,13 +91,9 @@ mod tests {
|
|||||||
let deserialized: SecretEventContent = from_json_value(json).unwrap();
|
let deserialized: SecretEventContent = from_json_value(json).unwrap();
|
||||||
let secret_data = deserialized.encrypted.get("key_one").unwrap();
|
let secret_data = deserialized.encrypted.get("key_one").unwrap();
|
||||||
|
|
||||||
let (iv, ciphertext, mac) = assert_matches!(
|
assert_matches!(
|
||||||
secret_data,
|
secret_data,
|
||||||
SecretEncryptedData::AesHmacSha2EncryptedData {
|
SecretEncryptedData::AesHmacSha2EncryptedData { iv, ciphertext, mac }
|
||||||
iv,
|
|
||||||
ciphertext,
|
|
||||||
mac
|
|
||||||
} => (iv, ciphertext, mac)
|
|
||||||
);
|
);
|
||||||
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
|
||||||
assert_eq!(ciphertext.encode(), "dGhpc2lzZGVmaW5pdGVseWNpcGhlcnRleHQ");
|
assert_eq!(ciphertext.encode(), "dGhpc2lzZGVmaW5pdGVseWNpcGhlcnRleHQ");
|
||||||
|
@ -540,7 +540,7 @@ impl FromStr for MatrixUri {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_identifiers_validation::{
|
use ruma_identifiers_validation::{
|
||||||
error::{MatrixIdError, MatrixToError, MatrixUriError},
|
error::{MatrixIdError, MatrixToError, MatrixUriError},
|
||||||
Error,
|
Error,
|
||||||
|
@ -150,7 +150,7 @@ impl From<String> for VoipVersionId {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
@ -177,10 +177,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn valid_custom_string_version() {
|
fn valid_custom_string_version() {
|
||||||
let version = assert_matches!(
|
assert_matches!(VoipVersionId::try_from("io.ruma.2"), Ok(version));
|
||||||
VoipVersionId::try_from("io.ruma.2"),
|
|
||||||
Ok(version) => version
|
|
||||||
);
|
|
||||||
assert_eq!(version.as_ref(), "io.ruma.2");
|
assert_eq!(version.as_ref(), "io.ruma.2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -977,7 +977,7 @@ pub enum RemovePushRuleError {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::{int, uint};
|
use js_int::{int, uint};
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_value as from_json_value, json, to_value as to_json_value,
|
from_value as from_json_value, json, to_value as to_json_value,
|
||||||
@ -1043,25 +1043,25 @@ mod tests {
|
|||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(
|
||||||
rule_opt.unwrap(),
|
rule_opt.unwrap(),
|
||||||
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
|
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(rule_id, ".m.rule.call");
|
assert_eq!(rule_id, ".m.rule.call");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(
|
||||||
rule_opt.unwrap(),
|
rule_opt.unwrap(),
|
||||||
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
|
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(rule_id, "!roomid:matrix.org");
|
assert_eq!(rule_id, "!roomid:matrix.org");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(
|
||||||
rule_opt.unwrap(),
|
rule_opt.unwrap(),
|
||||||
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
|
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(rule_id, ".m.rule.suppress_notices");
|
assert_eq!(rule_id, ".m.rule.suppress_notices");
|
||||||
|
|
||||||
@ -1314,10 +1314,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut iter = rule.actions.iter();
|
let mut iter = rule.actions.iter();
|
||||||
assert_matches!(iter.next(), Some(Action::Notify));
|
assert_matches!(iter.next(), Some(Action::Notify));
|
||||||
let sound = assert_matches!(
|
assert_matches!(iter.next(), Some(Action::SetTweak(Tweak::Sound(sound))));
|
||||||
iter.next(),
|
|
||||||
Some(Action::SetTweak(Tweak::Sound(sound))) => sound
|
|
||||||
);
|
|
||||||
assert_eq!(sound, "default");
|
assert_eq!(sound, "default");
|
||||||
assert_matches!(iter.next(), Some(Action::SetTweak(Tweak::Highlight(true))));
|
assert_matches!(iter.next(), Some(Action::SetTweak(Tweak::Highlight(true))));
|
||||||
assert_matches!(iter.next(), None);
|
assert_matches!(iter.next(), None);
|
||||||
@ -1383,49 +1380,40 @@ mod tests {
|
|||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(
|
||||||
rule_opt.unwrap(),
|
rule_opt.unwrap(),
|
||||||
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
|
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(rule_id, "!roomid:server.name");
|
assert_eq!(rule_id, "!roomid:server.name");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(
|
||||||
rule_opt.unwrap(),
|
rule_opt.unwrap(),
|
||||||
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
|
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(rule_id, ".m.rule.call");
|
assert_eq!(rule_id, ".m.rule.call");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(rule_opt.unwrap(), AnyPushRule::Content(PatternedPushRule { rule_id, .. }));
|
||||||
rule_opt.unwrap(),
|
|
||||||
AnyPushRule::Content(PatternedPushRule { rule_id, .. }) => rule_id
|
|
||||||
);
|
|
||||||
assert_eq!(rule_id, ".m.rule.contains_user_name");
|
assert_eq!(rule_id, ".m.rule.contains_user_name");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(rule_opt.unwrap(), AnyPushRule::Content(PatternedPushRule { rule_id, .. }));
|
||||||
rule_opt.unwrap(),
|
|
||||||
AnyPushRule::Content(PatternedPushRule { rule_id, .. }) => rule_id
|
|
||||||
);
|
|
||||||
assert_eq!(rule_id, "ruma");
|
assert_eq!(rule_id, "ruma");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(rule_opt.unwrap(), AnyPushRule::Room(SimplePushRule { rule_id, .. }));
|
||||||
rule_opt.unwrap(),
|
|
||||||
AnyPushRule::Room(SimplePushRule { rule_id, .. }) => rule_id
|
|
||||||
);
|
|
||||||
assert_eq!(rule_id, "!roomid:server.name");
|
assert_eq!(rule_id, "!roomid:server.name");
|
||||||
|
|
||||||
let rule_opt = iter.next();
|
let rule_opt = iter.next();
|
||||||
assert!(rule_opt.is_some());
|
assert!(rule_opt.is_some());
|
||||||
let rule_id = assert_matches!(
|
assert_matches!(
|
||||||
rule_opt.unwrap(),
|
rule_opt.unwrap(),
|
||||||
AnyPushRule::Underride(ConditionalPushRule { rule_id, .. }) => rule_id
|
AnyPushRule::Underride(ConditionalPushRule { rule_id, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(rule_id, ".m.rule.room_one_to_one");
|
assert_eq!(rule_id, ".m.rule.room_one_to_one");
|
||||||
|
|
||||||
@ -1633,8 +1621,8 @@ mod tests {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
test_set.get_actions(&message, context_one_to_one),
|
test_set.get_actions(&message, context_one_to_one),
|
||||||
[Action::SetTweak(Tweak::Sound(sound))]
|
[Action::SetTweak(Tweak::Sound(sound))]
|
||||||
if sound == "content"
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(sound, "content");
|
||||||
|
|
||||||
let three_conditions = ConditionalPushRule {
|
let three_conditions = ConditionalPushRule {
|
||||||
actions: vec![Action::SetTweak(Tweak::Sound("three".into()))],
|
actions: vec![Action::SetTweak(Tweak::Sound("three".into()))],
|
||||||
@ -1652,9 +1640,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
set.override_.insert(three_conditions);
|
set.override_.insert(three_conditions);
|
||||||
|
|
||||||
let sound = assert_matches!(
|
assert_matches!(
|
||||||
set.get_actions(&message, context_one_to_one),
|
set.get_actions(&message, context_one_to_one),
|
||||||
[Action::SetTweak(Tweak::Sound(sound))] => sound
|
[Action::SetTweak(Tweak::Sound(sound))]
|
||||||
);
|
);
|
||||||
assert_eq!(sound, "content");
|
assert_eq!(sound, "content");
|
||||||
|
|
||||||
@ -1670,9 +1658,9 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let sound = assert_matches!(
|
assert_matches!(
|
||||||
set.get_actions(&new_message, context_one_to_one),
|
set.get_actions(&new_message, context_one_to_one),
|
||||||
[Action::SetTweak(Tweak::Sound(sound))] => sound
|
[Action::SetTweak(Tweak::Sound(sound))]
|
||||||
);
|
);
|
||||||
assert_eq!(sound, "three");
|
assert_eq!(sound, "three");
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ mod tweak_serde {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::{Action, Tweak};
|
use super::{Action, Tweak};
|
||||||
@ -224,9 +224,9 @@ mod tests {
|
|||||||
"set_tweak": "sound",
|
"set_tweak": "sound",
|
||||||
"value": "default"
|
"value": "default"
|
||||||
});
|
});
|
||||||
let value = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<Action>(json_data),
|
from_json_value::<Action>(json_data),
|
||||||
Ok(Action::SetTweak(Tweak::Sound(value))) => value
|
Ok(Action::SetTweak(Tweak::Sound(value)))
|
||||||
);
|
);
|
||||||
assert_eq!(value, "default");
|
assert_eq!(value, "default");
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ impl StrExt for str {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::{int, uint};
|
use js_int::{int, uint};
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
|
||||||
@ -511,9 +511,9 @@ mod tests {
|
|||||||
"kind": "event_match",
|
"kind": "event_match",
|
||||||
"pattern": "m.notice"
|
"pattern": "m.notice"
|
||||||
});
|
});
|
||||||
let (key, pattern) = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<PushCondition>(json_data).unwrap(),
|
from_json_value::<PushCondition>(json_data).unwrap(),
|
||||||
PushCondition::EventMatch { key, pattern } => (key, pattern)
|
PushCondition::EventMatch { key, pattern }
|
||||||
);
|
);
|
||||||
assert_eq!(key, "content.msgtype");
|
assert_eq!(key, "content.msgtype");
|
||||||
assert_eq!(pattern, "m.notice");
|
assert_eq!(pattern, "m.notice");
|
||||||
@ -533,9 +533,9 @@ mod tests {
|
|||||||
"is": "2",
|
"is": "2",
|
||||||
"kind": "room_member_count"
|
"kind": "room_member_count"
|
||||||
});
|
});
|
||||||
let is = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<PushCondition>(json_data).unwrap(),
|
from_json_value::<PushCondition>(json_data).unwrap(),
|
||||||
PushCondition::RoomMemberCount { is } => is
|
PushCondition::RoomMemberCount { is }
|
||||||
);
|
);
|
||||||
assert_eq!(is, RoomMemberCountIs::from(uint!(2)));
|
assert_eq!(is, RoomMemberCountIs::from(uint!(2)));
|
||||||
}
|
}
|
||||||
@ -546,9 +546,9 @@ mod tests {
|
|||||||
"key": "room",
|
"key": "room",
|
||||||
"kind": "sender_notification_permission"
|
"kind": "sender_notification_permission"
|
||||||
});
|
});
|
||||||
let key = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<PushCondition>(json_data).unwrap(),
|
from_json_value::<PushCondition>(json_data).unwrap(),
|
||||||
PushCondition::SenderNotificationPermission { key } => key
|
PushCondition::SenderNotificationPermission { key }
|
||||||
);
|
);
|
||||||
assert_eq!(key, "room");
|
assert_eq!(key, "room");
|
||||||
}
|
}
|
||||||
|
@ -596,7 +596,7 @@ pub enum PredefinedContentRuleId {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
|
|
||||||
use super::PredefinedOverrideRuleId;
|
use super::PredefinedOverrideRuleId;
|
||||||
@ -647,7 +647,7 @@ mod tests {
|
|||||||
// `enabled` and `actions` have been copied from the old rules.
|
// `enabled` and `actions` have been copied from the old rules.
|
||||||
assert!(master_rule.enabled);
|
assert!(master_rule.enabled);
|
||||||
assert_eq!(master_rule.actions.len(), 1);
|
assert_eq!(master_rule.actions.len(), 1);
|
||||||
assert_matches!(master_rule.actions[0], Action::Notify);
|
assert_matches!(&master_rule.actions[0], Action::Notify);
|
||||||
|
|
||||||
// Non-server-default rule is still present and hasn't changed.
|
// Non-server-default rule is still present and hasn't changed.
|
||||||
let user_rule = ruleset.override_.get(user_rule_id).unwrap();
|
let user_rule = ruleset.override_.get(user_rule_id).unwrap();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
#[cfg(feature = "unstable-msc3246")]
|
#[cfg(feature = "unstable-msc3246")]
|
||||||
use ruma_common::events::audio::Amplitude;
|
use ruma_common::events::audio::Amplitude;
|
||||||
@ -287,9 +287,9 @@ fn message_event_deserialization() {
|
|||||||
"type": "org.matrix.msc1767.audio",
|
"type": "org.matrix.msc1767.audio",
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||||
AnyMessageLikeEvent::Audio(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::Audio(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
#[cfg(feature = "unstable-msc2747")]
|
#[cfg(feature = "unstable-msc2747")]
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
@ -81,9 +81,9 @@ fn answer_v0_event_deserialization() {
|
|||||||
"type": "m.call.answer"
|
"type": "m.call.answer"
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||||
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||||
@ -118,9 +118,9 @@ fn answer_v0_event_deserialization_then_convert_to_full() {
|
|||||||
|
|
||||||
let sync_ev: AnySyncMessageLikeEvent = from_json_value(json_data).unwrap();
|
let sync_ev: AnySyncMessageLikeEvent = from_json_value(json_data).unwrap();
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
sync_ev.into_full_event(rid.to_owned()),
|
sync_ev.into_full_event(rid.to_owned()),
|
||||||
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||||
@ -238,9 +238,9 @@ fn invite_v1_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallInvite(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallInvite(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
@ -327,9 +327,9 @@ fn answer_unknown_version_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
@ -402,9 +402,9 @@ fn candidates_v1_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallCandidates(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallCandidates(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
@ -451,9 +451,9 @@ fn hangup_v1_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallHangup(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallHangup(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
@ -507,9 +507,9 @@ fn negotiate_v1_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallNegotiate(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallNegotiate(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
@ -549,9 +549,9 @@ fn reject_v1_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallReject(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallReject(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
@ -592,9 +592,9 @@ fn select_v1_answer_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::CallSelectAnswer(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallSelectAnswer(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
assert_eq!(content.call_id, "abcdef");
|
assert_eq!(content.call_id, "abcdef");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
device_id, event_id,
|
device_id, event_id,
|
||||||
events::{
|
events::{
|
||||||
@ -67,10 +67,7 @@ fn content_no_relation_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
||||||
|
|
||||||
let encrypted_content = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encrypted_content.ciphertext,
|
encrypted_content.ciphertext,
|
||||||
@ -138,10 +135,7 @@ fn content_reply_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
||||||
|
|
||||||
let encrypted_content = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encrypted_content.ciphertext,
|
encrypted_content.ciphertext,
|
||||||
@ -153,10 +147,7 @@ fn content_reply_deserialization() {
|
|||||||
lDl5mzVO3tPnJMKZ0hn+AF"
|
lDl5mzVO3tPnJMKZ0hn+AF"
|
||||||
);
|
);
|
||||||
|
|
||||||
let in_reply_to = assert_matches!(
|
assert_matches!(content.relates_to, Some(Relation::Reply { in_reply_to }));
|
||||||
content.relates_to,
|
|
||||||
Some(Relation::Reply { in_reply_to }) => in_reply_to
|
|
||||||
);
|
|
||||||
assert_eq!(in_reply_to.event_id, "$replied_to_event");
|
assert_eq!(in_reply_to.event_id, "$replied_to_event");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,10 +200,7 @@ fn content_replacement_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
||||||
|
|
||||||
let encrypted_content = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encrypted_content.ciphertext,
|
encrypted_content.ciphertext,
|
||||||
@ -224,10 +212,7 @@ fn content_replacement_deserialization() {
|
|||||||
lDl5mzVO3tPnJMKZ0hn+AF"
|
lDl5mzVO3tPnJMKZ0hn+AF"
|
||||||
);
|
);
|
||||||
|
|
||||||
let replacement = assert_matches!(
|
assert_matches!(content.relates_to, Some(Relation::Replacement(replacement)));
|
||||||
content.relates_to,
|
|
||||||
Some(Relation::Replacement(replacement)) => replacement
|
|
||||||
);
|
|
||||||
assert_eq!(replacement.event_id, "$replaced_event");
|
assert_eq!(replacement.event_id, "$replaced_event");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,10 +265,7 @@ fn content_reference_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
||||||
|
|
||||||
let encrypted_content = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encrypted_content.ciphertext,
|
encrypted_content.ciphertext,
|
||||||
@ -295,10 +277,7 @@ fn content_reference_deserialization() {
|
|||||||
lDl5mzVO3tPnJMKZ0hn+AF"
|
lDl5mzVO3tPnJMKZ0hn+AF"
|
||||||
);
|
);
|
||||||
|
|
||||||
let reference = assert_matches!(
|
assert_matches!(content.relates_to, Some(Relation::Reference(reference)));
|
||||||
content.relates_to,
|
|
||||||
Some(Relation::Reference(reference)) => reference
|
|
||||||
);
|
|
||||||
assert_eq!(reference.event_id, "$referenced_event");
|
assert_eq!(reference.event_id, "$referenced_event");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,10 +340,7 @@ fn content_thread_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
||||||
|
|
||||||
let encrypted_content = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encrypted_content.ciphertext,
|
encrypted_content.ciphertext,
|
||||||
@ -376,10 +352,7 @@ fn content_thread_deserialization() {
|
|||||||
lDl5mzVO3tPnJMKZ0hn+AF"
|
lDl5mzVO3tPnJMKZ0hn+AF"
|
||||||
);
|
);
|
||||||
|
|
||||||
let thread = assert_matches!(
|
assert_matches!(content.relates_to, Some(Relation::Thread(thread)));
|
||||||
content.relates_to,
|
|
||||||
Some(Relation::Thread(thread)) => thread
|
|
||||||
);
|
|
||||||
assert_eq!(thread.event_id, "$thread_root");
|
assert_eq!(thread.event_id, "$thread_root");
|
||||||
assert_eq!(thread.in_reply_to.unwrap().event_id, "$prev_event");
|
assert_eq!(thread.in_reply_to.unwrap().event_id, "$prev_event");
|
||||||
assert!(!thread.is_falling_back);
|
assert!(!thread.is_falling_back);
|
||||||
@ -441,10 +414,7 @@ fn content_annotation_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
|
||||||
|
|
||||||
let encrypted_content = assert_matches!(
|
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
|
||||||
content.scheme,
|
|
||||||
EncryptedEventScheme::MegolmV1AesSha2(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encrypted_content.ciphertext,
|
encrypted_content.ciphertext,
|
||||||
@ -456,10 +426,7 @@ fn content_annotation_deserialization() {
|
|||||||
lDl5mzVO3tPnJMKZ0hn+AF"
|
lDl5mzVO3tPnJMKZ0hn+AF"
|
||||||
);
|
);
|
||||||
|
|
||||||
let annotation = assert_matches!(
|
assert_matches!(content.relates_to, Some(Relation::Annotation(annotation)));
|
||||||
content.relates_to,
|
|
||||||
Some(Relation::Annotation(annotation)) => annotation
|
|
||||||
);
|
|
||||||
assert_eq!(annotation.event_id, "$annotated_event");
|
assert_eq!(annotation.event_id, "$annotated_event");
|
||||||
assert_eq!(annotation.key, "some_key");
|
assert_eq!(annotation.key, "some_key");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::int;
|
use js_int::int;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{MessageLikeEvent, StateEvent, SyncMessageLikeEvent, SyncStateEvent},
|
events::{MessageLikeEvent, StateEvent, SyncMessageLikeEvent, SyncStateEvent},
|
||||||
@ -122,18 +122,14 @@ fn power_event_sync_deserialization() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let ban = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(json_data),
|
from_json_value::<AnySyncTimelineEvent>(json_data),
|
||||||
Ok(AnySyncTimelineEvent::State(
|
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomPowerLevels(
|
||||||
AnySyncStateEvent::RoomPowerLevels(SyncStateEvent::Original(
|
SyncStateEvent::Original(OriginalSyncStateEvent {
|
||||||
OriginalSyncStateEvent {
|
content: RoomPowerLevelsEventContent { ban, .. },
|
||||||
content: RoomPowerLevelsEventContent {
|
..
|
||||||
ban, ..
|
},)
|
||||||
},
|
),))
|
||||||
..
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
)) => ban
|
|
||||||
);
|
);
|
||||||
assert_eq!(ban, int!(50));
|
assert_eq!(ban, int!(50));
|
||||||
}
|
}
|
||||||
@ -142,19 +138,14 @@ fn power_event_sync_deserialization() {
|
|||||||
fn message_event_sync_deserialization() {
|
fn message_event_sync_deserialization() {
|
||||||
let json_data = message_event_sync();
|
let json_data = message_event_sync();
|
||||||
|
|
||||||
let text_content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(json_data),
|
from_json_value::<AnySyncTimelineEvent>(json_data),
|
||||||
Ok(AnySyncTimelineEvent::MessageLike(
|
Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
|
||||||
AnySyncMessageLikeEvent::RoomMessage(SyncMessageLikeEvent::Original(
|
SyncMessageLikeEvent::Original(OriginalSyncMessageLikeEvent {
|
||||||
OriginalSyncMessageLikeEvent {
|
content: RoomMessageEventContent { msgtype: MessageType::Text(text_content), .. },
|
||||||
content: RoomMessageEventContent {
|
..
|
||||||
msgtype: MessageType::Text(text_content),
|
},)
|
||||||
..
|
)))
|
||||||
},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
))
|
|
||||||
)) => text_content
|
|
||||||
);
|
);
|
||||||
assert_eq!(text_content.body, "baba");
|
assert_eq!(text_content.body, "baba");
|
||||||
let formatted = text_content.formatted.unwrap();
|
let formatted = text_content.formatted.unwrap();
|
||||||
@ -165,11 +156,11 @@ fn message_event_sync_deserialization() {
|
|||||||
fn aliases_event_sync_deserialization() {
|
fn aliases_event_sync_deserialization() {
|
||||||
let json_data = aliases_event_sync();
|
let json_data = aliases_event_sync();
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(json_data),
|
from_json_value::<AnySyncTimelineEvent>(json_data),
|
||||||
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(
|
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(
|
||||||
ev,
|
ev,
|
||||||
)))) => ev
|
))))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
@ -179,19 +170,14 @@ fn aliases_event_sync_deserialization() {
|
|||||||
fn message_room_event_deserialization() {
|
fn message_room_event_deserialization() {
|
||||||
let json_data = message_event();
|
let json_data = message_event();
|
||||||
|
|
||||||
let text_content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(json_data),
|
from_json_value::<AnyTimelineEvent>(json_data),
|
||||||
Ok(AnyTimelineEvent::MessageLike(
|
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
|
||||||
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(
|
MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||||
OriginalMessageLikeEvent {
|
content: RoomMessageEventContent { msgtype: MessageType::Text(text_content), .. },
|
||||||
content: RoomMessageEventContent {
|
..
|
||||||
msgtype: MessageType::Text(text_content),
|
},)
|
||||||
..
|
)))
|
||||||
},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
))
|
|
||||||
)) => text_content
|
|
||||||
);
|
);
|
||||||
assert_eq!(text_content.body, "baba");
|
assert_eq!(text_content.body, "baba");
|
||||||
let formatted = text_content.formatted.unwrap();
|
let formatted = text_content.formatted.unwrap();
|
||||||
@ -212,17 +198,11 @@ fn message_event_serialization() {
|
|||||||
fn alias_room_event_deserialization() {
|
fn alias_room_event_deserialization() {
|
||||||
let json_data = aliases_event();
|
let json_data = aliases_event();
|
||||||
|
|
||||||
let aliases = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(json_data),
|
from_json_value::<AnyTimelineEvent>(json_data),
|
||||||
Ok(AnyTimelineEvent::State(
|
Ok(AnyTimelineEvent::State(AnyStateEvent::RoomAliases(StateEvent::Original(
|
||||||
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
|
OriginalStateEvent { content: RoomAliasesEventContent { aliases, .. }, .. }
|
||||||
content: RoomAliasesEventContent {
|
))))
|
||||||
aliases,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
}))
|
|
||||||
)) => aliases
|
|
||||||
);
|
);
|
||||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
}
|
}
|
||||||
@ -231,17 +211,14 @@ fn alias_room_event_deserialization() {
|
|||||||
fn message_event_deserialization() {
|
fn message_event_deserialization() {
|
||||||
let json_data = message_event();
|
let json_data = message_event();
|
||||||
|
|
||||||
let text_content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(json_data),
|
from_json_value::<AnyTimelineEvent>(json_data),
|
||||||
Ok(AnyTimelineEvent::MessageLike(
|
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
|
||||||
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||||
content: RoomMessageEventContent {
|
content: RoomMessageEventContent { msgtype: MessageType::Text(text_content), .. },
|
||||||
msgtype: MessageType::Text(text_content),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
..
|
||||||
}))
|
})
|
||||||
)) => text_content
|
)))
|
||||||
);
|
);
|
||||||
assert_eq!(text_content.body, "baba");
|
assert_eq!(text_content.body, "baba");
|
||||||
let formatted = text_content.formatted.unwrap();
|
let formatted = text_content.formatted.unwrap();
|
||||||
@ -252,17 +229,11 @@ fn message_event_deserialization() {
|
|||||||
fn alias_event_deserialization() {
|
fn alias_event_deserialization() {
|
||||||
let json_data = aliases_event();
|
let json_data = aliases_event();
|
||||||
|
|
||||||
let aliases = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(json_data),
|
from_json_value::<AnyTimelineEvent>(json_data),
|
||||||
Ok(AnyTimelineEvent::State(
|
Ok(AnyTimelineEvent::State(AnyStateEvent::RoomAliases(StateEvent::Original(
|
||||||
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
|
OriginalStateEvent { content: RoomAliasesEventContent { aliases, .. }, .. }
|
||||||
content: RoomAliasesEventContent {
|
))))
|
||||||
aliases,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
}))
|
|
||||||
)) => aliases
|
|
||||||
);
|
);
|
||||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
}
|
}
|
||||||
@ -271,9 +242,9 @@ fn alias_event_deserialization() {
|
|||||||
fn alias_event_field_access() {
|
fn alias_event_field_access() {
|
||||||
let json_data = aliases_event();
|
let json_data = aliases_event();
|
||||||
|
|
||||||
let state_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(json_data.clone()),
|
from_json_value::<AnyTimelineEvent>(json_data.clone()),
|
||||||
Ok(AnyTimelineEvent::State(state_event)) => state_event
|
Ok(AnyTimelineEvent::State(state_event))
|
||||||
);
|
);
|
||||||
assert_eq!(state_event.state_key(), "room.com");
|
assert_eq!(state_event.state_key(), "room.com");
|
||||||
assert_eq!(state_event.room_id(), "!room:room.com");
|
assert_eq!(state_event.room_id(), "!room:room.com");
|
||||||
@ -281,7 +252,7 @@ fn alias_event_field_access() {
|
|||||||
assert_eq!(state_event.sender(), "@example:localhost");
|
assert_eq!(state_event.sender(), "@example:localhost");
|
||||||
|
|
||||||
let deser = from_json_value::<AnyStateEvent>(json_data).unwrap();
|
let deser = from_json_value::<AnyStateEvent>(json_data).unwrap();
|
||||||
let ev = assert_matches!(&deser, AnyStateEvent::RoomAliases(StateEvent::Original(ev)) => ev);
|
assert_matches!(&deser, AnyStateEvent::RoomAliases(StateEvent::Original(ev)));
|
||||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
assert_eq!(deser.event_type().to_string(), "m.room.aliases");
|
assert_eq!(deser.event_type().to_string(), "m.room.aliases");
|
||||||
}
|
}
|
||||||
@ -299,9 +270,9 @@ fn ephemeral_event_deserialization() {
|
|||||||
"type": "m.typing"
|
"type": "m.typing"
|
||||||
});
|
});
|
||||||
|
|
||||||
let ephem = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
||||||
Ok(ephem @ AnyEphemeralRoomEvent::Typing(_)) => ephem
|
Ok(ephem @ AnyEphemeralRoomEvent::Typing(_))
|
||||||
);
|
);
|
||||||
assert_eq!(ephem.room_id(), "!jEsUZKDJdhlrceRyVU:example.org");
|
assert_eq!(ephem.room_id(), "!jEsUZKDJdhlrceRyVU:example.org");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use maplit::btreemap;
|
use maplit::btreemap;
|
||||||
use ruma_common::{event_id, events::receipt::ReceiptType, user_id, MilliSecondsSinceUnixEpoch};
|
use ruma_common::{event_id, events::receipt::ReceiptType, user_id, MilliSecondsSinceUnixEpoch};
|
||||||
@ -32,9 +32,9 @@ fn deserialize_ephemeral_typing() {
|
|||||||
"type": "m.typing"
|
"type": "m.typing"
|
||||||
});
|
});
|
||||||
|
|
||||||
let typing_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
||||||
Ok(AnyEphemeralRoomEvent::Typing(typing_event)) => typing_event
|
Ok(AnyEphemeralRoomEvent::Typing(typing_event))
|
||||||
);
|
);
|
||||||
assert_eq!(typing_event.content.user_ids.len(), 1);
|
assert_eq!(typing_event.content.user_ids.len(), 1);
|
||||||
assert_eq!(typing_event.content.user_ids[0], "@carl:example.com");
|
assert_eq!(typing_event.content.user_ids[0], "@carl:example.com");
|
||||||
@ -83,9 +83,9 @@ fn deserialize_ephemeral_receipt() {
|
|||||||
"type": "m.receipt"
|
"type": "m.receipt"
|
||||||
});
|
});
|
||||||
|
|
||||||
let receipt_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
||||||
Ok(AnyEphemeralRoomEvent::Receipt(receipt_event)) => receipt_event
|
Ok(AnyEphemeralRoomEvent::Receipt(receipt_event))
|
||||||
);
|
);
|
||||||
let receipts = receipt_event.content.0;
|
let receipts = receipt_event.content.0;
|
||||||
assert_eq!(receipts.len(), 1);
|
assert_eq!(receipts.len(), 1);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{AnyMessageLikeEvent, MessageLikeEvent},
|
events::{AnyMessageLikeEvent, MessageLikeEvent},
|
||||||
@ -33,9 +33,9 @@ fn deserialize_message_event() {
|
|||||||
"type": "m.call.answer"
|
"type": "m.call.answer"
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||||
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "unstable-msc3551")]
|
#![cfg(feature = "unstable-msc3551")]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -199,9 +199,9 @@ fn message_event_deserialization() {
|
|||||||
"type": "org.matrix.msc1767.file",
|
"type": "org.matrix.msc1767.file",
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::File(MessageLikeEvent::Original(message_event))) => message_event
|
Ok(AnyMessageLikeEvent::File(MessageLikeEvent::Original(message_event)))
|
||||||
);
|
);
|
||||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||||
let content = message_event.content;
|
let content = message_event.content;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "unstable-msc3552")]
|
#![cfg(feature = "unstable-msc3552")]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -283,9 +283,9 @@ fn message_event_deserialization() {
|
|||||||
"type": "org.matrix.msc1767.image",
|
"type": "org.matrix.msc1767.image",
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::Image(MessageLikeEvent::Original(message_event))) => message_event
|
Ok(AnyMessageLikeEvent::Image(MessageLikeEvent::Original(message_event)))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::events::AnyInitialStateEvent;
|
use ruma_common::events::AnyInitialStateEvent;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
@ -9,6 +9,6 @@ fn deserialize_initial_state_event() {
|
|||||||
"content": { "name": "foo" }
|
"content": { "name": "foo" }
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let ev = assert_matches!(ev, AnyInitialStateEvent::RoomName(ev) => ev);
|
assert_matches!(ev, AnyInitialStateEvent::RoomName(ev));
|
||||||
assert_eq!(ev.content.name.as_deref(), Some("foo"));
|
assert_eq!(ev.content.name.as_deref(), Some("foo"));
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "unstable-msc3488")]
|
#![cfg(feature = "unstable-msc3488")]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -120,11 +120,9 @@ fn zoomlevel_deserialization_pass() {
|
|||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<LocationContent>(json_data).unwrap(),
|
from_json_value::<LocationContent>(json_data).unwrap(),
|
||||||
LocationContent {
|
LocationContent { zoom_level: Some(zoom_level), .. }
|
||||||
zoom_level: Some(zoom_level),
|
|
||||||
..
|
|
||||||
} if zoom_level.get() == uint!(16)
|
|
||||||
);
|
);
|
||||||
|
assert_eq!(zoom_level.get(), uint!(16));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -167,9 +165,7 @@ fn message_event_deserialization() {
|
|||||||
|
|
||||||
let ev = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let ev = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
|
|
||||||
let ev =
|
assert_matches!(ev, AnyMessageLikeEvent::Location(MessageLikeEvent::Original(ev)));
|
||||||
assert_matches!(ev, AnyMessageLikeEvent::Location(MessageLikeEvent::Original(ev)) => ev);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ev.content.text.find_plain(),
|
ev.content.text.find_plain(),
|
||||||
Some("Alice was at geo:51.5008,0.1247;u=35 as of Sat Nov 13 18:50:58 2021")
|
Some("Alice was at geo:51.5008,0.1247;u=35 as of Sat Nov 13 18:50:58 2021")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "unstable-msc1767")]
|
#![cfg(feature = "unstable-msc1767")]
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -229,9 +229,9 @@ fn relates_to_content_deserialization() {
|
|||||||
assert_eq!(content.text.find_plain(), Some("> <@test:example.com> test\n\ntest reply"));
|
assert_eq!(content.text.find_plain(), Some("> <@test:example.com> test\n\ntest reply"));
|
||||||
assert_eq!(content.text.find_html(), None);
|
assert_eq!(content.text.find_html(), None);
|
||||||
|
|
||||||
let event_id = assert_matches!(
|
assert_matches!(
|
||||||
content.relates_to,
|
content.relates_to,
|
||||||
Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. } }) => event_id
|
Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. } })
|
||||||
);
|
);
|
||||||
assert_eq!(event_id, "$15827405538098VGFWH:example.com");
|
assert_eq!(event_id, "$15827405538098VGFWH:example.com");
|
||||||
}
|
}
|
||||||
@ -251,9 +251,9 @@ fn message_event_deserialization() {
|
|||||||
"type": "org.matrix.msc1767.message",
|
"type": "org.matrix.msc1767.message",
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::Message(MessageLikeEvent::Original(message_event))) => message_event
|
Ok(AnyMessageLikeEvent::Message(MessageLikeEvent::Original(message_event)))
|
||||||
);
|
);
|
||||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||||
assert_eq!(message_event.content.text.find_plain(), Some("Hello, World!"));
|
assert_eq!(message_event.content.text.find_plain(), Some("Hello, World!"));
|
||||||
@ -296,9 +296,9 @@ fn emote_event_deserialization() {
|
|||||||
"type": "org.matrix.msc1767.emote",
|
"type": "org.matrix.msc1767.emote",
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::Emote(MessageLikeEvent::Original(message_event))) => message_event
|
Ok(AnyMessageLikeEvent::Emote(MessageLikeEvent::Original(message_event)))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -171,9 +171,9 @@ fn start_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::PollStart(MessageLikeEvent::Original(message_event)) => message_event
|
AnyMessageLikeEvent::PollStart(MessageLikeEvent::Original(message_event))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
message_event.content.text[0].body,
|
message_event.content.text[0].body,
|
||||||
@ -249,18 +249,14 @@ fn response_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
event,
|
event,
|
||||||
AnyMessageLikeEvent::PollResponse(MessageLikeEvent::Original(message_event))
|
AnyMessageLikeEvent::PollResponse(MessageLikeEvent::Original(message_event))
|
||||||
=> message_event
|
|
||||||
);
|
);
|
||||||
let selections = message_event.content.selections;
|
let selections = message_event.content.selections;
|
||||||
assert_eq!(selections.len(), 1);
|
assert_eq!(selections.len(), 1);
|
||||||
assert_eq!(selections[0], "my-answer");
|
assert_eq!(selections[0], "my-answer");
|
||||||
let event_id = assert_matches!(
|
assert_matches!(message_event.content.relates_to, Reference { event_id, .. });
|
||||||
message_event.content.relates_to,
|
|
||||||
Reference { event_id, .. } => event_id
|
|
||||||
);
|
|
||||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,14 +335,8 @@ fn end_event_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
|
||||||
let message_event = assert_matches!(
|
assert_matches!(event, AnyMessageLikeEvent::PollEnd(MessageLikeEvent::Original(message_event)));
|
||||||
event,
|
|
||||||
AnyMessageLikeEvent::PollEnd(MessageLikeEvent::Original(message_event)) => message_event
|
|
||||||
);
|
|
||||||
assert_eq!(message_event.content.text[0].body, "The poll has closed. Top answer: Amazing!");
|
assert_eq!(message_event.content.text[0].body, "The poll has closed. Top answer: Amazing!");
|
||||||
let event_id = assert_matches!(
|
assert_matches!(message_event.content.relates_to, Reference { event_id, .. });
|
||||||
message_event.content.relates_to,
|
|
||||||
Reference { event_id, .. } => event_id
|
|
||||||
);
|
|
||||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{
|
events::{
|
||||||
room::{
|
room::{
|
||||||
@ -60,11 +60,11 @@ fn deserialize_redacted_aliases() {
|
|||||||
"type": "m.room.aliases",
|
"type": "m.room.aliases",
|
||||||
});
|
});
|
||||||
|
|
||||||
let redacted = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(redacted),
|
from_json_value::<AnySyncTimelineEvent>(redacted),
|
||||||
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(
|
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(SyncStateEvent::Redacted(
|
||||||
SyncStateEvent::Redacted(redacted),
|
redacted
|
||||||
))) => redacted
|
),)))
|
||||||
);
|
);
|
||||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(redacted.content.aliases, None);
|
assert_eq!(redacted.content.aliases, None);
|
||||||
@ -82,11 +82,11 @@ fn deserialize_redacted_any_room() {
|
|||||||
"type": "m.room.message",
|
"type": "m.room.message",
|
||||||
});
|
});
|
||||||
|
|
||||||
let redacted = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(redacted),
|
from_json_value::<AnyTimelineEvent>(redacted),
|
||||||
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
|
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
|
||||||
MessageLikeEvent::Redacted(redacted),
|
MessageLikeEvent::Redacted(redacted),
|
||||||
))) => redacted
|
)))
|
||||||
);
|
);
|
||||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(redacted.room_id, "!roomid:room.com");
|
assert_eq!(redacted.room_id, "!roomid:room.com");
|
||||||
@ -103,11 +103,11 @@ fn deserialize_redacted_any_room_sync() {
|
|||||||
"type": "m.room.message",
|
"type": "m.room.message",
|
||||||
});
|
});
|
||||||
|
|
||||||
let redacted = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(redacted),
|
from_json_value::<AnySyncTimelineEvent>(redacted),
|
||||||
Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
|
Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
|
||||||
SyncMessageLikeEvent::Redacted(redacted),
|
SyncMessageLikeEvent::Redacted(redacted),
|
||||||
))) => redacted
|
)))
|
||||||
);
|
);
|
||||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||||
}
|
}
|
||||||
@ -126,11 +126,11 @@ fn deserialize_redacted_state_event() {
|
|||||||
"type": "m.room.create",
|
"type": "m.room.create",
|
||||||
});
|
});
|
||||||
|
|
||||||
let redacted = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(redacted),
|
from_json_value::<AnySyncTimelineEvent>(redacted),
|
||||||
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomCreate(
|
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomCreate(SyncStateEvent::Redacted(
|
||||||
SyncStateEvent::Redacted(redacted),
|
redacted
|
||||||
))) => redacted
|
),)))
|
||||||
);
|
);
|
||||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(redacted.content.creator, "@carl:example.com");
|
assert_eq!(redacted.content.creator, "@carl:example.com");
|
||||||
@ -148,9 +148,9 @@ fn deserialize_redacted_custom_event() {
|
|||||||
"type": "m.made.up",
|
"type": "m.made.up",
|
||||||
});
|
});
|
||||||
|
|
||||||
let state_ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncTimelineEvent>(redacted),
|
from_json_value::<AnySyncTimelineEvent>(redacted),
|
||||||
Ok(AnySyncTimelineEvent::State(state_ev)) => state_ev
|
Ok(AnySyncTimelineEvent::State(state_ev))
|
||||||
);
|
);
|
||||||
assert_eq!(state_ev.event_id(), "$h29iv0s8:example.com");
|
assert_eq!(state_ev.event_id(), "$h29iv0s8:example.com");
|
||||||
}
|
}
|
||||||
@ -223,12 +223,9 @@ fn redact_state_content() {
|
|||||||
let raw_json = to_raw_json_value(&json).unwrap();
|
let raw_json = to_raw_json_value(&json).unwrap();
|
||||||
let content = RoomCreateEventContent::from_parts("m.room.create", &raw_json).unwrap();
|
let content = RoomCreateEventContent::from_parts("m.room.create", &raw_json).unwrap();
|
||||||
|
|
||||||
let creator = assert_matches!(
|
assert_matches!(
|
||||||
content.redact(&RoomVersionId::V6),
|
content.redact(&RoomVersionId::V6),
|
||||||
RedactedRoomCreateEventContent {
|
RedactedRoomCreateEventContent { creator, .. }
|
||||||
creator,
|
|
||||||
..
|
|
||||||
} => creator
|
|
||||||
);
|
);
|
||||||
assert_eq!(creator, "@carl:example.com");
|
assert_eq!(creator, "@carl:example.com");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{
|
events::{
|
||||||
@ -36,9 +36,9 @@ fn deserialize_redaction() {
|
|||||||
"type": "m.room.redaction"
|
"type": "m.room.redaction"
|
||||||
});
|
});
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::RoomRedaction(RoomRedactionEvent::Original(ev))) => ev
|
Ok(AnyMessageLikeEvent::RoomRedaction(RoomRedactionEvent::Original(ev)))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.content.reason.as_deref(), Some("being very unfriendly"));
|
assert_eq!(ev.content.reason.as_deref(), Some("being very unfriendly"));
|
||||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -21,13 +21,13 @@ fn reply_deserialize() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let event_id = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json),
|
from_json_value::<RoomMessageEventContent>(json),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(_),
|
msgtype: MessageType::Text(_),
|
||||||
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. }, .. }),
|
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. }, .. }),
|
||||||
..
|
..
|
||||||
}) => event_id
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(event_id, "$1598361704261elfgc:localhost");
|
assert_eq!(event_id, "$1598361704261elfgc:localhost");
|
||||||
}
|
}
|
||||||
@ -98,16 +98,16 @@ fn replacement_deserialize() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let replacement = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json),
|
from_json_value::<RoomMessageEventContent>(json),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(_),
|
msgtype: MessageType::Text(_),
|
||||||
relates_to: Some(Relation::Replacement(replacement)),
|
relates_to: Some(Relation::Replacement(replacement)),
|
||||||
..
|
..
|
||||||
}) => replacement
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(replacement.event_id, "$1598361704261elfgc");
|
assert_eq!(replacement.event_id, "$1598361704261elfgc");
|
||||||
let text = assert_matches!(replacement.new_content, MessageType::Text(text) => text);
|
assert_matches!(replacement.new_content, MessageType::Text(text));
|
||||||
assert_eq!(text.body, "Hello! My name is bar");
|
assert_eq!(text.body, "Hello! My name is bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,13 +183,13 @@ fn thread_stable_deserialize() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let thread = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json),
|
from_json_value::<RoomMessageEventContent>(json),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(_),
|
msgtype: MessageType::Text(_),
|
||||||
relates_to: Some(Relation::Thread(thread)),
|
relates_to: Some(Relation::Thread(thread)),
|
||||||
..
|
..
|
||||||
}) => thread
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
||||||
assert_matches!(thread.in_reply_to, None);
|
assert_matches!(thread.in_reply_to, None);
|
||||||
@ -210,13 +210,13 @@ fn thread_stable_reply_deserialize() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let thread = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json),
|
from_json_value::<RoomMessageEventContent>(json),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(_),
|
msgtype: MessageType::Text(_),
|
||||||
relates_to: Some(Relation::Thread(thread)),
|
relates_to: Some(Relation::Thread(thread)),
|
||||||
..
|
..
|
||||||
}) => thread
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
||||||
assert_eq!(thread.in_reply_to.unwrap().event_id, "$latesteventid");
|
assert_eq!(thread.in_reply_to.unwrap().event_id, "$latesteventid");
|
||||||
@ -237,13 +237,13 @@ fn thread_unstable_deserialize() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let thread = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json),
|
from_json_value::<RoomMessageEventContent>(json),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent {
|
||||||
msgtype: MessageType::Text(_),
|
msgtype: MessageType::Text(_),
|
||||||
relates_to: Some(Relation::Thread(thread)),
|
relates_to: Some(Relation::Thread(thread)),
|
||||||
..
|
..
|
||||||
}) => thread
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
||||||
assert_eq!(thread.in_reply_to.unwrap().event_id, "$latesteventid");
|
assert_eq!(thread.in_reply_to.unwrap().event_id, "$latesteventid");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -212,10 +212,7 @@ fn verification_request_msgtype_deserialization() {
|
|||||||
|
|
||||||
let content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
|
|
||||||
let verification = assert_matches!(
|
assert_matches!(content.msgtype, MessageType::VerificationRequest(verification));
|
||||||
content.msgtype,
|
|
||||||
MessageType::VerificationRequest(verification) => verification
|
|
||||||
);
|
|
||||||
assert_eq!(verification.body, "@example:localhost is requesting to verify your key, ...");
|
assert_eq!(verification.body, "@example:localhost is requesting to verify your key, ...");
|
||||||
assert_eq!(verification.to, user_id);
|
assert_eq!(verification.to, user_id);
|
||||||
assert_eq!(verification.from_device, device_id);
|
assert_eq!(verification.from_device, device_id);
|
||||||
@ -272,15 +269,15 @@ fn escape_tags_in_plain_reply_body() {
|
|||||||
let second_message = RoomMessageEventContent::text_plain("Usage: rm <path>")
|
let second_message = RoomMessageEventContent::text_plain("Usage: rm <path>")
|
||||||
.make_reply_to(&first_message, ForwardThread::Yes);
|
.make_reply_to(&first_message, ForwardThread::Yes);
|
||||||
|
|
||||||
let body = assert_matches!(
|
assert_matches!(
|
||||||
first_message.content.msgtype,
|
first_message.content.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted: None, .. }) => body
|
MessageType::Text(TextMessageEventContent { body, formatted: None, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(body, "Usage: cp <source> <destination>");
|
assert_eq!(body, "Usage: cp <source> <destination>");
|
||||||
|
|
||||||
let (body, formatted) = assert_matches!(
|
assert_matches!(
|
||||||
second_message.msgtype,
|
second_message.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
|
MessageType::Text(TextMessageEventContent { body, formatted, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
body,
|
body,
|
||||||
@ -340,17 +337,17 @@ fn reply_sanitize() {
|
|||||||
)
|
)
|
||||||
.make_reply_to(&second_message, ForwardThread::Yes);
|
.make_reply_to(&second_message, ForwardThread::Yes);
|
||||||
|
|
||||||
let (body, formatted) = assert_matches!(
|
assert_matches!(
|
||||||
first_message.content.msgtype,
|
first_message.content.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
|
MessageType::Text(TextMessageEventContent { body, formatted, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(body, "# This is the first message");
|
assert_eq!(body, "# This is the first message");
|
||||||
let formatted = formatted.unwrap();
|
let formatted = formatted.unwrap();
|
||||||
assert_eq!(formatted.body, "<h1>This is the first message</h1>");
|
assert_eq!(formatted.body, "<h1>This is the first message</h1>");
|
||||||
|
|
||||||
let (body, formatted) = assert_matches!(
|
assert_matches!(
|
||||||
second_message.content.msgtype,
|
second_message.content.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
|
MessageType::Text(TextMessageEventContent { body, formatted, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
body,
|
body,
|
||||||
@ -375,9 +372,9 @@ fn reply_sanitize() {
|
|||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
|
||||||
let (body, formatted) = assert_matches!(
|
assert_matches!(
|
||||||
final_reply.msgtype,
|
final_reply.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
|
MessageType::Text(TextMessageEventContent { body, formatted, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
body,
|
body,
|
||||||
@ -413,9 +410,9 @@ fn make_replacement_no_reply() {
|
|||||||
|
|
||||||
let content = content.make_replacement(event_id, None);
|
let content = content.make_replacement(event_id, None);
|
||||||
|
|
||||||
let (body, formatted) = assert_matches!(
|
assert_matches!(
|
||||||
content.msgtype,
|
content.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
|
MessageType::Text(TextMessageEventContent { body, formatted, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(body, "* This is _an edited_ message.");
|
assert_eq!(body, "* This is _an edited_ message.");
|
||||||
let formatted = formatted.unwrap();
|
let formatted = formatted.unwrap();
|
||||||
@ -444,9 +441,9 @@ fn make_replacement_with_reply() {
|
|||||||
|
|
||||||
let content = content.make_replacement(event_id, Some(&replied_to_message));
|
let content = content.make_replacement(event_id, Some(&replied_to_message));
|
||||||
|
|
||||||
let (body, formatted) = assert_matches!(
|
assert_matches!(
|
||||||
content.msgtype,
|
content.msgtype,
|
||||||
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
|
MessageType::Text(TextMessageEventContent { body, formatted, .. })
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
body,
|
body,
|
||||||
@ -500,9 +497,9 @@ fn audio_msgtype_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
let content = assert_matches!(event_content.msgtype, MessageType::Audio(content) => content);
|
assert_matches!(event_content.msgtype, MessageType::Audio(content));
|
||||||
assert_eq!(content.body, "Upload: my_song.mp3");
|
assert_eq!(content.body, "Upload: my_song.mp3");
|
||||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
assert_matches!(content.source, MediaSource::Plain(url));
|
||||||
assert_eq!(url, "mxc://notareal.hs/file");
|
assert_eq!(url, "mxc://notareal.hs/file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,9 +581,9 @@ fn file_msgtype_plain_content_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
let content = assert_matches!(event_content.msgtype, MessageType::File(content) => content);
|
assert_matches!(event_content.msgtype, MessageType::File(content));
|
||||||
assert_eq!(content.body, "Upload: my_file.txt");
|
assert_eq!(content.body, "Upload: my_file.txt");
|
||||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
assert_matches!(content.source, MediaSource::Plain(url));
|
||||||
assert_eq!(url, "mxc://notareal.hs/file");
|
assert_eq!(url, "mxc://notareal.hs/file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,9 +610,9 @@ fn file_msgtype_encrypted_content_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
let content = assert_matches!(event_content.msgtype, MessageType::File(content) => content);
|
assert_matches!(event_content.msgtype, MessageType::File(content));
|
||||||
assert_eq!(content.body, "Upload: my_file.txt");
|
assert_eq!(content.body, "Upload: my_file.txt");
|
||||||
let encrypted_file = assert_matches!(content.source, MediaSource::Encrypted(f) => f);
|
assert_matches!(content.source, MediaSource::Encrypted(encrypted_file));
|
||||||
assert_eq!(encrypted_file.url, "mxc://notareal.hs/file");
|
assert_eq!(encrypted_file.url, "mxc://notareal.hs/file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,9 +644,9 @@ fn image_msgtype_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
let content = assert_matches!(event_content.msgtype, MessageType::Image(content) => content);
|
assert_matches!(event_content.msgtype, MessageType::Image(content));
|
||||||
assert_eq!(content.body, "Upload: my_image.jpg");
|
assert_eq!(content.body, "Upload: my_image.jpg");
|
||||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
assert_matches!(content.source, MediaSource::Plain(url));
|
||||||
assert_eq!(url, "mxc://notareal.hs/file");
|
assert_eq!(url, "mxc://notareal.hs/file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -680,8 +677,7 @@ fn location_msgtype_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
let content = assert_matches!(event_content.msgtype, MessageType::Location(c) => c);
|
assert_matches!(event_content.msgtype, MessageType::Location(content));
|
||||||
|
|
||||||
assert_eq!(content.body, "Alice was at geo:51.5008,0.1247;u=35");
|
assert_eq!(content.body, "Alice was at geo:51.5008,0.1247;u=35");
|
||||||
assert_eq!(content.geo_uri, "geo:51.5008,0.1247;u=35");
|
assert_eq!(content.geo_uri, "geo:51.5008,0.1247;u=35");
|
||||||
}
|
}
|
||||||
@ -693,12 +689,9 @@ fn text_msgtype_body_deserialization() {
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json_data),
|
from_json_value::<RoomMessageEventContent>(json_data),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent { msgtype: MessageType::Text(content), .. })
|
||||||
msgtype: MessageType::Text(content),
|
|
||||||
..
|
|
||||||
}) => content
|
|
||||||
);
|
);
|
||||||
assert_eq!(content.body, "test");
|
assert_eq!(content.body, "test");
|
||||||
}
|
}
|
||||||
@ -712,12 +705,9 @@ fn text_msgtype_formatted_body_and_body_deserialization() {
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json_data),
|
from_json_value::<RoomMessageEventContent>(json_data),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent { msgtype: MessageType::Text(content), .. })
|
||||||
msgtype: MessageType::Text(content),
|
|
||||||
..
|
|
||||||
}) => content
|
|
||||||
);
|
);
|
||||||
assert_eq!(content.body, "test");
|
assert_eq!(content.body, "test");
|
||||||
let formatted = content.formatted.unwrap();
|
let formatted = content.formatted.unwrap();
|
||||||
@ -745,12 +735,9 @@ fn notice_msgtype_deserialization() {
|
|||||||
"msgtype": "m.notice",
|
"msgtype": "m.notice",
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json_data),
|
from_json_value::<RoomMessageEventContent>(json_data),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent { msgtype: MessageType::Notice(content), .. })
|
||||||
msgtype: MessageType::Notice(content),
|
|
||||||
..
|
|
||||||
}) => content
|
|
||||||
);
|
);
|
||||||
assert_eq!(content.body, "test");
|
assert_eq!(content.body, "test");
|
||||||
}
|
}
|
||||||
@ -777,12 +764,9 @@ fn emote_msgtype_deserialization() {
|
|||||||
"msgtype": "m.emote",
|
"msgtype": "m.emote",
|
||||||
});
|
});
|
||||||
|
|
||||||
let content = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<RoomMessageEventContent>(json_data),
|
from_json_value::<RoomMessageEventContent>(json_data),
|
||||||
Ok(RoomMessageEventContent {
|
Ok(RoomMessageEventContent { msgtype: MessageType::Emote(content), .. })
|
||||||
msgtype: MessageType::Emote(content),
|
|
||||||
..
|
|
||||||
}) => content
|
|
||||||
);
|
);
|
||||||
assert_eq!(content.body, "test");
|
assert_eq!(content.body, "test");
|
||||||
}
|
}
|
||||||
@ -815,8 +799,8 @@ fn video_msgtype_deserialization() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||||
let content = assert_matches!(event_content.msgtype, MessageType::Video(content) => content);
|
assert_matches!(event_content.msgtype, MessageType::Video(content));
|
||||||
assert_eq!(content.body, "Upload: my_video.mp4");
|
assert_eq!(content.body, "Upload: my_video.mp4");
|
||||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
assert_matches!(content.source, MediaSource::Plain(url));
|
||||||
assert_eq!(url, "mxc://notareal.hs/file");
|
assert_eq!(url, "mxc://notareal.hs/file");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{
|
events::{
|
||||||
@ -44,9 +44,9 @@ fn deserialize_aliases_content() {
|
|||||||
fn deserialize_aliases_with_prev_content() {
|
fn deserialize_aliases_with_prev_content() {
|
||||||
let json_data = aliases_event_with_prev_content();
|
let json_data = aliases_event_with_prev_content();
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyStateEvent>(json_data),
|
from_json_value::<AnyStateEvent>(json_data),
|
||||||
Ok(AnyStateEvent::RoomAliases(StateEvent::Original(ev))) => ev
|
Ok(AnyStateEvent::RoomAliases(StateEvent::Original(ev)))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||||
@ -63,9 +63,9 @@ fn deserialize_aliases_sync_with_room_id() {
|
|||||||
// The same JSON can be used to create a sync event, it just ignores the `room_id` field
|
// The same JSON can be used to create a sync event, it just ignores the `room_id` field
|
||||||
let json_data = aliases_event_with_prev_content();
|
let json_data = aliases_event_with_prev_content();
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnySyncStateEvent>(json_data),
|
from_json_value::<AnySyncStateEvent>(json_data),
|
||||||
Ok(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(ev))) => ev
|
Ok(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(ev)))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||||
@ -103,9 +103,9 @@ fn deserialize_avatar_without_prev_content() {
|
|||||||
"type": "m.room.avatar"
|
"type": "m.room.avatar"
|
||||||
});
|
});
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyStateEvent>(json_data),
|
from_json_value::<AnyStateEvent>(json_data),
|
||||||
Ok(AnyStateEvent::RoomAvatar(StateEvent::Original(ev))) => ev
|
Ok(AnyStateEvent::RoomAvatar(StateEvent::Original(ev)))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||||
@ -148,9 +148,9 @@ fn deserialize_member_event_with_top_level_membership_field() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyTimelineEvent>(json_data),
|
from_json_value::<AnyTimelineEvent>(json_data),
|
||||||
Ok(AnyTimelineEvent::State(AnyStateEvent::RoomMember(StateEvent::Original(ev)))) => ev
|
Ok(AnyTimelineEvent::State(AnyStateEvent::RoomMember(StateEvent::Original(ev))))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||||
@ -163,9 +163,9 @@ fn deserialize_full_event_convert_to_sync() {
|
|||||||
let json_data = aliases_event_with_prev_content();
|
let json_data = aliases_event_with_prev_content();
|
||||||
|
|
||||||
let full_ev: AnyStateEvent = from_json_value(json_data).unwrap();
|
let full_ev: AnyStateEvent = from_json_value(json_data).unwrap();
|
||||||
let sync_ev = assert_matches!(
|
assert_matches!(
|
||||||
AnySyncStateEvent::from(full_ev),
|
AnySyncStateEvent::from(full_ev),
|
||||||
AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(ev)) => ev
|
AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(sync_ev))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(sync_ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
assert_eq!(sync_ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use assign::assign;
|
use assign::assign;
|
||||||
use js_int::{uint, UInt};
|
use js_int::{uint, UInt};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
@ -113,9 +113,9 @@ fn event_deserialization() {
|
|||||||
"type": "m.sticker"
|
"type": "m.sticker"
|
||||||
});
|
});
|
||||||
|
|
||||||
let message_event = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::Sticker(MessageLikeEvent::Original(message_event))) => message_event
|
Ok(AnyMessageLikeEvent::Sticker(MessageLikeEvent::Original(message_event)))
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
||||||
@ -132,10 +132,7 @@ fn event_deserialization() {
|
|||||||
assert_eq!(content.info.size, Some(uint!(84242)));
|
assert_eq!(content.info.size, Some(uint!(84242)));
|
||||||
assert_eq!(content.url, "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD");
|
assert_eq!(content.url, "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD");
|
||||||
|
|
||||||
let thumbnail_url = assert_matches!(
|
assert_matches!(content.info.thumbnail_source, Some(MediaSource::Plain(thumbnail_url)));
|
||||||
content.info.thumbnail_source,
|
|
||||||
Some(MediaSource::Plain(thumbnail_url)) => thumbnail_url
|
|
||||||
);
|
|
||||||
assert_eq!(thumbnail_url, "mxc://matrix.org/irnsNRS2879");
|
assert_eq!(thumbnail_url, "mxc://matrix.org/irnsNRS2879");
|
||||||
let thumbnail_info = content.info.thumbnail_info.unwrap();
|
let thumbnail_info = content.info.thumbnail_info.unwrap();
|
||||||
assert_eq!(thumbnail_info.width, Some(uint!(800)));
|
assert_eq!(thumbnail_info.width, Some(uint!(800)));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
events::{
|
events::{
|
||||||
@ -63,17 +63,17 @@ fn deserialize_stripped_state_events() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let ev = from_json_value::<AnyStrippedStateEvent>(name_event).unwrap();
|
let ev = from_json_value::<AnyStrippedStateEvent>(name_event).unwrap();
|
||||||
let ev = assert_matches!(ev, AnyStrippedStateEvent::RoomName(ev) => ev);
|
assert_matches!(ev, AnyStrippedStateEvent::RoomName(ev));
|
||||||
assert_eq!(ev.content.name.as_deref(), Some("Ruma"));
|
assert_eq!(ev.content.name.as_deref(), Some("Ruma"));
|
||||||
assert_eq!(ev.sender.to_string(), "@example:localhost");
|
assert_eq!(ev.sender.to_string(), "@example:localhost");
|
||||||
|
|
||||||
let ev = from_json_value::<AnyStrippedStateEvent>(join_rules_event).unwrap();
|
let ev = from_json_value::<AnyStrippedStateEvent>(join_rules_event).unwrap();
|
||||||
let ev = assert_matches!(ev,AnyStrippedStateEvent::RoomJoinRules(ev)=>ev );
|
assert_matches!(ev, AnyStrippedStateEvent::RoomJoinRules(ev));
|
||||||
assert_eq!(ev.content.join_rule, JoinRule::Public);
|
assert_eq!(ev.content.join_rule, JoinRule::Public);
|
||||||
assert_eq!(ev.sender.to_string(), "@example:localhost");
|
assert_eq!(ev.sender.to_string(), "@example:localhost");
|
||||||
|
|
||||||
let ev = from_json_value::<AnyStrippedStateEvent>(avatar_event).unwrap();
|
let ev = from_json_value::<AnyStrippedStateEvent>(avatar_event).unwrap();
|
||||||
let ev = assert_matches!(ev, AnyStrippedStateEvent::RoomAvatar(ev) => ev);
|
assert_matches!(ev, AnyStrippedStateEvent::RoomAvatar(ev));
|
||||||
assert_eq!(ev.content.url.unwrap(), mxc_uri!("mxc://example.com/iMag3"));
|
assert_eq!(ev.content.url.unwrap(), mxc_uri!("mxc://example.com/iMag3"));
|
||||||
assert_eq!(ev.sender.to_string(), "@example:localhost");
|
assert_eq!(ev.sender.to_string(), "@example:localhost");
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -291,9 +291,9 @@ fn message_event_deserialization() {
|
|||||||
"type": "org.matrix.msc1767.video",
|
"type": "org.matrix.msc1767.video",
|
||||||
});
|
});
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::Video(MessageLikeEvent::Original(ev))) => ev
|
Ok(AnyMessageLikeEvent::Video(MessageLikeEvent::Original(ev)))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.event_id, "$event:notareal.hs");
|
assert_eq!(ev.event_id, "$event:notareal.hs");
|
||||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
@ -90,9 +90,9 @@ fn message_event_deserialization() {
|
|||||||
"type": "org.matrix.msc3245.voice.v2",
|
"type": "org.matrix.msc3245.voice.v2",
|
||||||
});
|
});
|
||||||
|
|
||||||
let ev = assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||||
Ok(AnyMessageLikeEvent::Voice(MessageLikeEvent::Original(ev))) => ev
|
Ok(AnyMessageLikeEvent::Voice(MessageLikeEvent::Original(ev)))
|
||||||
);
|
);
|
||||||
assert_eq!(ev.event_id, "$event:notareal.hs");
|
assert_eq!(ev.event_id, "$event:notareal.hs");
|
||||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{
|
events::{
|
||||||
@ -31,10 +31,7 @@ fn deserialize_room_message_content_without_relation() {
|
|||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
});
|
});
|
||||||
|
|
||||||
let text = assert_matches!(
|
assert_matches!(from_json_value::<MessageType>(json_data), Ok(MessageType::Text(text)));
|
||||||
from_json_value::<MessageType>(json_data),
|
|
||||||
Ok(MessageType::Text(text)) => text
|
|
||||||
);
|
|
||||||
assert_eq!(text.body, "Hello, world!");
|
assert_eq!(text.body, "Hello, world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,13 +42,9 @@ fn convert_room_message_content_without_relation_to_full() {
|
|||||||
Some(Relation::Reply { in_reply_to: InReplyTo::new(event_id!("$eventId").to_owned()) });
|
Some(Relation::Reply { in_reply_to: InReplyTo::new(event_id!("$eventId").to_owned()) });
|
||||||
let new_content = RoomMessageEventContent::from(MessageType::from(content));
|
let new_content = RoomMessageEventContent::from(MessageType::from(content));
|
||||||
|
|
||||||
let (text, relates_to) = assert_matches!(
|
assert_matches!(
|
||||||
new_content,
|
new_content,
|
||||||
RoomMessageEventContent {
|
RoomMessageEventContent { msgtype: MessageType::Text(text), relates_to, .. }
|
||||||
msgtype: MessageType::Text(text),
|
|
||||||
relates_to,
|
|
||||||
..
|
|
||||||
} => (text, relates_to)
|
|
||||||
);
|
);
|
||||||
assert_eq!(text.body, "Hello, world!");
|
assert_eq!(text.body, "Hello, world!");
|
||||||
assert_matches!(relates_to, None);
|
assert_matches!(relates_to, None);
|
||||||
|
@ -35,5 +35,5 @@ serde = { workspace = true }
|
|||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = { workspace = true }
|
assert_matches2 = { workspace = true }
|
||||||
http = { workspace = true }
|
http = { workspace = true }
|
||||||
|
@ -70,7 +70,7 @@ where
|
|||||||
#[cfg(not(feature = "unstable-unspecified"))]
|
#[cfg(not(feature = "unstable-unspecified"))]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use super::{deserialize, serialize};
|
use super::{deserialize, serialize};
|
||||||
|
@ -314,7 +314,7 @@ impl SigningKeyUpdateContent {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use js_int::uint;
|
use js_int::uint;
|
||||||
use ruma_common::{room_id, user_id};
|
use ruma_common::{room_id, user_id};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -352,17 +352,17 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||||
let DeviceListUpdateContent {
|
assert_matches!(
|
||||||
user_id,
|
|
||||||
device_id,
|
|
||||||
device_display_name,
|
|
||||||
stream_id,
|
|
||||||
prev_id,
|
|
||||||
deleted,
|
|
||||||
keys,
|
|
||||||
} = assert_matches!(
|
|
||||||
&edu,
|
&edu,
|
||||||
Edu::DeviceListUpdate(u) => u
|
Edu::DeviceListUpdate(DeviceListUpdateContent {
|
||||||
|
user_id,
|
||||||
|
device_id,
|
||||||
|
device_display_name,
|
||||||
|
stream_id,
|
||||||
|
prev_id,
|
||||||
|
deleted,
|
||||||
|
keys,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(user_id, "@john:example.com");
|
assert_eq!(user_id, "@john:example.com");
|
||||||
@ -388,17 +388,17 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||||
let DeviceListUpdateContent {
|
assert_matches!(
|
||||||
user_id,
|
|
||||||
device_id,
|
|
||||||
device_display_name,
|
|
||||||
stream_id,
|
|
||||||
prev_id,
|
|
||||||
deleted,
|
|
||||||
keys,
|
|
||||||
} = assert_matches!(
|
|
||||||
&edu,
|
&edu,
|
||||||
Edu::DeviceListUpdate(u) => u
|
Edu::DeviceListUpdate(DeviceListUpdateContent {
|
||||||
|
user_id,
|
||||||
|
device_id,
|
||||||
|
device_display_name,
|
||||||
|
stream_id,
|
||||||
|
prev_id,
|
||||||
|
deleted,
|
||||||
|
keys,
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(user_id, "@john:example.com");
|
assert_eq!(user_id, "@john:example.com");
|
||||||
@ -433,10 +433,7 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||||
let receipts = assert_matches!(
|
assert_matches!(&edu, Edu::Receipt(ReceiptContent { receipts }));
|
||||||
&edu,
|
|
||||||
Edu::Receipt(ReceiptContent { receipts }) => receipts
|
|
||||||
);
|
|
||||||
assert!(receipts.get(room_id!("!some_room:example.org")).is_some());
|
assert!(receipts.get(room_id!("!some_room:example.org")).is_some());
|
||||||
|
|
||||||
assert_eq!(serde_json::to_value(&edu).unwrap(), json);
|
assert_eq!(serde_json::to_value(&edu).unwrap(), json);
|
||||||
@ -454,10 +451,7 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||||
let content = assert_matches!(
|
assert_matches!(&edu, Edu::Typing(content));
|
||||||
&edu,
|
|
||||||
Edu::Typing(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(content.room_id, "!somewhere:matrix.org");
|
assert_eq!(content.room_id, "!somewhere:matrix.org");
|
||||||
assert_eq!(content.user_id, "@john:matrix.org");
|
assert_eq!(content.user_id, "@john:matrix.org");
|
||||||
assert!(content.typing);
|
assert!(content.typing);
|
||||||
@ -487,10 +481,7 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||||
let content = assert_matches!(
|
assert_matches!(&edu, Edu::DirectToDevice(content));
|
||||||
&edu,
|
|
||||||
Edu::DirectToDevice(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(content.sender, "@john:example.com");
|
assert_eq!(content.sender, "@john:example.com");
|
||||||
assert_eq!(content.ev_type, ToDeviceEventType::RoomKeyRequest);
|
assert_eq!(content.ev_type, ToDeviceEventType::RoomKeyRequest);
|
||||||
assert_eq!(content.message_id, "hiezohf6Hoo7kaev");
|
assert_eq!(content.message_id, "hiezohf6Hoo7kaev");
|
||||||
@ -540,10 +531,7 @@ mod test {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||||
let content = assert_matches!(
|
assert_matches!(&edu, Edu::SigningKeyUpdate(content));
|
||||||
&edu,
|
|
||||||
Edu::SigningKeyUpdate(content) => content
|
|
||||||
);
|
|
||||||
assert_eq!(content.user_id, "@alice:example.com");
|
assert_eq!(content.user_id, "@alice:example.com");
|
||||||
assert!(content.master_key.is_some());
|
assert!(content.master_key.is_some());
|
||||||
assert!(content.self_signing_key.is_some());
|
assert!(content.self_signing_key.is_some());
|
||||||
|
@ -32,4 +32,4 @@ subslice = { version = "0.2.3", optional = true }
|
|||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = { workspace = true }
|
assert_matches2 = { workspace = true }
|
||||||
|
@ -725,7 +725,7 @@ fn is_third_party_invite(object: &CanonicalJsonObject) -> Result<bool, Error> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches2::assert_matches;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
serde::Base64, CanonicalJsonValue, RoomVersionId, ServerSigningKeyId, SigningKeyAlgorithm,
|
serde::Base64, CanonicalJsonValue, RoomVersionId, ServerSigningKeyId, SigningKeyAlgorithm,
|
||||||
};
|
};
|
||||||
@ -910,9 +910,9 @@ mod tests {
|
|||||||
|
|
||||||
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V9);
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V9);
|
||||||
|
|
||||||
let server = assert_matches!(
|
assert_matches!(
|
||||||
verification_result,
|
verification_result,
|
||||||
Err(Error::Verification(VerificationError::SignatureNotFound(server))) => server
|
Err(Error::Verification(VerificationError::SignatureNotFound(server)))
|
||||||
);
|
);
|
||||||
assert_eq!(server, "domain-authorized");
|
assert_eq!(server, "domain-authorized");
|
||||||
}
|
}
|
||||||
@ -947,9 +947,9 @@ mod tests {
|
|||||||
let public_key_map = BTreeMap::new();
|
let public_key_map = BTreeMap::new();
|
||||||
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
||||||
|
|
||||||
let entity = assert_matches!(
|
assert_matches!(
|
||||||
verification_result,
|
verification_result,
|
||||||
Err(Error::Verification(VerificationError::PublicKeyNotFound(entity))) => entity
|
Err(Error::Verification(VerificationError::PublicKeyNotFound(entity)))
|
||||||
);
|
);
|
||||||
assert_eq!(entity, "domain-sender");
|
assert_eq!(entity, "domain-sender");
|
||||||
}
|
}
|
||||||
@ -993,9 +993,9 @@ mod tests {
|
|||||||
|
|
||||||
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
||||||
|
|
||||||
let error = assert_matches!(
|
assert_matches!(
|
||||||
verification_result,
|
verification_result,
|
||||||
Err(Error::Verification(VerificationError::Signature(error))) => error
|
Err(Error::Verification(VerificationError::Signature(error)))
|
||||||
);
|
);
|
||||||
// dalek doesn't expose InternalError :(
|
// dalek doesn't expose InternalError :(
|
||||||
// https://github.com/dalek-cryptography/ed25519-dalek/issues/174
|
// https://github.com/dalek-cryptography/ed25519-dalek/issues/174
|
||||||
|
Loading…
x
Reference in New Issue
Block a user