irc: allow PART without a reason

This commit is contained in:
Nikita Vilunov 2024-04-06 23:01:24 +00:00
parent adece11fef
commit 36b0d50d51
2 changed files with 24 additions and 8 deletions

View File

@ -271,11 +271,10 @@ async fn scenario_two_users() -> Result<()> {
// The first user should receive the message // The first user should receive the message
s1.expect(":tester2 PRIVMSG #test :Hello").await?; s1.expect(":tester2 PRIVMSG #test :Hello").await?;
// Leave the channel from the first user // Leave the channel from the first user
// TODO implement irc PART command s1.send("PART #test").await?;
// s1.send("PART #test").await?; s1.expect(":tester1 PART #test").await?;
// s1.expect(":tester1 PART #test").await?;
// The second user should receive the PART message // The second user should receive the PART message
// s2.expect(":tester1 PART #test").await?; s2.expect(":tester1 PART #test").await?;
Ok(()) Ok(())
} }

View File

@ -49,7 +49,7 @@ pub enum ClientMessage {
}, },
Part { Part {
chan: Chan, chan: Chan,
message: Str, message: Option<Str>,
}, },
/// `PRIVMSG <target> :<msg>` /// `PRIVMSG <target> :<msg>`
PrivateMessage { PrivateMessage {
@ -194,14 +194,20 @@ fn client_message_topic(input: &str) -> IResult<&str, ClientMessage> {
fn client_message_part(input: &str) -> IResult<&str, ClientMessage> { fn client_message_part(input: &str) -> IResult<&str, ClientMessage> {
let (input, _) = tag("PART ")(input)?; let (input, _) = tag("PART ")(input)?;
let (input, chan) = chan(input)?; let (input, chan) = chan(input)?;
let (input, _) = tag(" ")(input)?; let (input, t) = opt(tag(" "))(input)?;
match t {
Some(_) => (),
None => {
return Ok((input, ClientMessage::Part { chan, message: None }));
}
}
let (input, r) = opt(tag(":"))(input)?; let (input, r) = opt(tag(":"))(input)?;
let (input, message) = match r { let (input, message) = match r {
Some(_) => token(input)?, Some(_) => token(input)?,
None => receiver(input)?, None => receiver(input)?,
}; };
let message = message.into(); let message = Some(message.into());
Ok((input, ClientMessage::Part { chan, message })) Ok((input, ClientMessage::Part { chan, message }))
} }
@ -369,7 +375,18 @@ mod test {
let input = "PART #chan :Pokasiki !!!"; let input = "PART #chan :Pokasiki !!!";
let expected = ClientMessage::Part { let expected = ClientMessage::Part {
chan: Chan::Global("chan".into()), chan: Chan::Global("chan".into()),
message: "Pokasiki !!!".into(), message: Some("Pokasiki !!!".into()),
};
let result = client_message(input);
assert_matches!(result, Ok(result) => assert_eq!(expected, result));
}
#[test]
fn test_client_message_part_empty() {
let input = "PART #chan";
let expected = ClientMessage::Part {
chan: Chan::Global("chan".into()),
message: None,
}; };
let result = client_message(input); let result = client_message(input);