Skip to content

Commit

Permalink
fix(headers): Don't display q if q=1 in quality item.
Browse files Browse the repository at this point in the history
Fixes #281
  • Loading branch information
reem committed Jan 28, 2015
1 parent 93821fc commit 91df244
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/header/shared/quality_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ impl<T> QualityItem<T> {

impl<T: fmt::Display> fmt::Display for QualityItem<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}; q={}", self.item, format!("{:.3}", self.quality).trim_right_matches(['0', '.'].as_slice()))
if self.quality == 1.0 {
write!(f, "{}", self.item)
} else {
write!(f, "{}; q={}", self.item,
format!("{:.3}", self.quality).trim_right_matches(&['0', '.'][]))
}
}
}

Expand Down Expand Up @@ -79,7 +84,7 @@ pub fn qitem<T>(item: T) -> QualityItem<T> {
#[test]
fn test_quality_item_show1() {
let x = qitem(Chunked);
assert_eq!(format!("{}", x), "chunked; q=1");
assert_eq!(format!("{}", x), "chunked");
}
#[test]
fn test_quality_item_show2() {
Expand Down

0 comments on commit 91df244

Please sign in to comment.