From 121e2cc84458f49c024732dc559fa39236fc7b5e Mon Sep 17 00:00:00 2001 From: isra17 Date: Tue, 13 Mar 2018 13:18:58 -0400 Subject: [PATCH] Fix wrong RPL numeric formatting --- src/proto/command.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/proto/command.rs b/src/proto/command.rs index 7c0b70a..f0ec551 100644 --- a/src/proto/command.rs +++ b/src/proto/command.rs @@ -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), - &a.iter().map(|s| &s[..]).collect::>(), - Some(s), - ) + stringify(&format!("{:03}", *resp as u16), + &a.iter().map(|s| &s[..]).collect::>(), + Some(s)) } Command::Response(ref resp, ref a, None) => { - stringify( - &format!("{}", *resp as u16), - &a.iter().map(|s| &s[..]).collect::>(), - None, - ) + stringify(&format!("{:03}", *resp as u16), + &a.iter().map(|s| &s[..]).collect::>(), + None) } Command::Raw(ref c, ref a, Some(ref s)) => { stringify(c, &a.iter().map(|s| &s[..]).collect::>(), 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"); + } +}