Skip to content

Commit

Permalink
Merge pull request #283 from reem/dont-print-q=1
Browse files Browse the repository at this point in the history
fix(headers): Don't display q if q=1 in quality item.
  • Loading branch information
seanmonstar committed Jan 28, 2015
2 parents 93821fc + 91df244 commit 537d691
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 537d691

Please sign in to comment.