diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-11-11 03:39:25 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-11-11 03:39:25 +0100 |
commit | 2053d956af43d26238f7be9ae6acf0d60b85acad (patch) | |
tree | aa8e5e51819821a162b0dd29ea06685f7a415bfa | |
parent | 43f00a146355ed234570542324cf2d20c51436cb (diff) |
Add test for parser which contains subtraction
-rw-r--r-- | src/parser.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs index 1b87bc4..2cbf046 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -618,5 +618,28 @@ mod tests { // upper assertions are enough. } + #[test] + fn test_expressions_to_timetype_subtract() { + let res = timetype(&b"5min + 12min + 15hours - 1hour"[..]); + assert!(res.is_done()); + let (_, o) = res.unwrap(); + + println!("{:#?}", o); + + let calc_res : timetype::TimeType = o.into(); + println!("{:#?}", calc_res); + + let calc_res = calc_res.calculate(); + assert!(calc_res.is_ok()); + println!("{:#?}", calc_res); + + let calc_res = calc_res.unwrap(); + assert_eq!(calc_res.get_seconds(), 17 * 60 + (14 * 60 * 60)); + assert_eq!(calc_res.get_minutes(), 17 + (14 * 60)); + assert_eq!(calc_res.get_hours(), 14); + assert_eq!(calc_res.get_days(), 0); + assert_eq!(calc_res.get_years(), 0); + } + } |