Fix wrong RPL numeric formatting

This commit is contained in:
isra17 2018-03-13 13:18:58 -04:00
parent 7af436a7d2
commit 121e2cc844
No known key found for this signature in database
GPG key ID: 6367E68766123B1F

View file

@ -421,18 +421,14 @@ impl<'a> From<&'a Command> for String {
Command::CHGHOST(ref u, ref h) => stringify("CHGHOST", &[u, h], None),
Command::Response(ref resp, ref a, Some(ref s)) => {
stringify(
&format!("{}", *resp as u16),
stringify(&format!("{:03}", *resp as u16),
&a.iter().map(|s| &s[..]).collect::<Vec<_>>(),
Some(s),
)
Some(s))
}
Command::Response(ref resp, ref a, None) => {
stringify(
&format!("{}", *resp as u16),
stringify(&format!("{:03}", *resp as u16),
&a.iter().map(|s| &s[..]).collect::<Vec<_>>(),
None,
)
None)
}
Command::Raw(ref c, ref a, Some(ref s)) => {
stringify(c, &a.iter().map(|s| &s[..]).collect::<Vec<_>>(), Some(s))
@ -1763,3 +1759,16 @@ impl FromStr for BatchSubCommand {
}
}
}
#[cfg(test)]
mod test {
use super::Response;
use super::Command;
#[test]
fn format_response() {
assert!(String::from(&Command::Response(Response::RPL_WELCOME,
vec!["foo".into()],
None)) == "001 foo");
}
}