Merge pull request #123 from isra17/develop

Fix wrong RPL numeric formatting
This commit is contained in:
Aaron Weiss 2018-03-13 18:28:59 +01:00 committed by GitHub
commit e7e1149bee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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::CHGHOST(ref u, ref h) => stringify("CHGHOST", &[u, h], None),
Command::Response(ref resp, ref a, Some(ref s)) => { Command::Response(ref resp, ref a, Some(ref s)) => {
stringify( stringify(&format!("{:03}", *resp as u16),
&format!("{}", *resp as u16), &a.iter().map(|s| &s[..]).collect::<Vec<_>>(),
&a.iter().map(|s| &s[..]).collect::<Vec<_>>(), Some(s))
Some(s),
)
} }
Command::Response(ref resp, ref a, None) => { Command::Response(ref resp, ref a, None) => {
stringify( stringify(&format!("{:03}", *resp as u16),
&format!("{}", *resp as u16), &a.iter().map(|s| &s[..]).collect::<Vec<_>>(),
&a.iter().map(|s| &s[..]).collect::<Vec<_>>(), None)
None,
)
} }
Command::Raw(ref c, ref a, Some(ref s)) => { Command::Raw(ref c, ref a, Some(ref s)) => {
stringify(c, &a.iter().map(|s| &s[..]).collect::<Vec<_>>(), Some(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");
}
}