fix(headers): Fix formatting of 0 qualites and formatting of empty list header fields.

This commit is contained in:
Pyfisch
2015-04-28 08:46:26 +02:00
parent 29c8dd1b20
commit 621ef521f6
4 changed files with 19 additions and 33 deletions

View File

@@ -24,10 +24,10 @@ pub struct Quality(pub u16);
impl fmt::Display for Quality {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.0 == 1000 {
write!(f, "")
} else {
write!(f, "; q=0.{}", format!("{:03}", self.0).trim_right_matches('0'))
match self.0 {
1000 => Ok(()),
0 => f.write_str("; q=0"),
x => write!(f, "; q=0.{}", format!("{:03}", x).trim_right_matches('0'))
}
}
}
@@ -196,6 +196,11 @@ mod tests {
assert_eq!(q(0.5), Quality(500));
}
#[test]
fn test_quality2() {
assert_eq!(format!("{}", q(0.0)), "; q=0");
}
#[test]
#[should_panic]
fn test_quality_invalid() {