Skip to content

Commit

Permalink
fix parsing error location precise prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed May 10, 2024
1 parent 64faee5 commit 6077ed1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ trait ExpectErr<const LEN: usize> {
fn expect_err<S: AsRef<str> + Display>(s: S) -> String;
}

#[derive(Debug, Eq, PartialEq, Clone, Default)]
#[derive(Debug, Eq, PartialEq, Clone)]
enum CondUnit {
Plus,
#[default]
Star,
}

Expand All @@ -239,7 +238,7 @@ impl ExpectErr<2> for CondUnit {
}

fn expect_err<S: AsRef<str> + Display>(s: S) -> String {
format!("expect one of:['+','*'], but find:{}", s)
format!("expect one of:{:?}, but find:{}", Self::expect_val(), s)
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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()
);
}
Expand Down

0 comments on commit 6077ed1

Please sign in to comment.