Replace assert_matches by assert_matches2

This commit is contained in:
Jonas Platte 2023-06-08 11:29:41 +02:00
parent a8670e7fdf
commit ba5bf8cfce
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
68 changed files with 380 additions and 628 deletions

View File

@ -5,7 +5,7 @@ default-members = ["crates/*"]
resolver = "2"
[workspace.dependencies]
assert_matches = "1.5.0"
assert_matches2 = "0.1.0"
assign = "1.1.1"
base64 = "0.21.0"
criterion = "0.5.0"

View File

@ -29,5 +29,5 @@ serde = { workspace = true }
serde_json = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
assert_matches2 = { workspace = true }
serde_yaml = "0.9.14"

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_appservice_api::Registration;
#[test]
@ -58,9 +58,6 @@ fn config_with_optional_url() {
aliases: []
rooms: []
"#;
let url = assert_matches!(
serde_yaml::from_str(registration_config).unwrap(),
Registration { url, .. } => url
);
assert_matches!(serde_yaml::from_str(registration_config).unwrap(), Registration { url, .. });
assert_eq!(url, "null");
}

View File

@ -55,4 +55,4 @@ serde_html_form = { workspace = true }
serde_json = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
assert_matches2 = { workspace = true }

View File

@ -296,7 +296,7 @@ impl Default for ThirdPartyIdChangesCapability {
mod tests {
use std::borrow::Cow;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use serde_json::json;
use super::Capabilities;

View File

@ -537,7 +537,7 @@ mod tests {
#[cfg(feature = "unstable-msc2967")]
#[test]
fn deserialize_insufficient_scope() {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::api::EndpointError;
use super::{AuthenticateError, Error, ErrorBody};
@ -559,14 +559,10 @@ mod tests {
let error = Error::from_http_response(response);
assert_eq!(error.status_code, http::StatusCode::UNAUTHORIZED);
let (kind, message) =
assert_matches!(error.body, ErrorBody::Standard { kind, message } => (kind, message));
assert_matches!(error.body, ErrorBody::Standard { kind, message });
assert_eq!(kind, ErrorKind::Forbidden);
assert_eq!(message, "Insufficient privilege");
let scope = assert_matches::assert_matches!(
error.authenticate,
Some(AuthenticateError::InsufficientScope { scope }) => scope
);
assert_matches!(error.authenticate, Some(AuthenticateError::InsufficientScope { scope }));
assert_eq!(scope, "something_privileged");
}
}

View File

@ -368,7 +368,6 @@ can_be_empty!(RoomFilter);
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::{
@ -421,7 +420,7 @@ mod tests {
"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.not_types, vec![""; 0]);

View File

@ -76,7 +76,7 @@ pub mod v3 {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use serde_json::{
from_value as from_json_value, json,
value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue},

View File

@ -82,7 +82,7 @@ pub mod v3 {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::thirdparty::Medium;
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" }))
.unwrap();
let user_id = assert_matches!(
incoming,
InvitationRecipient::UserId { user_id } => user_id
);
assert_matches!(incoming, InvitationRecipient::UserId { user_id });
assert_eq!(user_id, "@carl:example.org");
}
@ -111,10 +108,7 @@ pub mod v3 {
}))
.unwrap();
let third_party_id = assert_matches!(
incoming,
InvitationRecipient::ThirdPartyId(id) => id
);
assert_matches!(incoming, InvitationRecipient::ThirdPartyId(third_party_id));
assert_eq!(third_party_id.id_server, "example.org");
assert_eq!(third_party_id.id_access_token, "abcdefghijklmnop");

View File

@ -79,7 +79,7 @@ impl<'de> Deserialize<'de> for PusherKind {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::{push::HttpPusherData, serde::JsonObject};
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!(
from_json_value(json).unwrap(),
PusherKind::Http(data) => data
);
assert_matches!(from_json_value(json).unwrap(), PusherKind::Http(data));
assert_eq!(data.url, "http://localhost");
assert_eq!(data.format, None);
}
@ -164,9 +160,7 @@ mod tests {
"data": {}
});
let custom =
assert_matches!(from_json_value(json).unwrap(), PusherKind::_Custom(custom) => custom);
assert_matches!(from_json_value(json).unwrap(), PusherKind::_Custom(custom));
assert_eq!(custom.kind, "my.custom.kind");
assert!(custom.data.is_empty());
}

View File

@ -67,7 +67,7 @@ impl<'de> Deserialize<'de> for PusherAction {
#[cfg(test)]
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 super::PusherAction;
@ -130,11 +130,7 @@ mod tests {
"data": {}
});
let post_data = assert_matches!(
from_json_value(json).unwrap(),
PusherAction::Post(post_data) => post_data
);
assert_matches!(from_json_value(json).unwrap(), PusherAction::Post(post_data));
assert!(!post_data.append);
let pusher = post_data.pusher;
@ -155,11 +151,7 @@ mod tests {
"kind": null,
});
let ids = assert_matches!(
from_json_value(json).unwrap(),
PusherAction::Delete(ids) => ids
);
assert_matches!(from_json_value(json).unwrap(), PusherAction::Delete(ids));
assert_eq!(ids.pushkey, "abcdef");
assert_eq!(ids.app_id, "my.matrix.app");
}

View File

