identifiers: Test server_name function in room_id tests

This commit is contained in:
Jonas Platte 2023-09-28 11:56:53 +02:00
parent 984cbda962
commit d78f56e85c
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C

View File

@ -203,29 +203,25 @@ impl RoomId {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{OwnedRoomId, RoomId}; use super::{OwnedRoomId, RoomId};
use crate::IdParseError; use crate::{server_name, IdParseError};
#[test] #[test]
fn valid_room_id() { fn valid_room_id() {
assert_eq!( let room_id =
<&RoomId>::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId."), <&RoomId>::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.");
"!29fhd83h92h0:example.com" assert_eq!(room_id, "!29fhd83h92h0:example.com");
);
} }
#[test] #[test]
fn empty_localpart() { fn empty_localpart() {
assert_eq!( let room_id = <&RoomId>::try_from("!:example.com").expect("Failed to create RoomId.");
<&RoomId>::try_from("!:example.com").expect("Failed to create RoomId."), assert_eq!(room_id, "!:example.com");
"!:example.com" assert_eq!(room_id.server_name(), Some(server_name!("example.com")));
);
} }
#[cfg(feature = "rand")] #[cfg(feature = "rand")]
#[test] #[test]
fn generate_random_valid_room_id() { fn generate_random_valid_room_id() {
use crate::server_name;
let room_id = RoomId::new(server_name!("example.com")); let room_id = RoomId::new(server_name!("example.com"));
let id_str = room_id.as_str(); let id_str = room_id.as_str();
@ -255,10 +251,10 @@ mod tests {
#[test] #[test]
fn valid_room_id_with_explicit_standard_port() { fn valid_room_id_with_explicit_standard_port() {
assert_eq!( let room_id =
<&RoomId>::try_from("!29fhd83h92h0:example.com:443").expect("Failed to create RoomId."), <&RoomId>::try_from("!29fhd83h92h0:example.com:443").expect("Failed to create RoomId.");
"!29fhd83h92h0:example.com:443" assert_eq!(room_id, "!29fhd83h92h0:example.com:443");
); assert_eq!(room_id.server_name(), Some(server_name!("example.com:443")));
} }
#[test] #[test]
@ -280,10 +276,9 @@ mod tests {
#[test] #[test]
fn missing_server_name() { fn missing_server_name() {
assert_eq!( let room_id = <&RoomId>::try_from("!29fhd83h92h0").expect("Failed to create RoomId.");
<&RoomId>::try_from("!29fhd83h92h0").expect("Failed to create RoomId."), assert_eq!(room_id, "!29fhd83h92h0");
"!29fhd83h92h0" assert_eq!(room_id.server_name(), None);
);
} }
#[test] #[test]