From 91df2441a0bb8c032b6fc5ccff50ed0eb98f2194 Mon Sep 17 00:00:00 2001 From: Jonathan Reem Date: Wed, 28 Jan 2015 00:53:26 -0500 Subject: [PATCH] fix(headers): Don't display q if q=1 in quality item. Fixes #281 --- src/header/shared/quality_item.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/header/shared/quality_item.rs b/src/header/shared/quality_item.rs index d9edecf167..73eaf05644 100644 --- a/src/header/shared/quality_item.rs +++ b/src/header/shared/quality_item.rs @@ -28,7 +28,12 @@ impl QualityItem { impl fmt::Display for QualityItem { 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', '.'][])) + } } } @@ -79,7 +84,7 @@ pub fn qitem(item: T) -> QualityItem { #[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() {