fix irc tests

This commit is contained in:
Nikita Vilunov 2023-07-23 15:21:26 +02:00
parent b80daf9648
commit c1a461a09e
2 changed files with 39 additions and 39 deletions

View File

@ -58,24 +58,24 @@ const SERVER_HOSTNAME: &'static str = "irc.localhost";
#[rustfmt::skip] #[rustfmt::skip]
async fn registration(scope: &mut TestScope<'_>, nickname: &str) -> Result<()> { async fn registration(scope: &mut TestScope<'_>, nickname: &str) -> Result<()> {
expect!(scope, ":irc.localhost NOTICE * :Welcome to my server!\n"); expect!(scope, ":irc.localhost NOTICE * :Welcome to my server!\r\n");
send!(scope, "NICK {nickname}\n"); send!(scope, "NICK {nickname}\r\n");
send!(scope, "USER UserName 0 * :Real Name\n"); send!(scope, "USER UserName 0 * :Real Name\r\n");
expect!(scope, ":irc.localhost 001 {nickname} :Welcome to Kek Server\n"); expect!(scope, ":irc.localhost 001 {nickname} :Welcome to Kek Server\r\n");
expect!(scope, ":irc.localhost 002 {nickname} :Welcome to Kek Server\n"); expect!(scope, ":irc.localhost 002 {nickname} :Welcome to Kek Server\r\n");
expect!(scope, ":irc.localhost 003 {nickname} :Welcome to Kek Server\n"); expect!(scope, ":irc.localhost 003 {nickname} :Welcome to Kek Server\r\n");
expect!(scope, ":irc.localhost 004 {nickname} irc.localhost kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz\n"); expect!(scope, ":irc.localhost 004 {nickname} irc.localhost kek-0.1.alpha.3 r CFILPQbcefgijklmnopqrstvz\r\n");
expect!(scope, ":irc.localhost 005 {nickname} CHANTYPES=# :are supported by this server\n"); expect!(scope, ":irc.localhost 005 {nickname} CHANTYPES=# :are supported by this server\r\n");
Ok(()) Ok(())
} }
#[rustfmt::skip] #[rustfmt::skip]
async fn join(scope: &mut TestScope<'_>, nickname: &str, chan: &str) -> Result<()> { async fn join(scope: &mut TestScope<'_>, nickname: &str, chan: &str) -> Result<()> {
send!(scope, "JOIN #{chan}\n"); send!(scope, "JOIN #{chan}\r\n");
expect!(scope, ":{nickname} JOIN #{chan}\n"); expect!(scope, ":{nickname} JOIN #{chan}\r\n");
expect!(scope, ":irc.localhost 332 {nickname} #{chan} :New room\n"); expect!(scope, ":irc.localhost 332 {nickname} #{chan} :New room\r\n");
expect!(scope, ":irc.localhost 353 {nickname} = #{chan} :{nickname}\n"); expect!(scope, ":irc.localhost 353 {nickname} = #{chan} :{nickname}\r\n");
expect!(scope, ":irc.localhost 366 {nickname} #{chan} :End of /NAMES list\n"); expect!(scope, ":irc.localhost 366 {nickname} #{chan} :End of /NAMES list\r\n");
Ok(()) Ok(())
} }
@ -105,26 +105,26 @@ async fn test_two_connections_one_player() -> Result<()> {
join(&mut scope1, nickname, chan).await?; join(&mut scope1, nickname, chan).await?;
// force join on second connection when the other one joins a room // force join on second connection when the other one joins a room
expect!(scope2, ":{nickname} JOIN #{chan}\n"); expect!(scope2, ":{nickname} JOIN #{chan}\r\n");
expect!(scope2, ":{SERVER_HOSTNAME} 332 {nickname} #{chan} :New room\n"); expect!(scope2, ":{SERVER_HOSTNAME} 332 {nickname} #{chan} :New room\r\n");
expect!(scope2, ":{SERVER_HOSTNAME} 353 {nickname} = #{chan} :{nickname}\n"); expect!(scope2, ":{SERVER_HOSTNAME} 353 {nickname} = #{chan} :{nickname}\r\n");
expect!(scope2, ":{SERVER_HOSTNAME} 366 {nickname} #{chan} :End of /NAMES list\n"); expect!(scope2, ":{SERVER_HOSTNAME} 366 {nickname} #{chan} :End of /NAMES list\r\n");
// force send PRIVMSG to other connections // force send PRIVMSG to other connections
send!(scope1, "PRIVMSG #{chan} :Chmoki vsem v etam chati!\n"); send!(scope1, "PRIVMSG #{chan} :Chmoki vsem v etam chati!\r\n");
expect!(scope2, ":{nickname} PRIVMSG #{chan} :Chmoki vsem v etam chati!\n"); expect!(scope2, ":{nickname} PRIVMSG #{chan} :Chmoki vsem v etam chati!\r\n");
send!(scope2, "PRIVMSG #{chan} :I tebe privetiki\n"); send!(scope2, "PRIVMSG #{chan} :I tebe privetiki\r\n");
expect!(scope1, ":{nickname} PRIVMSG #{chan} :I tebe privetiki\n"); expect!(scope1, ":{nickname} PRIVMSG #{chan} :I tebe privetiki\r\n");
let mut stream3 = TcpStream::connect("127.0.0.1:6667").await?; let mut stream3 = TcpStream::connect("127.0.0.1:6667").await?;
let mut scope3 = init_client(&mut stream3).await?; let mut scope3 = init_client(&mut stream3).await?;
registration(&mut scope3, nickname).await?; registration(&mut scope3, nickname).await?;
// force join on registration // force join on registration
expect!(scope3, ":{nickname} JOIN #{chan}\n"); expect!(scope3, ":{nickname} JOIN #{chan}\r\n");
expect!(scope3, ":{SERVER_HOSTNAME} 332 {nickname} #{chan} :New room\n"); expect!(scope3, ":{SERVER_HOSTNAME} 332 {nickname} #{chan} :New room\r\n");
expect!(scope3, ":{SERVER_HOSTNAME} 353 {nickname} = #{chan} :{nickname}\n"); expect!(scope3, ":{SERVER_HOSTNAME} 353 {nickname} = #{chan} :{nickname}\r\n");
expect!(scope3, ":{SERVER_HOSTNAME} 366 {nickname} #{chan} :End of /NAMES list\n"); expect!(scope3, ":{SERVER_HOSTNAME} 366 {nickname} #{chan} :End of /NAMES list\r\n");
Ok(()) Ok(())
} }
@ -145,22 +145,22 @@ async fn test_two_players() -> Result<()> {
registration(&mut scope1, "NickName3").await?; registration(&mut scope1, "NickName3").await?;
registration(&mut scope2, "NickName4").await?; registration(&mut scope2, "NickName4").await?;
join(&mut scope1, nickname1, "chan3").await?; join(&mut scope1, nickname1, "chan3").await?;
send!(scope2, "JOIN #{chan}\n"); send!(scope2, "JOIN #{chan}\r\n");
expect!(scope2, ":{nickname2} JOIN #{chan}\n"); expect!(scope2, ":{nickname2} JOIN #{chan}\r\n");
expect!(scope2, ":irc.localhost 332 {nickname2} #{chan} :New room\n"); expect!(scope2, ":irc.localhost 332 {nickname2} #{chan} :New room\r\n");
scope2.assert(|line| { scope2.assert(|line| {
if line == format!(":irc.localhost 353 {nickname2} = #{chan} :{nickname1} {nickname2}\n") { return Ok(()) } if line == format!(":irc.localhost 353 {nickname2} = #{chan} :{nickname1} {nickname2}\r\n") { return Ok(()) }
if line == format!(":irc.localhost 353 {nickname2} = #{chan} :{nickname2} {nickname1}\n") { return Ok(()) } if line == format!(":irc.localhost 353 {nickname2} = #{chan} :{nickname2} {nickname1}\r\n") { return Ok(()) }
panic!("incorrect chan member list received: {line}"); panic!("incorrect chan member list received: {line}");
}).await?; }).await?;
expect!(scope2, ":irc.localhost 366 {nickname2} #{chan} :End of /NAMES list\n"); expect!(scope2, ":irc.localhost 366 {nickname2} #{chan} :End of /NAMES list\r\n");
expect!(scope1, ":{nickname2} JOIN #{chan}\n"); expect!(scope1, ":{nickname2} JOIN #{chan}\r\n");
send!(scope1, "PRIVMSG #chan3 :Chmoki vsem v etam chati!\n"); send!(scope1, "PRIVMSG #chan3 :Chmoki vsem v etam chati!\r\n");
expect!(scope2, ":{nickname1} PRIVMSG #chan3 :Chmoki vsem v etam chati!\n"); expect!(scope2, ":{nickname1} PRIVMSG #chan3 :Chmoki vsem v etam chati!\r\n");
send!(scope2, "PRIVMSG #chan3 :I tebe privetiki\n"); send!(scope2, "PRIVMSG #chan3 :I tebe privetiki\r\n");
expect!(scope1, ":{nickname2} PRIVMSG #chan3 :I tebe privetiki\n"); expect!(scope1, ":{nickname2} PRIVMSG #chan3 :I tebe privetiki\r\n");
Ok(()) Ok(())
} }

View File

@ -31,7 +31,7 @@ impl ServerMessage {
pub fn server_message(input: &str) -> IResult<&str, ServerMessage> { pub fn server_message(input: &str) -> IResult<&str, ServerMessage> {
let (input, command) = server_message_body(input)?; let (input, command) = server_message_body(input)?;
let (input, _) = tag("\n")(input)?; let (input, _) = tag("\r\n")(input)?;
let message = ServerMessage { let message = ServerMessage {
tags: vec![], tags: vec![],
@ -374,7 +374,7 @@ mod test {
#[test] #[test]
fn test_server_message_notice() { fn test_server_message_notice() {
let input = "NOTICE * :*** Looking up your hostname...\n"; let input = "NOTICE * :*** Looking up your hostname...\r\n";
let expected = ServerMessage { let expected = ServerMessage {
tags: vec![], tags: vec![],
sender: None, sender: None,
@ -397,7 +397,7 @@ mod test {
#[test] #[test]
fn test_server_message_pong() { fn test_server_message_pong() {
let input = "PONG server.example :LAG004911\n"; let input = "PONG server.example :LAG004911\r\n";
let expected = ServerMessage { let expected = ServerMessage {
tags: vec![], tags: vec![],
sender: None, sender: None,