diff options
Diffstat (limited to 'yt/src/select/selection_file/duration.rs')
-rw-r--r-- | yt/src/select/selection_file/duration.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/yt/src/select/selection_file/duration.rs b/yt/src/select/selection_file/duration.rs index 3957f0f..ab3a18b 100644 --- a/yt/src/select/selection_file/duration.rs +++ b/yt/src/select/selection_file/duration.rs @@ -14,7 +14,7 @@ use anyhow::{Context, Result}; use crate::unreachable::Unreachable; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct Duration { time: u32, } @@ -30,7 +30,7 @@ impl FromStr for Duration { .with_context(|| format!("Failed to parse '{suffix}'")) } - if s == "[No Duration]" { + if s == "[No duration]" { return Ok(Self { time: 0 }); } @@ -88,7 +88,7 @@ impl std::fmt::Display for Duration { let s = base_sec / SECOND; if self.time == 0 { - write!(f, "[No Duration]") + write!(f, "[No duration]") } else if h > 0 { write!(f, "{h}h {m}m") } else { @@ -98,6 +98,8 @@ impl std::fmt::Display for Duration { } #[cfg(test)] mod test { + use std::str::FromStr; + use super::Duration; #[test] @@ -110,4 +112,11 @@ mod test { let dur = Duration { time: 60 * 30 }; assert_eq!("30m 0s".to_owned(), dur.to_string()); } + #[test] + fn test_display_duration_roundtrip() { + let dur = Duration { time: 0 }; + let dur_str = dur.to_string(); + + assert_eq!(Duration { time: 0 }, Duration::from_str(&dur_str).unwrap()); + } } |