From 9e5742a46211fbf4cb33e32082febb5932b5ad3e Mon Sep 17 00:00:00 2001 From: Fredrik Meringdal Date: Fri, 16 Oct 2020 01:31:17 +0200 Subject: more tests and some bug fixes --- src/iter.rs | 13 ++++------- src/yearinfo.rs | 4 ++-- tests/rrule.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/iter.rs b/src/iter.rs index b9c1560..daa67c2 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -108,7 +108,6 @@ pub fn iter(iter_result: &mut IterResult, options: &mut ParsedOptions) -> Vec Vec>>(); - println!("dayset: {:?}", dayset); let filtered = remove_filtered_days(&mut dayset, start, end, &ii, options); - println!("dayset: {:?}", dayset); if not_empty(&options.bysetpos) { let poslist = build_poslist(&options.bysetpos, ×et, start, end, &ii, &dayset); @@ -150,7 +147,6 @@ pub fn iter(iter_result: &mut IterResult, options: &mut ParsedOptions) -> Vec Vec(v: &Vec) -> bool { } pub fn is_filtered(ii: &IterInfo, current_day: usize, options: &ParsedOptions) -> bool { - println!( - "Was filtered here: {}", - (not_empty(&options.byweekno) && (ii.wnomask().unwrap()[current_day]) == 0) - ); + //println!( + //"Filtered here: {}", + //(not_empty(&options.byweekno) && (ii.wnomask().unwrap()[current_day]) == 0) + //); return (not_empty(&options.bymonth) && !includes(&options.bymonth, &ii.mmask().unwrap()[current_day])) || (not_empty(&options.byweekno) && (ii.wnomask().unwrap()[current_day]) == 0) diff --git a/src/yearinfo.rs b/src/yearinfo.rs index a2cd972..5ae6340 100644 --- a/src/yearinfo.rs +++ b/src/yearinfo.rs @@ -115,7 +115,7 @@ pub fn rebuild_year(year: i32, options: &ParsedOptions) -> YearInfo { } let div = (wyearlen as f32 / 7.).round() as isize; - let year_mod = pymod(div, 7); + let year_mod = pymod(wyearlen, 7); //const numweeks = Math.floor(div + mod / 4) let numweeks = div + (year_mod / 4); @@ -174,7 +174,7 @@ pub fn rebuild_year(year: i32, options: &ParsedOptions) -> YearInfo { // days from last year's last week number in // this year. let lnumweeks; - if options.byweekno.iter().any(|&weekno| weekno == -1) { + if !options.byweekno.iter().any(|&weekno| weekno == -1) { let lyearweekday = get_weekday_val(&Utc.ymd(year - 1, 1, 1).weekday()); let lno1wkst = pymod((7 - lyearweekday + options.wkst) as isize, 7); diff --git a/tests/rrule.rs b/tests/rrule.rs index 3691fbb..967e337 100644 --- a/tests/rrule.rs +++ b/tests/rrule.rs @@ -565,10 +565,10 @@ mod test { count: Some(3), bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), - byweekday: vec![20], + byweekday: vec![], byhour: vec![9], bysetpos: vec![], - byweekno: vec![], + byweekno: vec![20], byminute: vec![0], bysecond: vec![0], byyearday: vec![], @@ -584,8 +584,72 @@ mod test { &mut options, &vec![ ymd_hms(1998, 5, 11, 9, 0, 0), - ymd_hms(1999, 5, 12, 9, 0, 0), - ymd_hms(1999, 5, 13, 9, 0, 0), + ymd_hms(1998, 5, 12, 9, 0, 0), + ymd_hms(1998, 5, 13, 9, 0, 0), + ], + ); + } + + #[test] + fn yearly_by_weekno_and_weekday() { + let mut options = ParsedOptions { + freq: Frequenzy::YEARLY, + count: Some(3), + bymonth: vec![], + dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), + byweekday: vec![0], + byhour: vec![9], + bysetpos: vec![], + byweekno: vec![1], + byminute: vec![0], + bysecond: vec![0], + byyearday: vec![], + bymonthday: vec![], + bynweekday: vec![], + bynmonthday: vec![], + until: None, + wkst: 0, + tzid: None, + interval: 1, + }; + test_recurring( + &mut options, + &vec![ + ymd_hms(1997, 12, 29, 9, 0, 0), + ymd_hms(1999, 1, 4, 9, 0, 0), + ymd_hms(2000, 1, 3, 9, 0, 0), + ], + ); + } + + #[test] + fn yearly_by_weekno_and_weekday_large() { + let mut options = ParsedOptions { + freq: Frequenzy::YEARLY, + count: Some(3), + bymonth: vec![], + dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), + byweekday: vec![6], + byhour: vec![9], + bysetpos: vec![], + byweekno: vec![52], + byminute: vec![0], + bysecond: vec![0], + byyearday: vec![], + bymonthday: vec![], + bynweekday: vec![], + bynmonthday: vec![], + until: None, + wkst: 0, + tzid: None, + interval: 1, + }; + test_recurring( + &mut options, + &vec![ + ymd_hms(1997, 12, 28, 9, 0, 0), + ymd_hms(1998, 12, 27, 9, 0, 0), + ymd_hms(2000, 1, 2, 9, 0, 0), ], ); } -- cgit v1.2.3