fix(headers): Fix formatting of 0 qualites and formatting of empty list header fields.
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user