diff --git a/README.md b/README.md index 385e6b0..b663f3f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,9 @@ fn main() { let duration = parse("3m + 31").unwrap(); //the default duration unit is second. assert_eq!(duration, Duration::new(211, 0)); + let duration = parse("3m31s").unwrap(); + assert_eq!(duration, Duration::new(211, 0)); + let duration = parse("3m + 13s + 29ms").unwrap(); assert_eq!(duration, Duration::new(193, 29 * 1000 * 1000 + 0 + 0)); diff --git a/src/lib.rs b/src/lib.rs index 2a57bd2..2e3cd93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,10 +214,9 @@ trait ExpectErr { fn expect_err + Display>(s: S) -> String; } -#[derive(Debug, Eq, PartialEq, Clone, Default)] +#[derive(Debug, Eq, PartialEq, Clone)] enum CondUnit { Plus, - #[default] Star, } @@ -239,7 +238,7 @@ impl ExpectErr<2> for CondUnit { } fn expect_err + Display>(s: S) -> String { - format!("expect one of:['+','*'], but find:{}", s) + format!("expect one of:{:?}, but find:{}", Self::expect_val(), s) } } diff --git a/src/parser.rs b/src/parser.rs index d9807bd..ddf4cb4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -150,6 +150,12 @@ mod tests { let duration = parse("1m+31").unwrap(); assert_eq!(duration, Duration::new(91, 0)); + let duration = parse("1m31").unwrap(); + assert_eq!(duration, Duration::new(91, 0)); + + let duration = parse("1m31s").unwrap(); + assert_eq!(duration, Duration::new(91, 0)); + let duration = parse("1m*60").unwrap(); assert_eq!(duration, Duration::new(3600, 0)); @@ -187,7 +193,7 @@ partial_input:mxyz, expect one of :["y", "mon", "w", "d", "h", "m", "s", "ms", " r#" 3ms-2ms ^ -partial_input:-2ms, expect one of:['+','*'], but find:-2ms"# +partial_input:-2ms, expect one of:["+", "*"], but find:-2ms"# .trim() ); }