@ -316,7 +316,7 @@ pub mod v3 {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::mxc_uri;
use serde::{Deserialize, Serialize};
use serde_json::{
@ -341,7 +341,7 @@ pub mod v3 {
}))
.unwrap();
assert_eq!(wrapper.flows.len(), 1);
assert_matches!(wrapper.flows[0], LoginType::Password(_));
assert_matches!(&wrapper.flows[0], LoginType::Password(_));
}
#[test]
@ -356,10 +356,7 @@ pub mod v3 {
}))
.unwrap();
assert_eq!(wrapper.flows.len(), 1);
let custom = assert_matches!(
&wrapper.flows[0],
LoginType::_Custom(custom) => custom
);
assert_matches!(&wrapper.flows[0], LoginType::_Custom(custom));
assert_eq!(custom.type_, "io.ruma.custom");
assert_eq!(custom.data.len(), 1);
assert_eq!(custom.data.get("color"), Some(&JsonValue::from("green")));
@ -390,10 +387,7 @@ pub mod v3 {
assert_eq!(wrapper.flows.len(), 1);
let flow = &wrapper.flows[0];
let identity_providers = assert_matches!(
flow,
LoginType::Sso(SsoLoginType { identity_providers }) => identity_providers
);
assert_matches!(flow, LoginType::Sso(SsoLoginType { identity_providers }));
assert_eq!(identity_providers.len(), 2);
let provider = &identity_providers[0];

View File

@ -356,7 +356,7 @@ pub mod v3 {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use serde_json::{from_value as from_json_value, json};
use super::{LoginInfo, Token};
@ -364,7 +364,7 @@ pub mod v3 {
#[test]
fn deserialize_login_type() {
let login = assert_matches!(
assert_matches!(
from_json_value(json!({
"type": "m.login.password",
"identifier": {
@ -374,22 +374,19 @@ pub mod v3 {
"password": "ilovebananas"
}))
.unwrap(),
LoginInfo::Password(login) => login
);
let user = assert_matches!(
login.identifier,
UserIdentifier::UserIdOrLocalpart(user) => user
LoginInfo::Password(login)
);
assert_matches!(login.identifier, UserIdentifier::UserIdOrLocalpart(user));
assert_eq!(user, "cheeky_monkey");
assert_eq!(login.password, "ilovebananas");
let token = assert_matches!(
assert_matches!(
from_json_value(json!({
"type": "m.login.token",
"token": "1234567890abcdef"
}))
.unwrap(),
LoginInfo::Token(Token { token }) => token
LoginInfo::Token(Token { token })
);
assert_eq!(token, "1234567890abcdef");
}

View File

@ -657,7 +657,7 @@ mod client_tests {
mod server_tests {
use std::time::Duration;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::{api::IncomingRequest as _, presence::PresenceState};
use super::{Filter, Request};
@ -684,7 +684,7 @@ mod server_tests {
)
.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!(req.since.as_deref(), Some("myts"));
assert!(!req.full_state);
@ -733,7 +733,7 @@ mod server_tests {
)
.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!(req.since, None);
assert!(!req.full_state);

View File

@ -105,7 +105,7 @@ impl<'de> Deserialize<'de> for UserIdentifier {
#[cfg(test)]
mod tests {
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};
#[test]
@ -168,10 +168,7 @@ mod tests {
"type": "m.id.user",
"user": "@user:notareal.hs",
});
let user = assert_matches!(
from_json_value(json),
Ok(UserIdentifier::UserIdOrLocalpart(user)) => user
);
assert_matches!(from_json_value(json), Ok(UserIdentifier::UserIdOrLocalpart(user)));
assert_eq!(user, "@user:notareal.hs");
let json = json!({
@ -179,10 +176,7 @@ mod tests {
"country": "33",
"phone": "0102030405",
});
let (country, phone) = assert_matches!(
from_json_value(json),
Ok(UserIdentifier::PhoneNumber { country, phone }) => (country, phone)
);
assert_matches!(from_json_value(json), Ok(UserIdentifier::PhoneNumber { country, phone }));
assert_eq!(country, "33");
assert_eq!(phone, "0102030405");
@ -191,10 +185,7 @@ mod tests {
"medium": "email",
"address": "me@myprovider.net",
});
let address = assert_matches!(
from_json_value(json),
Ok(UserIdentifier::Email { address }) => address
);
assert_matches!(from_json_value(json), Ok(UserIdentifier::Email { address }));
assert_eq!(address, "me@myprovider.net");
let json = json!({
@ -202,10 +193,7 @@ mod tests {
"medium": "msisdn",
"address": "330102030405",
});
let number = assert_matches!(
from_json_value(json),
Ok(UserIdentifier::Msisdn { number }) => number
);
assert_matches!(from_json_value(json), Ok(UserIdentifier::Msisdn { number }));
assert_eq!(number, "330102030405");
let json = json!({

View File

@ -1,6 +1,6 @@
#![cfg(any(feature = "client", feature = "server"))]
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use assign::assign;
use ruma_client_api::{
error::ErrorKind,
@ -14,13 +14,13 @@ use serde_json::{
#[test]
fn deserialize_user_identifier() {
let id = assert_matches!(
assert_matches!(
from_json_value(json!({
"type": "m.id.user",
"user": "cheeky_monkey"
}))
.unwrap(),
UserIdentifier::UserIdOrLocalpart(id) => id
UserIdentifier::UserIdOrLocalpart(id)
);
assert_eq!(id, "cheeky_monkey");
}
@ -50,10 +50,7 @@ fn deserialize_auth_data_registration_token() {
"session": "session",
});
let data = assert_matches!(
from_json_value(json),
Ok(AuthData::RegistrationToken(data)) => data
);
assert_matches!(from_json_value(json), Ok(AuthData::RegistrationToken(data)));
assert_eq!(data.token, "mytoken");
assert_eq!(data.session.as_deref(), Some("session"));
}
@ -70,10 +67,7 @@ fn serialize_auth_data_fallback() {
fn deserialize_auth_data_fallback() {
let json = json!({ "session": "opaque_session_id" });
let data = assert_matches!(
from_json_value(json).unwrap(),
AuthData::FallbackAcknowledgement(data) => data
);
assert_matches!(from_json_value(json).unwrap(), AuthData::FallbackAcknowledgement(data));
assert_eq!(data.session, "opaque_session_id");
}
@ -203,9 +197,9 @@ fn try_uiaa_response_from_http_response() {
.body(json.as_bytes())
.unwrap();
let info = assert_matches!(
assert_matches!(
UiaaResponse::from_http_response(http_response),
UiaaResponse::AuthResponse(info) => info
UiaaResponse::AuthResponse(info)
);
assert_eq!(info.completed, vec![AuthType::ReCaptcha]);
assert_eq!(info.flows.len(), 2);

View File

@ -104,7 +104,7 @@ criterion = { workspace = true, optional = true }
js-sys = { version = "0.3", optional = true }
[dev-dependencies]
assert_matches = { workspace = true }
assert_matches2 = { workspace = true }
assign = { workspace = true }
http = { workspace = true }
maplit = { workspace = true }

View File

@ -699,7 +699,7 @@ impl Display for MatrixVersion {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use http::Method;
use super::{

View File

@ -225,7 +225,7 @@ where
#[cfg(test)]
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 super::{Filter, RoomNetwork, RoomTypeFilter};
@ -326,7 +326,7 @@ mod tests {
assert_eq!(filter.room_types.len(), 3);
assert_eq!(filter.room_types[0], RoomTypeFilter::Default);
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"));
}
}

View File

@ -91,7 +91,7 @@
//!
//! // 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.
//! assert_matches::assert_matches!(
//! assert!(matches!(
//! serde_json::from_value::<OriginalSyncMessageLikeEvent<ReactionEventContent>>(json),
//! Ok(OriginalSyncMessageLikeEvent {
//! content: ReactionEventContent {
@ -99,7 +99,7 @@
//! },
//! ..
//! }) if key == "👍"
//! );
//! ));
//! ```
use serde::{de::IgnoredAny, Deserialize, Serializer};

View File

@ -51,7 +51,7 @@ impl IgnoredUser {
#[cfg(test)]
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 super::IgnoredUserListEventContent;
@ -82,9 +82,9 @@ mod tests {
"type": "m.ignored_user_list"
});
let ev = assert_matches!(
assert_matches!(
from_json_value::<AnyGlobalAccountDataEvent>(json),
Ok(AnyGlobalAccountDataEvent::IgnoredUserList(ev)) => ev
Ok(AnyGlobalAccountDataEvent::IgnoredUserList(ev))
);
assert_eq!(
ev.content.ignored_users.keys().collect::<Vec<_>>(),

View File

@ -163,7 +163,7 @@ impl From<SasV1ContentInit> for SasV1Content {
mod tests {
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, Value as JsonValue,
};
@ -270,10 +270,7 @@ mod tests {
let content = from_json_value::<ToDeviceKeyVerificationAcceptEventContent>(json).unwrap();
assert_eq!(content.transaction_id, "456");
let sas = assert_matches!(
content.method,
AcceptMethod::SasV1(sas) => sas
);
assert_matches!(content.method, AcceptMethod::SasV1(sas));
assert_eq!(sas.commitment.encode(), "aGVsbG8");
assert_eq!(sas.hash, HashAlgorithm::Sha256);
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
@ -299,10 +296,7 @@ mod tests {
assert_eq!(ev.content.transaction_id, "456");
assert_eq!(ev.sender, "@example:localhost");
let sas = assert_matches!(
ev.content.method,
AcceptMethod::SasV1(sas) => sas
);
assert_matches!(ev.content.method, AcceptMethod::SasV1(sas));
assert_eq!(sas.commitment.encode(), "aGVsbG8");
assert_eq!(sas.hash, HashAlgorithm::Sha256);
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);
@ -325,10 +319,7 @@ mod tests {
assert_eq!(ev.content.transaction_id, "456");
assert_eq!(ev.sender, "@example:localhost");
let custom = assert_matches!(
ev.content.method,
AcceptMethod::_Custom(custom) => custom
);
assert_matches!(ev.content.method, AcceptMethod::_Custom(custom));
assert_eq!(custom.method, "m.sas.custom");
assert_eq!(custom.data.get("test"), Some(&JsonValue::from("field")));
}
@ -352,10 +343,7 @@ mod tests {
let content = from_json_value::<KeyVerificationAcceptEventContent>(json).unwrap();
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
let sas = assert_matches!(
content.method,
AcceptMethod::SasV1(sas) => sas
);
assert_matches!(content.method, AcceptMethod::SasV1(sas));
assert_eq!(sas.commitment.encode(), "aGVsbG8");
assert_eq!(sas.hash, HashAlgorithm::Sha256);
assert_eq!(sas.key_agreement_protocol, KeyAgreementProtocol::Curve25519);

View File

@ -208,7 +208,7 @@ impl From<SasV1ContentInit> for SasV1Content {
mod tests {
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, Value as JsonValue,
};
@ -364,10 +364,7 @@ mod tests {
assert_eq!(content.from_device, "123");
assert_eq!(content.transaction_id, "456");
let sas = assert_matches!(
content.method,
StartMethod::SasV1(sas) => sas
);
assert_matches!(content.method, StartMethod::SasV1(sas));
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
assert_eq!(
@ -396,10 +393,7 @@ mod tests {
assert_eq!(ev.content.from_device, "123");
assert_eq!(ev.content.transaction_id, "456");
let sas = assert_matches!(
ev.content.method,
StartMethod::SasV1(sas) => sas
);
assert_matches!(ev.content.method, StartMethod::SasV1(sas));
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
assert_eq!(
@ -425,10 +419,7 @@ mod tests {
assert_eq!(ev.content.from_device, "123");
assert_eq!(ev.content.transaction_id, "456");
let custom = assert_matches!(
ev.content.method,
StartMethod::_Custom(custom) => custom
);
assert_matches!(ev.content.method, StartMethod::_Custom(custom));
assert_eq!(custom.method, "m.sas.custom");
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.transaction_id, "456");
let reciprocate = assert_matches!(
ev.content.method,
StartMethod::ReciprocateV1(reciprocate) => reciprocate
);
assert_matches!(ev.content.method, StartMethod::ReciprocateV1(reciprocate));
assert_eq!(reciprocate.secret.encode(), "c2VjcmV0Cg");
}
@ -476,10 +464,7 @@ mod tests {
assert_eq!(content.from_device, "123");
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
let sas = assert_matches!(
content.method,
StartMethod::SasV1(sas) => sas
);
assert_matches!(content.method, StartMethod::SasV1(sas));
assert_eq!(sas.hashes, vec![HashAlgorithm::Sha256]);
assert_eq!(sas.key_agreement_protocols, vec![KeyAgreementProtocol::Curve25519]);
assert_eq!(
@ -502,10 +487,7 @@ mod tests {
assert_eq!(content.from_device, "123");
assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
let reciprocate = assert_matches!(
content.method,
StartMethod::ReciprocateV1(reciprocate) => reciprocate
);
assert_matches!(content.method, StartMethod::ReciprocateV1(reciprocate));
assert_eq!(reciprocate.secret.encode(), "c2VjcmV0Cg");
}
}

View File

@ -36,7 +36,7 @@ impl From<Annotation> for ReactionEventContent {
#[cfg(test)]
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 super::ReactionEventContent;
@ -52,9 +52,9 @@ mod tests {
}
});
let relates_to = assert_matches!(
assert_matches!(
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.key, "🦛");

View File

@ -211,7 +211,7 @@ where
#[cfg(test)]
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 super::{Receipt, ReceiptThread};
@ -251,7 +251,7 @@ mod tests {
let receipt = from_json_value::<Receipt>(json!({ "thread_id": "$abcdef76543" })).unwrap();
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");
let receipt = from_json_value::<Receipt>(json!({ "ts": 1_664_702_144_365_u64 })).unwrap();
@ -269,7 +269,7 @@ mod tests {
receipt.ts.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");
}
}

View File

@ -281,7 +281,7 @@ impl From<JsonWebKeyInit> for JsonWebKey {
mod tests {
use std::collections::BTreeMap;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use serde::Deserialize;
use serde_json::{from_value as from_json_value, json};

View File

@ -87,7 +87,7 @@ fn default_room_version_id() -> RoomVersionId {
#[cfg(test)]
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 super::{RoomCreateEventContent, RoomType};

View File

@ -243,7 +243,7 @@ impl From<MegolmV1AesSha2ContentInit> for MegolmV1AesSha2Content {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
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 scheme = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(scheme) => scheme
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(scheme));
assert_eq!(scheme.ciphertext, "ciphertext");
assert_eq!(scheme.sender_key, "sender_key");
assert_eq!(scheme.device_id, "device_id");
assert_eq!(scheme.session_id, "session_id");
let in_reply_to = assert_matches!(
content.relates_to,
Some(Relation::Reply { in_reply_to }) => in_reply_to
);
assert_matches!(content.relates_to, Some(Relation::Reply { in_reply_to }));
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 c = assert_matches!(
content.scheme,
EncryptedEventScheme::OlmV1Curve25519AesSha2(c) => c
);
assert_matches!(content.scheme, EncryptedEventScheme::OlmV1Curve25519AesSha2(c));
assert_eq!(c.sender_key, "test_key");
assert_eq!(c.ciphertext.len(), 1);
assert_eq!(c.ciphertext["test_curve_key"].body, "encrypted_body");

View File

@ -245,7 +245,7 @@ impl<'de> Deserialize<'de> for AllowRule {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use super::{AllowRule, JoinRule, OriginalSyncRoomJoinRulesEvent, RoomJoinRulesEventContent};
use crate::room_id;

View File

@ -535,7 +535,7 @@ impl CanBeEmpty for RoomMemberUnsigned {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use maplit::btreemap;
use serde_json::{from_value as from_json_value, json};

View File

@ -29,7 +29,7 @@ impl RoomNameEventContent {
#[cfg(test)]
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 super::RoomNameEventContent;

View File

@ -51,7 +51,7 @@ where
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use serde::{Deserialize, Serialize};
use serde_json::json;
@ -71,9 +71,9 @@ mod tests {
fn deserialize_plain() {
let json = json!({ "thumbnail_url": "mxc://notareal.hs/abcdef" });
let url = assert_matches!(
assert_matches!(
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");
}
@ -98,9 +98,9 @@ mod tests {
},
});
let file = assert_matches!(
assert_matches!(
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");
}

View File

@ -134,7 +134,7 @@ pub enum SecretName {
#[cfg(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 super::{RequestAction, SecretName, ToDeviceSecretRequestEventContent};
@ -222,10 +222,7 @@ mod test {
let content = from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap();
assert_eq!(content.requesting_device_id, "ABCDEFG");
assert_eq!(content.request_id, "randomly_generated_id_9573");
let secret = assert_matches!(
content.action,
RequestAction::Request(secret) => secret
);
assert_matches!(content.action, RequestAction::Request(secret));
assert_eq!(secret.as_str(), "org.example.some.secret");
}
@ -255,10 +252,7 @@ mod test {
let content = from_json_value::<ToDeviceSecretRequestEventContent>(json).unwrap();
assert_eq!(content.requesting_device_id, "XYZxyz");
assert_eq!(content.request_id, "this_is_a_request_id");
let secret = assert_matches!(
content.action,
RequestAction::Request(secret) => secret
);
assert_matches!(content.action, RequestAction::Request(secret));
assert_eq!(secret, SecretName::RecoveryKey);
}

View File

@ -96,7 +96,7 @@ pub enum SecretEncryptionAlgorithm {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use serde_json::{
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_matches!(content.passphrase, None);
let (iv, mac) = assert_matches!(
assert_matches!(
content.algorithm,
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
iv,
mac,
} => (iv, mac)
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
@ -171,12 +168,9 @@ mod tests {
assert!(content.name.is_none());
assert_matches!(content.passphrase, None);
let (iv, mac) = assert_matches!(
assert_matches!(
content.algorithm,
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
iv,
mac,
} => (iv, mac)
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
@ -237,12 +231,9 @@ mod tests {
assert_eq!(passphrase.iterations, uint!(8));
assert_eq!(passphrase.bits, uint!(256));
let (iv, mac) = assert_matches!(
assert_matches!(
content.algorithm,
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
iv,
mac,
} => (iv, mac)
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");
@ -287,12 +278,9 @@ mod tests {
assert_eq!(ev.content.name.unwrap(), "my_key");
assert_matches!(ev.content.passphrase, None);
let (iv, mac) = assert_matches!(
assert_matches!(
ev.content.algorithm,
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 {
iv,
mac,
} => (iv, mac)
SecretEncryptionAlgorithm::SecretStorageV1AesHmacSha2 { iv, mac }
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
assert_eq!(mac.encode(), "aWRvbnRrbm93d2hhdGFtYWNsb29rc2xpa2U");

View File

@ -44,7 +44,7 @@ pub enum SecretEncryptedData {
mod tests {
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 super::{SecretEncryptedData, SecretEventContent};
@ -91,13 +91,9 @@ mod tests {
let deserialized: SecretEventContent = from_json_value(json).unwrap();
let secret_data = deserialized.encrypted.get("key_one").unwrap();
let (iv, ciphertext, mac) = assert_matches!(
assert_matches!(
secret_data,
SecretEncryptedData::AesHmacSha2EncryptedData {
iv,
ciphertext,
mac
} => (iv, ciphertext, mac)
SecretEncryptedData::AesHmacSha2EncryptedData { iv, ciphertext, mac }
);
assert_eq!(iv.encode(), "YWJjZGVmZ2hpamtsbW5vcA");
assert_eq!(ciphertext.encode(), "dGhpc2lzZGVmaW5pdGVseWNpcGhlcnRleHQ");

View File

@ -540,7 +540,7 @@ impl FromStr for MatrixUri {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_identifiers_validation::{
error::{MatrixIdError, MatrixToError, MatrixUriError},
Error,

View File

@ -150,7 +150,7 @@ impl From<String> for VoipVersionId {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -177,10 +177,7 @@ mod tests {
#[test]
fn valid_custom_string_version() {
let version = assert_matches!(
VoipVersionId::try_from("io.ruma.2"),
Ok(version) => version
);
assert_matches!(VoipVersionId::try_from("io.ruma.2"), Ok(version));
assert_eq!(version.as_ref(), "io.ruma.2");
}

View File

@ -977,7 +977,7 @@ pub enum RemovePushRuleError {
mod tests {
use std::collections::BTreeMap;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::{int, uint};
use serde_json::{
from_value as from_json_value, json, to_value as to_json_value,
@ -1043,25 +1043,25 @@ mod tests {
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
);
assert_eq!(rule_id, ".m.rule.call");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
);
assert_eq!(rule_id, "!roomid:matrix.org");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
);
assert_eq!(rule_id, ".m.rule.suppress_notices");
@ -1314,10 +1314,7 @@ mod tests {
let mut iter = rule.actions.iter();
assert_matches!(iter.next(), Some(Action::Notify));
let sound = assert_matches!(
iter.next(),
Some(Action::SetTweak(Tweak::Sound(sound))) => sound
);
assert_matches!(iter.next(), Some(Action::SetTweak(Tweak::Sound(sound))));
assert_eq!(sound, "default");
assert_matches!(iter.next(), Some(Action::SetTweak(Tweak::Highlight(true))));
assert_matches!(iter.next(), None);
@ -1383,49 +1380,40 @@ mod tests {
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
);
assert_eq!(rule_id, "!roomid:server.name");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Override(ConditionalPushRule { rule_id, .. }) => rule_id
AnyPushRule::Override(ConditionalPushRule { rule_id, .. })
);
assert_eq!(rule_id, ".m.rule.call");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Content(PatternedPushRule { rule_id, .. }) => rule_id
);
assert_matches!(rule_opt.unwrap(), AnyPushRule::Content(PatternedPushRule { rule_id, .. }));
assert_eq!(rule_id, ".m.rule.contains_user_name");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Content(PatternedPushRule { rule_id, .. }) => rule_id
);
assert_matches!(rule_opt.unwrap(), AnyPushRule::Content(PatternedPushRule { rule_id, .. }));
assert_eq!(rule_id, "ruma");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
rule_opt.unwrap(),
AnyPushRule::Room(SimplePushRule { rule_id, .. }) => rule_id
);
assert_matches!(rule_opt.unwrap(), AnyPushRule::Room(SimplePushRule { rule_id, .. }));
assert_eq!(rule_id, "!roomid:server.name");
let rule_opt = iter.next();
assert!(rule_opt.is_some());
let rule_id = assert_matches!(
assert_matches!(
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");
@ -1633,8 +1621,8 @@ mod tests {
assert_matches!(
test_set.get_actions(&message, context_one_to_one),
[Action::SetTweak(Tweak::Sound(sound))]
if sound == "content"
);
assert_eq!(sound, "content");
let three_conditions = ConditionalPushRule {
actions: vec![Action::SetTweak(Tweak::Sound("three".into()))],
@ -1652,9 +1640,9 @@ mod tests {
};
set.override_.insert(three_conditions);
let sound = assert_matches!(
assert_matches!(
set.get_actions(&message, context_one_to_one),
[Action::SetTweak(Tweak::Sound(sound))] => sound
[Action::SetTweak(Tweak::Sound(sound))]
);
assert_eq!(sound, "content");
@ -1670,9 +1658,9 @@ mod tests {
)
.unwrap();
let sound = assert_matches!(
assert_matches!(
set.get_actions(&new_message, context_one_to_one),
[Action::SetTweak(Tweak::Sound(sound))] => sound
[Action::SetTweak(Tweak::Sound(sound))]
);
assert_eq!(sound, "three");
}

View File

@ -182,7 +182,7 @@ mod tweak_serde {
#[cfg(test)]
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 super::{Action, Tweak};
@ -224,9 +224,9 @@ mod tests {
"set_tweak": "sound",
"value": "default"
});
let value = assert_matches!(
assert_matches!(
from_json_value::<Action>(json_data),
Ok(Action::SetTweak(Tweak::Sound(value))) => value
Ok(Action::SetTweak(Tweak::Sound(value)))
);
assert_eq!(value, "default");
}

View File

@ -444,7 +444,7 @@ impl StrExt for str {
mod tests {
use std::collections::BTreeMap;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::{int, uint};
use serde_json::{
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",
"pattern": "m.notice"
});
let (key, pattern) = assert_matches!(
assert_matches!(
from_json_value::<PushCondition>(json_data).unwrap(),
PushCondition::EventMatch { key, pattern } => (key, pattern)
PushCondition::EventMatch { key, pattern }
);
assert_eq!(key, "content.msgtype");
assert_eq!(pattern, "m.notice");
@ -533,9 +533,9 @@ mod tests {
"is": "2",
"kind": "room_member_count"
});
let is = assert_matches!(
assert_matches!(
from_json_value::<PushCondition>(json_data).unwrap(),
PushCondition::RoomMemberCount { is } => is
PushCondition::RoomMemberCount { is }
);
assert_eq!(is, RoomMemberCountIs::from(uint!(2)));
}
@ -546,9 +546,9 @@ mod tests {
"key": "room",
"kind": "sender_notification_permission"
});
let key = assert_matches!(
assert_matches!(
from_json_value::<PushCondition>(json_data).unwrap(),
PushCondition::SenderNotificationPermission { key } => key
PushCondition::SenderNotificationPermission { key }
);
assert_eq!(key, "room");
}

View File

@ -596,7 +596,7 @@ pub enum PredefinedContentRuleId {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use assign::assign;
use super::PredefinedOverrideRuleId;
@ -647,7 +647,7 @@ mod tests {
// `enabled` and `actions` have been copied from the old rules.
assert!(master_rule.enabled);
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.
let user_rule = ruleset.override_.get(user_rule_id).unwrap();

View File

@ -2,7 +2,7 @@
use std::time::Duration;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
#[cfg(feature = "unstable-msc3246")]
use ruma_common::events::audio::Amplitude;
@ -287,9 +287,9 @@ fn message_event_deserialization() {
"type": "org.matrix.msc1767.audio",
});
let message_event = assert_matches!(
assert_matches!(
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");

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
#[cfg(feature = "unstable-msc2747")]
use assign::assign;
use js_int::uint;
@ -81,9 +81,9 @@ fn answer_v0_event_deserialization() {
"type": "m.call.answer"
});
let message_event = assert_matches!(
assert_matches!(
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.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 message_event = assert_matches!(
assert_matches!(
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.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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallInvite(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallInvite(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallAnswer(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallCandidates(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallCandidates(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallHangup(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallHangup(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallNegotiate(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallNegotiate(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallReject(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallReject(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
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 message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::CallSelectAnswer(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::CallSelectAnswer(MessageLikeEvent::Original(message_event))
);
let content = message_event.content;
assert_eq!(content.call_id, "abcdef");

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::{
device_id, event_id,
events::{
@ -67,10 +67,7 @@ fn content_no_relation_deserialization() {
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
let encrypted_content = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(content) => content
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
assert_eq!(
encrypted_content.ciphertext,
@ -138,10 +135,7 @@ fn content_reply_deserialization() {
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
let encrypted_content = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(content) => content
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
assert_eq!(
encrypted_content.ciphertext,
@ -153,10 +147,7 @@ fn content_reply_deserialization() {
lDl5mzVO3tPnJMKZ0hn+AF"
);
let in_reply_to = assert_matches!(
content.relates_to,
Some(Relation::Reply { in_reply_to }) => in_reply_to
);
assert_matches!(content.relates_to, Some(Relation::Reply { in_reply_to }));
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 encrypted_content = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(content) => content
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
assert_eq!(
encrypted_content.ciphertext,
@ -224,10 +212,7 @@ fn content_replacement_deserialization() {
lDl5mzVO3tPnJMKZ0hn+AF"
);
let replacement = assert_matches!(
content.relates_to,
Some(Relation::Replacement(replacement)) => replacement
);
assert_matches!(content.relates_to, Some(Relation::Replacement(replacement)));
assert_eq!(replacement.event_id, "$replaced_event");
}
@ -280,10 +265,7 @@ fn content_reference_deserialization() {
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
let encrypted_content = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(content) => content
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
assert_eq!(
encrypted_content.ciphertext,
@ -295,10 +277,7 @@ fn content_reference_deserialization() {
lDl5mzVO3tPnJMKZ0hn+AF"
);
let reference = assert_matches!(
content.relates_to,
Some(Relation::Reference(reference)) => reference
);
assert_matches!(content.relates_to, Some(Relation::Reference(reference)));
assert_eq!(reference.event_id, "$referenced_event");
}
@ -361,10 +340,7 @@ fn content_thread_deserialization() {
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
let encrypted_content = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(content) => content
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
assert_eq!(
encrypted_content.ciphertext,
@ -376,10 +352,7 @@ fn content_thread_deserialization() {
lDl5mzVO3tPnJMKZ0hn+AF"
);
let thread = assert_matches!(
content.relates_to,
Some(Relation::Thread(thread)) => thread
);
assert_matches!(content.relates_to, Some(Relation::Thread(thread)));
assert_eq!(thread.event_id, "$thread_root");
assert_eq!(thread.in_reply_to.unwrap().event_id, "$prev_event");
assert!(!thread.is_falling_back);
@ -441,10 +414,7 @@ fn content_annotation_deserialization() {
let content = from_json_value::<RoomEncryptedEventContent>(json).unwrap();
let encrypted_content = assert_matches!(
content.scheme,
EncryptedEventScheme::MegolmV1AesSha2(content) => content
);
assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(encrypted_content));
assert_eq!(encrypted_content.session_id, "IkwqWxT2zy3DI1E/zM2Wq+CE8tr3eEpsxsVGjGrMPdw");
assert_eq!(
encrypted_content.ciphertext,
@ -456,10 +426,7 @@ fn content_annotation_deserialization() {
lDl5mzVO3tPnJMKZ0hn+AF"
);
let annotation = assert_matches!(
content.relates_to,
Some(Relation::Annotation(annotation)) => annotation
);
assert_matches!(content.relates_to, Some(Relation::Annotation(annotation)));
assert_eq!(annotation.event_id, "$annotated_event");
assert_eq!(annotation.key, "some_key");
}

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::int;
use ruma_common::{
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),
Ok(AnySyncTimelineEvent::State(
AnySyncStateEvent::RoomPowerLevels(SyncStateEvent::Original(
OriginalSyncStateEvent {
content: RoomPowerLevelsEventContent {
ban, ..
},
..
},
)),
)) => ban
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomPowerLevels(
SyncStateEvent::Original(OriginalSyncStateEvent {
content: RoomPowerLevelsEventContent { ban, .. },
..
},)
),))
);
assert_eq!(ban, int!(50));
}
@ -142,19 +138,14 @@ fn power_event_sync_deserialization() {
fn message_event_sync_deserialization() {
let json_data = message_event_sync();
let text_content = assert_matches!(
assert_matches!(
from_json_value::<AnySyncTimelineEvent>(json_data),
Ok(AnySyncTimelineEvent::MessageLike(
AnySyncMessageLikeEvent::RoomMessage(SyncMessageLikeEvent::Original(
OriginalSyncMessageLikeEvent {
content: RoomMessageEventContent {
msgtype: MessageType::Text(text_content),
..
},
..
},
))
)) => text_content
Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
SyncMessageLikeEvent::Original(OriginalSyncMessageLikeEvent {
content: RoomMessageEventContent { msgtype: MessageType::Text(text_content), .. },
..
},)
)))
);
assert_eq!(text_content.body, "baba");
let formatted = text_content.formatted.unwrap();
@ -165,11 +156,11 @@ fn message_event_sync_deserialization() {
fn aliases_event_sync_deserialization() {
let json_data = aliases_event_sync();
let ev = assert_matches!(
assert_matches!(
from_json_value::<AnySyncTimelineEvent>(json_data),
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(
ev,
)))) => ev
))))
);
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() {
let json_data = message_event();
let text_content = assert_matches!(
assert_matches!(
from_json_value::<AnyTimelineEvent>(json_data),
Ok(AnyTimelineEvent::MessageLike(
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(
OriginalMessageLikeEvent {
content: RoomMessageEventContent {
msgtype: MessageType::Text(text_content),
..
},
..
},
))
)) => text_content
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
MessageLikeEvent::Original(OriginalMessageLikeEvent {
content: RoomMessageEventContent { msgtype: MessageType::Text(text_content), .. },
..
},)
)))
);
assert_eq!(text_content.body, "baba");
let formatted = text_content.formatted.unwrap();
@ -212,17 +198,11 @@ fn message_event_serialization() {
fn alias_room_event_deserialization() {
let json_data = aliases_event();
let aliases = assert_matches!(
assert_matches!(
from_json_value::<AnyTimelineEvent>(json_data),
Ok(AnyTimelineEvent::State(
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
content: RoomAliasesEventContent {
aliases,
..
},
..
}))
)) => aliases
Ok(AnyTimelineEvent::State(AnyStateEvent::RoomAliases(StateEvent::Original(
OriginalStateEvent { content: RoomAliasesEventContent { aliases, .. }, .. }
))))
);
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
}
@ -231,17 +211,14 @@ fn alias_room_event_deserialization() {
fn message_event_deserialization() {
let json_data = message_event();
let text_content = assert_matches!(
assert_matches!(
from_json_value::<AnyTimelineEvent>(json_data),
Ok(AnyTimelineEvent::MessageLike(
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(OriginalMessageLikeEvent {
content: RoomMessageEventContent {
msgtype: MessageType::Text(text_content),
..
},
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
MessageLikeEvent::Original(OriginalMessageLikeEvent {
content: RoomMessageEventContent { msgtype: MessageType::Text(text_content), .. },
..
}))
)) => text_content
})
)))
);
assert_eq!(text_content.body, "baba");
let formatted = text_content.formatted.unwrap();
@ -252,17 +229,11 @@ fn message_event_deserialization() {
fn alias_event_deserialization() {
let json_data = aliases_event();
let aliases = assert_matches!(
assert_matches!(
from_json_value::<AnyTimelineEvent>(json_data),
Ok(AnyTimelineEvent::State(
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
content: RoomAliasesEventContent {
aliases,
..
},
..
}))
)) => aliases
Ok(AnyTimelineEvent::State(AnyStateEvent::RoomAliases(StateEvent::Original(
OriginalStateEvent { content: RoomAliasesEventContent { aliases, .. }, .. }
))))
);
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
}
@ -271,9 +242,9 @@ fn alias_event_deserialization() {
fn alias_event_field_access() {
let json_data = aliases_event();
let state_event = assert_matches!(
assert_matches!(
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.room_id(), "!room:room.com");
@ -281,7 +252,7 @@ fn alias_event_field_access() {
assert_eq!(state_event.sender(), "@example:localhost");
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!(deser.event_type().to_string(), "m.room.aliases");
}
@ -299,9 +270,9 @@ fn ephemeral_event_deserialization() {
"type": "m.typing"
});
let ephem = assert_matches!(
assert_matches!(
from_json_value::<AnyEphemeralRoomEvent>(json_data),
Ok(ephem @ AnyEphemeralRoomEvent::Typing(_)) => ephem
Ok(ephem @ AnyEphemeralRoomEvent::Typing(_))
);
assert_eq!(ephem.room_id(), "!jEsUZKDJdhlrceRyVU:example.org");
}

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use maplit::btreemap;
use ruma_common::{event_id, events::receipt::ReceiptType, user_id, MilliSecondsSinceUnixEpoch};
@ -32,9 +32,9 @@ fn deserialize_ephemeral_typing() {
"type": "m.typing"
});
let typing_event = assert_matches!(
assert_matches!(
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[0], "@carl:example.com");
@ -83,9 +83,9 @@ fn deserialize_ephemeral_receipt() {
"type": "m.receipt"
});
let receipt_event = assert_matches!(
assert_matches!(
from_json_value::<AnyEphemeralRoomEvent>(json_data),
Ok(AnyEphemeralRoomEvent::Receipt(receipt_event)) => receipt_event
Ok(AnyEphemeralRoomEvent::Receipt(receipt_event))
);
let receipts = receipt_event.content.0;
assert_eq!(receipts.len(), 1);

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
events::{AnyMessageLikeEvent, MessageLikeEvent},
@ -33,9 +33,9 @@ fn deserialize_message_event() {
"type": "m.call.answer"
});
let message_event = assert_matches!(
assert_matches!(
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");

View File

@ -1,6 +1,6 @@
#![cfg(feature = "unstable-msc3551")]
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
event_id,
@ -199,9 +199,9 @@ fn message_event_deserialization() {
"type": "org.matrix.msc1767.file",
});
let message_event = assert_matches!(
assert_matches!(
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");
let content = message_event.content;

View File

@ -1,6 +1,6 @@
#![cfg(feature = "unstable-msc3552")]
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
event_id,
@ -283,9 +283,9 @@ fn message_event_deserialization() {
"type": "org.matrix.msc1767.image",
});
let message_event = assert_matches!(
assert_matches!(
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");

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::events::AnyInitialStateEvent;
use serde_json::json;
@ -9,6 +9,6 @@ fn deserialize_initial_state_event() {
"content": { "name": "foo" }
}))
.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"));
}

View File

@ -1,6 +1,6 @@
#![cfg(feature = "unstable-msc3488")]
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use assign::assign;
use js_int::uint;
use ruma_common::{
@ -120,11 +120,9 @@ fn zoomlevel_deserialization_pass() {
assert_matches!(
from_json_value::<LocationContent>(json_data).unwrap(),
LocationContent {
zoom_level: Some(zoom_level),
..
} if zoom_level.get() == uint!(16)
LocationContent { zoom_level: Some(zoom_level), .. }
);
assert_eq!(zoom_level.get(), uint!(16));
}
#[test]
@ -167,9 +165,7 @@ fn message_event_deserialization() {
let ev = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let ev =
assert_matches!(ev, AnyMessageLikeEvent::Location(MessageLikeEvent::Original(ev)) => ev);
assert_matches!(ev, AnyMessageLikeEvent::Location(MessageLikeEvent::Original(ev)));
assert_eq!(
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")

View File

@ -1,6 +1,6 @@
#![cfg(feature = "unstable-msc1767")]
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use assign::assign;
use js_int::uint;
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_html(), None);
let event_id = assert_matches!(
assert_matches!(
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");
}
@ -251,9 +251,9 @@ fn message_event_deserialization() {
"type": "org.matrix.msc1767.message",
});
let message_event = assert_matches!(
assert_matches!(
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.content.text.find_plain(), Some("Hello, World!"));
@ -296,9 +296,9 @@ fn emote_event_deserialization() {
"type": "org.matrix.msc1767.emote",
});
let message_event = assert_matches!(
assert_matches!(
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");

View File

@ -2,7 +2,7 @@
use std::collections::BTreeMap;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
event_id,
@ -171,9 +171,9 @@ fn start_event_deserialization() {
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::PollStart(MessageLikeEvent::Original(message_event)) => message_event
AnyMessageLikeEvent::PollStart(MessageLikeEvent::Original(message_event))
);
assert_eq!(
message_event.content.text[0].body,
@ -249,18 +249,14 @@ fn response_event_deserialization() {
});
let event = from_json_value::<AnyMessageLikeEvent>(json_data).unwrap();
let message_event = assert_matches!(
assert_matches!(
event,
AnyMessageLikeEvent::PollResponse(MessageLikeEvent::Original(message_event))
=> message_event
);
let selections = message_event.content.selections;
assert_eq!(selections.len(), 1);
assert_eq!(selections[0], "my-answer");
let event_id = assert_matches!(
message_event.content.relates_to,
Reference { event_id, .. } => event_id
);
assert_matches!(message_event.content.relates_to, Reference { event_id, .. });
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 message_event = assert_matches!(
event,
AnyMessageLikeEvent::PollEnd(MessageLikeEvent::Original(message_event)) => message_event
);
assert_matches!(event, AnyMessageLikeEvent::PollEnd(MessageLikeEvent::Original(message_event)));
assert_eq!(message_event.content.text[0].body, "The poll has closed. Top answer: Amazing!");
let event_id = assert_matches!(
message_event.content.relates_to,
Reference { event_id, .. } => event_id
);
assert_matches!(message_event.content.relates_to, Reference { event_id, .. });
assert_eq!(event_id, "$related_event:notareal.hs");
}

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::{
events::{
room::{
@ -60,11 +60,11 @@ fn deserialize_redacted_aliases() {
"type": "m.room.aliases",
});
let redacted = assert_matches!(
assert_matches!(
from_json_value::<AnySyncTimelineEvent>(redacted),
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(
SyncStateEvent::Redacted(redacted),
))) => redacted
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomAliases(SyncStateEvent::Redacted(
redacted
),)))
);
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
assert_eq!(redacted.content.aliases, None);
@ -82,11 +82,11 @@ fn deserialize_redacted_any_room() {
"type": "m.room.message",
});
let redacted = assert_matches!(
assert_matches!(
from_json_value::<AnyTimelineEvent>(redacted),
Ok(AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
MessageLikeEvent::Redacted(redacted),
))) => redacted
)))
);
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
assert_eq!(redacted.room_id, "!roomid:room.com");
@ -103,11 +103,11 @@ fn deserialize_redacted_any_room_sync() {
"type": "m.room.message",
});
let redacted = assert_matches!(
assert_matches!(
from_json_value::<AnySyncTimelineEvent>(redacted),
Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
SyncMessageLikeEvent::Redacted(redacted),
))) => redacted
)))
);
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
}
@ -126,11 +126,11 @@ fn deserialize_redacted_state_event() {
"type": "m.room.create",
});
let redacted = assert_matches!(
assert_matches!(
from_json_value::<AnySyncTimelineEvent>(redacted),
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomCreate(
SyncStateEvent::Redacted(redacted),
))) => redacted
Ok(AnySyncTimelineEvent::State(AnySyncStateEvent::RoomCreate(SyncStateEvent::Redacted(
redacted
),)))
);
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
assert_eq!(redacted.content.creator, "@carl:example.com");
@ -148,9 +148,9 @@ fn deserialize_redacted_custom_event() {
"type": "m.made.up",
});
let state_ev = assert_matches!(
assert_matches!(
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");
}
@ -223,12 +223,9 @@ fn redact_state_content() {
let raw_json = to_raw_json_value(&json).unwrap();
let content = RoomCreateEventContent::from_parts("m.room.create", &raw_json).unwrap();
let creator = assert_matches!(
assert_matches!(
content.redact(&RoomVersionId::V6),
RedactedRoomCreateEventContent {
creator,
..
} => creator
RedactedRoomCreateEventContent { creator, .. }
);
assert_eq!(creator, "@carl:example.com");
}

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
events::{
@ -36,9 +36,9 @@ fn deserialize_redaction() {
"type": "m.room.redaction"
});
let ev = assert_matches!(
assert_matches!(
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.event_id, "$h29iv0s8:example.com");

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use assign::assign;
use ruma_common::{
event_id,
@ -21,13 +21,13 @@ fn reply_deserialize() {
},
});
let event_id = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(_),
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. }, .. }),
..
}) => event_id
})
);
assert_eq!(event_id, "$1598361704261elfgc:localhost");
}
@ -98,16 +98,16 @@ fn replacement_deserialize() {
},
});
let replacement = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(_),
relates_to: Some(Relation::Replacement(replacement)),
..
}) => replacement
})
);
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");
}
@ -183,13 +183,13 @@ fn thread_stable_deserialize() {
},
});
let thread = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(_),
relates_to: Some(Relation::Thread(thread)),
..
}) => thread
})
);
assert_eq!(thread.event_id, "$1598361704261elfgc");
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),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(_),
relates_to: Some(Relation::Thread(thread)),
..
}) => thread
})
);
assert_eq!(thread.event_id, "$1598361704261elfgc");
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),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(_),
relates_to: Some(Relation::Thread(thread)),
..
}) => thread
})
);
assert_eq!(thread.event_id, "$1598361704261elfgc");
assert_eq!(thread.in_reply_to.unwrap().event_id, "$latesteventid");

View File

@ -1,6 +1,6 @@
use std::borrow::Cow;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
event_id,
@ -212,10 +212,7 @@ fn verification_request_msgtype_deserialization() {
let content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let verification = assert_matches!(
content.msgtype,
MessageType::VerificationRequest(verification) => verification
);
assert_matches!(content.msgtype, MessageType::VerificationRequest(verification));
assert_eq!(verification.body, "@example:localhost is requesting to verify your key, ...");
assert_eq!(verification.to, user_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>")
.make_reply_to(&first_message, ForwardThread::Yes);
let body = assert_matches!(
assert_matches!(
first_message.content.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted: None, .. }) => body
MessageType::Text(TextMessageEventContent { body, formatted: None, .. })
);
assert_eq!(body, "Usage: cp <source> <destination>");
let (body, formatted) = assert_matches!(
assert_matches!(
second_message.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
MessageType::Text(TextMessageEventContent { body, formatted, .. })
);
assert_eq!(
body,
@ -340,17 +337,17 @@ fn reply_sanitize() {
)
.make_reply_to(&second_message, ForwardThread::Yes);
let (body, formatted) = assert_matches!(
assert_matches!(
first_message.content.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
MessageType::Text(TextMessageEventContent { body, formatted, .. })
);
assert_eq!(body, "# This is the first message");
let formatted = formatted.unwrap();
assert_eq!(formatted.body, "<h1>This is the first message</h1>");
let (body, formatted) = assert_matches!(
assert_matches!(
second_message.content.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
MessageType::Text(TextMessageEventContent { body, formatted, .. })
);
assert_eq!(
body,
@ -375,9 +372,9 @@ fn reply_sanitize() {
"
);
let (body, formatted) = assert_matches!(
assert_matches!(
final_reply.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
MessageType::Text(TextMessageEventContent { body, formatted, .. })
);
assert_eq!(
body,
@ -413,9 +410,9 @@ fn make_replacement_no_reply() {
let content = content.make_replacement(event_id, None);
let (body, formatted) = assert_matches!(
assert_matches!(
content.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
MessageType::Text(TextMessageEventContent { body, formatted, .. })
);
assert_eq!(body, "* This is _an edited_ message.");
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 (body, formatted) = assert_matches!(
assert_matches!(
content.msgtype,
MessageType::Text(TextMessageEventContent { body, formatted, .. }) => (body, formatted)
MessageType::Text(TextMessageEventContent { body, formatted, .. })
);
assert_eq!(
body,
@ -500,9 +497,9 @@ fn audio_msgtype_deserialization() {
});
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");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_matches!(content.source, MediaSource::Plain(url));
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 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");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_matches!(content.source, MediaSource::Plain(url));
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 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");
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");
}
@ -647,9 +644,9 @@ fn image_msgtype_deserialization() {
});
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");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_matches!(content.source, MediaSource::Plain(url));
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 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.geo_uri, "geo:51.5008,0.1247;u=35");
}
@ -693,12 +689,9 @@ fn text_msgtype_body_deserialization() {
"msgtype": "m.text",
});
let content = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(content),
..
}) => content
Ok(RoomMessageEventContent { msgtype: MessageType::Text(content), .. })
);
assert_eq!(content.body, "test");
}
@ -712,12 +705,9 @@ fn text_msgtype_formatted_body_and_body_deserialization() {
"msgtype": "m.text",
});
let content = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(content),
..
}) => content
Ok(RoomMessageEventContent { msgtype: MessageType::Text(content), .. })
);
assert_eq!(content.body, "test");
let formatted = content.formatted.unwrap();
@ -745,12 +735,9 @@ fn notice_msgtype_deserialization() {
"msgtype": "m.notice",
});
let content = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Notice(content),
..
}) => content
Ok(RoomMessageEventContent { msgtype: MessageType::Notice(content), .. })
);
assert_eq!(content.body, "test");
}
@ -777,12 +764,9 @@ fn emote_msgtype_deserialization() {
"msgtype": "m.emote",
});
let content = assert_matches!(
assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Emote(content),
..
}) => content
Ok(RoomMessageEventContent { msgtype: MessageType::Emote(content), .. })
);
assert_eq!(content.body, "test");
}
@ -815,8 +799,8 @@ fn video_msgtype_deserialization() {
});
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");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_matches!(content.source, MediaSource::Plain(url));
assert_eq!(url, "mxc://notareal.hs/file");
}

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
events::{
@ -44,9 +44,9 @@ fn deserialize_aliases_content() {
fn deserialize_aliases_with_prev_content() {
let json_data = aliases_event_with_prev_content();
let ev = assert_matches!(
assert_matches!(
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.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
let json_data = aliases_event_with_prev_content();
let ev = assert_matches!(
assert_matches!(
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.event_id, "$h29iv0s8:example.com");
@ -103,9 +103,9 @@ fn deserialize_avatar_without_prev_content() {
"type": "m.room.avatar"
});
let ev = assert_matches!(
assert_matches!(
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.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),
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.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 full_ev: AnyStateEvent = from_json_value(json_data).unwrap();
let sync_ev = assert_matches!(
assert_matches!(
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")]);

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use assign::assign;
use js_int::{uint, UInt};
use ruma_common::{
@ -113,9 +113,9 @@ fn event_deserialization() {
"type": "m.sticker"
});
let message_event = assert_matches!(
assert_matches!(
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");
@ -132,10 +132,7 @@ fn event_deserialization() {
assert_eq!(content.info.size, Some(uint!(84242)));
assert_eq!(content.url, "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD");
let thumbnail_url = assert_matches!(
content.info.thumbnail_source,
Some(MediaSource::Plain(thumbnail_url)) => thumbnail_url
);
assert_matches!(content.info.thumbnail_source, Some(MediaSource::Plain(thumbnail_url)));
assert_eq!(thumbnail_url, "mxc://matrix.org/irnsNRS2879");
let thumbnail_info = content.info.thumbnail_info.unwrap();
assert_eq!(thumbnail_info.width, Some(uint!(800)));

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
events::{
@ -63,17 +63,17 @@ fn deserialize_stripped_state_events() {
});
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.sender.to_string(), "@example:localhost");
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.sender.to_string(), "@example:localhost");
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.sender.to_string(), "@example:localhost");

View File

@ -2,7 +2,7 @@
use std::time::Duration;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
event_id,
@ -291,9 +291,9 @@ fn message_event_deserialization() {
"type": "org.matrix.msc1767.video",
});
let ev = assert_matches!(
assert_matches!(
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.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));

View File

@ -2,7 +2,7 @@
use std::time::Duration;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{
event_id,
@ -90,9 +90,9 @@ fn message_event_deserialization() {
"type": "org.matrix.msc3245.voice.v2",
});
let ev = assert_matches!(
assert_matches!(
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.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));

View File

@ -1,4 +1,4 @@
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::{
event_id,
events::{
@ -31,10 +31,7 @@ fn deserialize_room_message_content_without_relation() {
"msgtype": "m.text",
});
let text = assert_matches!(
from_json_value::<MessageType>(json_data),
Ok(MessageType::Text(text)) => text
);
assert_matches!(from_json_value::<MessageType>(json_data), Ok(MessageType::Text(text)));
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()) });
let new_content = RoomMessageEventContent::from(MessageType::from(content));
let (text, relates_to) = assert_matches!(
assert_matches!(
new_content,
RoomMessageEventContent {
msgtype: MessageType::Text(text),
relates_to,
..
} => (text, relates_to)
RoomMessageEventContent { msgtype: MessageType::Text(text), relates_to, .. }
);
assert_eq!(text.body, "Hello, world!");
assert_matches!(relates_to, None);

View File

@ -35,5 +35,5 @@ serde = { workspace = true }
serde_json = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
assert_matches2 = { workspace = true }
http = { workspace = true }

View File

@ -70,7 +70,7 @@ where
#[cfg(not(feature = "unstable-unspecified"))]
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use serde_json::json;
use super::{deserialize, serialize};

View File

@ -314,7 +314,7 @@ impl SigningKeyUpdateContent {
#[cfg(test)]
mod test {
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use js_int::uint;
use ruma_common::{room_id, user_id};
use serde_json::json;
@ -352,17 +352,17 @@ mod test {
});
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
let DeviceListUpdateContent {
user_id,
device_id,
device_display_name,
stream_id,
prev_id,
deleted,
keys,
} = assert_matches!(
assert_matches!(
&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");
@ -388,17 +388,17 @@ mod test {
});
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
let DeviceListUpdateContent {
user_id,
device_id,
device_display_name,
stream_id,
prev_id,
deleted,
keys,
} = assert_matches!(
assert_matches!(
&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");
@ -433,10 +433,7 @@ mod test {
});
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
let receipts = assert_matches!(
&edu,
Edu::Receipt(ReceiptContent { receipts }) => receipts
);
assert_matches!(&edu, Edu::Receipt(ReceiptContent { receipts }));
assert!(receipts.get(room_id!("!some_room:example.org")).is_some());
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 content = assert_matches!(
&edu,
Edu::Typing(content) => content
);
assert_matches!(&edu, Edu::Typing(content));
assert_eq!(content.room_id, "!somewhere:matrix.org");
assert_eq!(content.user_id, "@john:matrix.org");
assert!(content.typing);
@ -487,10 +481,7 @@ mod test {
});
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
let content = assert_matches!(
&edu,
Edu::DirectToDevice(content) => content
);
assert_matches!(&edu, Edu::DirectToDevice(content));
assert_eq!(content.sender, "@john:example.com");
assert_eq!(content.ev_type, ToDeviceEventType::RoomKeyRequest);
assert_eq!(content.message_id, "hiezohf6Hoo7kaev");
@ -540,10 +531,7 @@ mod test {
});
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
let content = assert_matches!(
&edu,
Edu::SigningKeyUpdate(content) => content
);
assert_matches!(&edu, Edu::SigningKeyUpdate(content));
assert_eq!(content.user_id, "@alice:example.com");
assert!(content.master_key.is_some());
assert!(content.self_signing_key.is_some());

View File

@ -32,4 +32,4 @@ subslice = { version = "0.2.3", optional = true }
thiserror = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
assert_matches2 = { workspace = true }

View File

@ -725,7 +725,7 @@ fn is_third_party_invite(object: &CanonicalJsonObject) -> Result<bool, Error> {
mod tests {
use std::collections::BTreeMap;
use assert_matches::assert_matches;
use assert_matches2::assert_matches;
use ruma_common::{
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 server = assert_matches!(
assert_matches!(
verification_result,
Err(Error::Verification(VerificationError::SignatureNotFound(server))) => server
Err(Error::Verification(VerificationError::SignatureNotFound(server)))
);
assert_eq!(server, "domain-authorized");
}
@ -947,9 +947,9 @@ mod tests {
let public_key_map = BTreeMap::new();
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
let entity = assert_matches!(
assert_matches!(
verification_result,
Err(Error::Verification(VerificationError::PublicKeyNotFound(entity))) => entity
Err(Error::Verification(VerificationError::PublicKeyNotFound(entity)))
);
assert_eq!(entity, "domain-sender");
}
@ -993,9 +993,9 @@ mod tests {
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
let error = assert_matches!(
assert_matches!(
verification_result,
Err(Error::Verification(VerificationError::Signature(error))) => error
Err(Error::Verification(VerificationError::Signature(error)))
);
// dalek doesn't expose InternalError :(
// https://github.com/dalek-cryptography/ed25519-dalek/issues/174