Split up some test assertions

This commit is contained in:
Jonas Platte 2022-05-25 09:08:48 +02:00 committed by GitHub
parent 22fbb9ee24
commit e50d59f7a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 46 deletions

View File

@ -56,8 +56,9 @@ fn config_with_optional_url() {
aliases: [] aliases: []
rooms: [] rooms: []
"#; "#;
assert_matches!( let url = assert_matches!(
serde_yaml::from_str(registration_config).unwrap(), serde_yaml::from_str(registration_config).unwrap(),
Registration { url, .. } if url == "null" Registration { url, .. } => url
); );
assert_eq!(url, "null");
} }

View File

@ -516,7 +516,7 @@ mod tests {
} }
#[test] #[test]
fn issue_366() -> serde_json::Result<()> { fn issue_366() {
let obj = json!({ let obj = json!({
"lazy_load_members": true, "lazy_load_members": true,
"filter_json": { "contains_url": true, "types": ["m.room.message"] }, "filter_json": { "contains_url": true, "types": ["m.room.message"] },
@ -529,40 +529,24 @@ mod tests {
"contains_url": true, "contains_url": true,
}); });
assert_matches!( let filter: IncomingRoomEventFilter = assert_matches!(from_json_value(obj), Ok(f) => f);
from_json_value(obj)?,
IncomingRoomEventFilter {
types: Some(types),
not_types,
rooms: None,
not_rooms,
senders: None,
not_senders,
limit: None,
url_filter: Some(UrlFilter::EventsWithUrl),
lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: false },
#[cfg(feature = "unstable-msc3440")]
related_by_rel_types,
#[cfg(feature = "unstable-msc3440")]
related_by_senders
} if {
let valid = types == vec!["m.room.message".to_owned()]
&& not_types.is_empty()
&& not_rooms.is_empty()
&& not_senders.is_empty();
#[cfg(not(feature = "unstable-msc3440"))] assert_eq!(filter.types, Some(vec!["m.room.message".to_owned()]));
{ assert_eq!(filter.not_types, vec![""; 0]);
valid assert_eq!(filter.rooms, None);
} assert_eq!(filter.not_rooms, vec![""; 0]);
assert_eq!(filter.senders, None);
#[cfg(feature = "unstable-msc3440")] assert_eq!(filter.not_senders, vec![""; 0]);
{ assert_eq!(filter.limit, None);
valid && related_by_rel_types.is_empty() && related_by_senders.is_empty() assert_eq!(filter.url_filter, Some(UrlFilter::EventsWithUrl));
} assert_eq!(
} filter.lazy_load_options,
LazyLoadOptions::Enabled { include_redundant_members: false }
); );
Ok(()) #[cfg(feature = "unstable-msc3440")]
assert_eq!(filter.related_by_rel_types, vec![]);
#[cfg(feature = "unstable-msc3440")]
assert_eq!(filter.related_by_senders, vec![""; 0]);
} }
} }

View File

@ -66,7 +66,7 @@ pub mod v3 {
use super::IncomingRequest; use super::IncomingRequest;
assert_matches!( let req = assert_matches!(
IncomingRequest::try_from_http_request( IncomingRequest::try_from_http_request(
http::Request::builder() http::Request::builder()
.method(http::Method::POST) .method(http::Method::POST)
@ -75,9 +75,11 @@ pub mod v3 {
.unwrap(), .unwrap(),
&["@foo:bar.com"] &["@foo:bar.com"]
), ),
Ok(IncomingRequest { user_id, filter }) Ok(req) => req
if user_id == "@foo:bar.com" && filter.is_empty()
); );
assert_eq!(req.user_id, "@foo:bar.com");
assert!(req.filter.is_empty());
} }
#[cfg(feature = "client")] #[cfg(feature = "client")]

View File

@ -203,7 +203,7 @@ mod tests {
#[test] #[test]
fn deserialize_string() { fn deserialize_string() {
assert_matches!(from_json_value::<Action>(json!("notify")).unwrap(), Action::Notify); assert_matches!(from_json_value::<Action>(json!("notify")), Ok(Action::Notify));
} }
#[test] #[test]
@ -212,10 +212,11 @@ mod tests {
"set_tweak": "sound", "set_tweak": "sound",
"value": "default" "value": "default"
}); });
assert_matches!( let value = assert_matches!(
&from_json_value::<Action>(json_data).unwrap(), from_json_value::<Action>(json_data),
Action::SetTweak(Tweak::Sound(value)) if value == "default" Ok(Action::SetTweak(Tweak::Sound(value))) => value
); );
assert_eq!(value, "default");
} }
#[test] #[test]
@ -225,16 +226,16 @@ mod tests {
"value": true "value": true
}); });
assert_matches!( assert_matches!(
from_json_value::<Action>(json_data).unwrap(), from_json_value::<Action>(json_data),
Action::SetTweak(Tweak::Highlight(true)) Ok(Action::SetTweak(Tweak::Highlight(true)))
); );
} }
#[test] #[test]
fn deserialize_tweak_highlight_with_default_value() { fn deserialize_tweak_highlight_with_default_value() {
assert_matches!( assert_matches!(
from_json_value::<Action>(json!({ "set_tweak": "highlight" })).unwrap(), from_json_value::<Action>(json!({ "set_tweak": "highlight" })),
Action::SetTweak(Tweak::Highlight(true)) Ok(Action::SetTweak(Tweak::Highlight(true)))
); );
} }
} }