Implemented tag output in Message::to_string() which apparently was _still_ a TODO.

This commit is contained in:
Aaron Weiss 2017-12-13 20:32:04 +01:00
parent f6588cb980
commit 4ec2212dbd
No known key found for this signature in database
GPG key ID: 047D32DF25DC22EF

View file

@ -73,8 +73,20 @@ impl Message {
/// Converts a Message into a String according to the IRC protocol.
pub fn to_string(&self) -> String {
// TODO: tags
let mut ret = String::new();
if let Some(ref tags) = self.tags {
ret.push('@');
for tag in tags {
ret.push_str(&tag.0);
if let Some(ref value) = tag.1 {
ret.push('=');
ret.push_str(value);
}
ret.push(';');
}
ret.pop();
ret.push(' ');
}
if let Some(ref prefix) = self.prefix {
ret.push(':');
ret.push_str(prefix);
@ -303,6 +315,13 @@ mod test {
)
}
#[test]
fn from_and_to_string() {
let message = "@aaa=bbb;ccc;example.com/ddd=eee :test!test@test PRIVMSG test :Testing with \
tags!\r\n";
assert_eq!(message.parse::<Message>().unwrap().to_string(), message);
}
#[test]
fn to_message() {
let message = Message {