diff options
author | dfhoughton <dfhoughton@gmail.com> | 2019-12-30 20:00:37 -0500 |
---|---|---|
committer | dfhoughton <dfhoughton@gmail.com> | 2019-12-30 20:00:37 -0500 |
commit | aa04e5f57cd94eb8d8f03d0087a8b4776f90b2d1 (patch) | |
tree | 879db0955a9c766ae10cbc133f9231fc88d604b1 /tests | |
parent | be6db59871d3399f4588f7c05eca7dd47224dd15 (diff) | |
download | two-timer-aa04e5f57cd94eb8d8f03d0087a8b4776f90b2d1.zip |
fixing bare "pay period" needed by jobrog
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.rs | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/tests/tests.rs b/tests/tests.rs index 2dee5c1..8030499 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,6 @@ #![feature(test)] extern crate two_timer; -use two_timer::{parse, parsable, Config}; +use two_timer::{parsable, parse, Config}; extern crate chrono; use chrono::naive::NaiveDate; use chrono::{Duration, Local}; @@ -493,12 +493,30 @@ fn this_pay_period() { .now(now); let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0); let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0); - let (start, end, _) = parse("this pay period", Some(config)).unwrap(); - assert_eq!(d1, start); - assert_eq!(d2, end); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(format!("this {}", pp), Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } } #[test] +fn bare_pay_period() { + let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0); + // two-week pay period beginning about a year before "now" on a Sunday + let config = Config::new() + .pay_period_start(Some(NaiveDate::from_ymd(1968, 5, 5))) + .pay_period_length(14) + .now(now); + let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0); + let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(pp, Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } +} +#[test] fn next_pay_period() { let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0); // two-week pay period beginning about a year before "now" on a Sunday @@ -508,9 +526,11 @@ fn next_pay_period() { .now(now); let d1 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0); let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0); - let (start, end, _) = parse("next pay period", Some(config)).unwrap(); - assert_eq!(d1, start); - assert_eq!(d2, end); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(format!("next {}", pp), Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } } #[test] @@ -523,9 +543,11 @@ fn last_pay_period() { .now(now); let d1 = NaiveDate::from_ymd(1969, 4, 20).and_hms(0, 0, 0); let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0); - let (start, end, _) = parse("last pay period", Some(config)).unwrap(); - assert_eq!(d1, start); - assert_eq!(d2, end); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(format!("last {}", pp), Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } } #[test] @@ -538,9 +560,11 @@ fn this_pay_period_weird() { .now(now); let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0); let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0); - let (start, end, _) = parse("this pay period", Some(config)).unwrap(); - assert_eq!(d1, start); - assert_eq!(d2, end); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(format!("this {}", pp), Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } } #[test] @@ -553,9 +577,11 @@ fn next_pay_period_weird() { .now(now); let d1 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0); let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0); - let (start, end, _) = parse("next pay period", Some(config)).unwrap(); - assert_eq!(d1, start); - assert_eq!(d2, end); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(format!("next {}", pp), Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } } #[test] @@ -568,9 +594,11 @@ fn last_pay_period_weird() { .now(now); let d1 = NaiveDate::from_ymd(1969, 4, 20).and_hms(0, 0, 0); let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0); - let (start, end, _) = parse("last pay period", Some(config)).unwrap(); - assert_eq!(d1, start); - assert_eq!(d2, end); + for pp in ["pp", "pay period", "payperiod"].iter() { + let (start, end, _) = parse(format!("last {}", pp), Some(config.clone())).unwrap(); + assert_eq!(d1, start); + assert_eq!(d2, end); + } } #[test] @@ -1506,4 +1534,4 @@ fn no_space_before_pm() { assert!(false, "didn't match"); } } -}
\ No newline at end of file +} |