-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trailing messages may omit the leading colon
- Loading branch information
Showing
1 changed file
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -571,7 +571,10 @@ impl ResponseParser { | |
} | ||
|
||
fn parse_trailing_message(tokenizer: &mut Tokenizer) -> String { | ||
tokenizer.match_str(":"); | ||
// The colon is only included if necessary to disambiguate the message components | ||
if tokenizer.peek() == Some(':') { | ||
tokenizer.match_str(":"); | ||
} | ||
tokenizer.read_to_str(IRC_LINE_DELIMITER).expect("Failed to read a message") | ||
} | ||
|
||
|
@@ -830,7 +833,7 @@ impl ResponseParser { | |
) | ||
}, | ||
IrcCommandName::Join => { | ||
let channel = tokenizer.read_to_str(IRC_LINE_DELIMITER).expect("Failed to read a channel name"); | ||
let channel = Self::parse_trailing_message(&mut tokenizer); | ||
if channel.contains(" ") { | ||
// Only clients can specify multiple channels | ||
panic!("Multiple channels mentioned, servers should not send multiple channels?") | ||
|
@@ -1270,6 +1273,23 @@ mod test { | |
) | ||
} | ||
|
||
#[test] | ||
fn test_parse_mode2() { | ||
let msg = parse_line(":coulomb.oftc.net MODE #zzzz13 +nt\r\n"); | ||
assert_eq!(msg.origin, Some("coulomb.oftc.net".to_string())); | ||
assert_eq!(msg.command_name, IrcCommandName::Mode); | ||
assert_eq!( | ||
msg.command, | ||
IrcCommand::Mode( | ||
ModeParams::new( | ||
// TODO(PT): This should be a UserOrChannel? | ||
&Nickname("#zzzz13".to_string()), | ||
"+nt" | ||
) | ||
) | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_parse_ping() { | ||
let msg = parse_line("PING :copper.libera.chat\r\n"); | ||
|
@@ -1362,6 +1382,22 @@ mod test { | |
) | ||
} | ||
|
||
#[test] | ||
fn test_names2() { | ||
let msg = parse_line(":coulomb.oftc.net 353 phillipt = #zzzz13 :@phillipt\r\n"); | ||
assert_eq!(msg.origin, Some("coulomb.oftc.net".to_string())); | ||
assert_eq!(msg.command_name, IrcCommandName::Names); | ||
assert_eq!( | ||
msg.command, | ||
IrcCommand::Names( | ||
NamesParameters::new( | ||
"#zzzz13".to_string(), | ||
vec![":@phillipt".to_string()], | ||
) | ||
) | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_end_of_names() { | ||
let msg = parse_line(":coulomb.oftc.net 366 phillip-testing2 #edk2 :End of /NAMES list\r\n"); | ||
|
@@ -1378,6 +1414,22 @@ mod test { | |
) | ||
} | ||
|
||
#[test] | ||
fn test_end_of_names2() { | ||
let msg = parse_line(":coulomb.oftc.net 366 phillipt #zzzz13 :End of /NAMES list.\r\n"); | ||
assert_eq!(msg.origin, Some("coulomb.oftc.net".to_string())); | ||
assert_eq!(msg.command_name, IrcCommandName::EndOfNames); | ||
assert_eq!( | ||
msg.command, | ||
IrcCommand::EndOfNames( | ||
EndOfNamesParameters::new( | ||
"#zzzz13".to_string(), | ||
"End of /NAMES list.".to_string(), | ||
) | ||
) | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_topic() { | ||
let msg = parse_line(":coulomb.oftc.net 332 phillip-testing2 #edk2 :EDK II/OVMF\r\n"); | ||
|
@@ -1410,4 +1462,19 @@ mod test { | |
) | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_join() { | ||
let msg = parse_line(":[email protected] JOIN :#zzzz13\r\n"); | ||
assert_eq!(msg.origin, Some("[email protected]".to_string())); | ||
assert_eq!(msg.command_name, IrcCommandName::Join); | ||
assert_eq!( | ||
msg.command, | ||
IrcCommand::Join( | ||
JoinParameters::new( | ||
&Channel("#zzzz13".to_string()), | ||
) | ||
) | ||
) | ||
} | ||
} |