| 1 |
use rstest::rstest; |
| 2 |
use rstest_reuse::{apply, template}; |
| 3 |
use time::Month::{self, *}; |
| 4 |
use time::iter::MonthIter; |
| 5 |
|
| 6 |
#[template] |
| 7 |
#[rstest] |
| 8 |
fn all_months( |
| 9 |
#[values( |
| 10 |
January, February, March, April, May, June, July, August, September, October, November, |
| 11 |
December |
| 12 |
)] |
| 13 |
start: Month, |
| 14 |
) { |
| 15 |
} |
| 16 |
|
| 17 |
#[apply(all_months)] |
| 18 |
fn new(start: Month) { |
| 19 |
let mut iter = MonthIter::new(start); |
| 20 |
assert_eq!(iter.next(), Some(start)); |
| 21 |
assert_eq!(iter.next(), Some(start.next())); |
| 22 |
} |
| 23 |
|
| 24 |
#[apply(all_months)] |
| 25 |
fn iter_from(start: Month) { |
| 26 |
let mut iter = Month::iter_from(start); |
| 27 |
assert_eq!(iter.next(), Some(start)); |
| 28 |
assert_eq!(iter.next(), Some(start.next())); |
| 29 |
} |
| 30 |
|
| 31 |
#[apply(all_months)] |
| 32 |
fn size_hint(start: Month) { |
| 33 |
assert_eq!(MonthIter::new(start).size_hint(), (usize::MAX, None)); |
| 34 |
} |
| 35 |
|
| 36 |
#[apply(all_months)] |
| 37 |
fn max(start: Month) { |
| 38 |
assert_eq!(MonthIter::new(start).max(), Some(December)); |
| 39 |
} |
| 40 |
|
| 41 |
#[apply(all_months)] |
| 42 |
fn min(start: Month) { |
| 43 |
assert_eq!(MonthIter::new(start).min(), Some(January)); |
| 44 |
} |
| 45 |
|
| 46 |
#[apply(all_months)] |
| 47 |
fn is_sorted(start: Month) { |
| 48 |
assert!(!MonthIter::new(start).is_sorted()); |
| 49 |
} |
| 50 |
|
| 51 |
#[apply(all_months)] |
| 52 |
fn nth(start: Month, #[values(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)] n: u8) { |
| 53 |
let expected = start.nth_next(n); |
| 54 |
assert_eq!(MonthIter::new(start).nth(n as usize), Some(expected)); |
| 55 |
} |
| 56 |
|
| 57 |
#[apply(all_months)] |
| 58 |
fn any_checks_all_months( |
| 59 |
start: Month, |
| 60 |
#[values( |
| 61 |
January, February, March, April, May, June, July, August, September, October, November, |
| 62 |
December |
| 63 |
)] |
| 64 |
target: Month, |
| 65 |
) { |
| 66 |
assert!(MonthIter::new(start).any(|m| m == target)); |
| 67 |
} |
| 68 |
|
| 69 |
#[apply(all_months)] |
| 70 |
fn any_terminates(start: Month) { |
| 71 |
assert!(!MonthIter::new(start).any(|_| false)); |
| 72 |
} |
| 73 |
|
| 74 |
#[apply(all_months)] |
| 75 |
fn all_checks_all_months( |
| 76 |
start: Month, |
| 77 |
#[values( |
| 78 |
January, February, March, April, May, June, July, August, September, October, November, |
| 79 |
December |
| 80 |
)] |
| 81 |
excludes: Month, |
| 82 |
) { |
| 83 |
assert!(!MonthIter::new(start).all(|m| m != excludes)); |
| 84 |
} |
| 85 |
|
| 86 |
#[apply(all_months)] |
| 87 |
fn all_terminates(start: Month) { |
| 88 |
assert!(MonthIter::new(start).all(|_| true)); |
| 89 |
} |
| 90 |
|
| 91 |
#[apply(all_months)] |
| 92 |
fn rev_next(start: Month) { |
| 93 |
let mut iter = MonthIter::new(start).rev(); |
| 94 |
assert_eq!(iter.next(), Some(start)); |
| 95 |
assert_eq!(iter.next(), Some(start.previous())); |
| 96 |
} |
| 97 |
|
| 98 |
#[apply(all_months)] |
| 99 |
fn rev_nth(start: Month, #[values(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)] n: u8) { |
| 100 |
let expected = start.nth_prev(n); |
| 101 |
assert_eq!(MonthIter::new(start).rev().nth(n as usize), Some(expected)); |
| 102 |
} |
| 103 |
|
| 104 |
#[apply(all_months)] |
| 105 |
fn rev_size_hint(start: Month) { |
| 106 |
assert_eq!(MonthIter::new(start).rev().size_hint(), (usize::MAX, None)); |
| 107 |
} |
| 108 |
|
| 109 |
#[apply(all_months)] |
| 110 |
fn rev_max(start: Month) { |
| 111 |
assert_eq!(MonthIter::new(start).rev().max(), Some(December)); |
| 112 |
} |
| 113 |
|
| 114 |
#[apply(all_months)] |
| 115 |
fn rev_min(start: Month) { |
| 116 |
assert_eq!(MonthIter::new(start).rev().min(), Some(January)); |
| 117 |
} |
| 118 |
|
| 119 |
#[apply(all_months)] |
| 120 |
fn rev_is_sorted(start: Month) { |
| 121 |
assert!(!MonthIter::new(start).rev().is_sorted()); |
| 122 |
} |
| 123 |
|
| 124 |
#[apply(all_months)] |
| 125 |
#[should_panic(expected = "infinite")] |
| 126 |
fn count_panics(start: Month) { |
| 127 |
MonthIter::new(start).count(); |
| 128 |
} |
| 129 |
|
| 130 |
#[apply(all_months)] |
| 131 |
#[should_panic(expected = "infinite")] |
| 132 |
fn last_panics(start: Month) { |
| 133 |
MonthIter::new(start).last(); |
| 134 |
} |
| 135 |
|
| 136 |
#[apply(all_months)] |
| 137 |
#[should_panic(expected = "infinite")] |
| 138 |
fn rev_count_panics(start: Month) { |
| 139 |
MonthIter::new(start).rev().count(); |
| 140 |
} |
| 141 |
|
| 142 |
#[apply(all_months)] |
| 143 |
#[should_panic(expected = "infinite")] |
| 144 |
fn rev_last_panics(start: Month) { |
| 145 |
MonthIter::new(start).rev().last(); |
| 146 |
} |
| 147 |
|
| 148 |
#[apply(all_months)] |
| 149 |
fn rev_any_checks_all_months( |
| 150 |
start: Month, |
| 151 |
#[values( |
| 152 |
January, February, March, April, May, June, July, August, September, October, November, |
| 153 |
December |
| 154 |
)] |
| 155 |
target: Month, |
| 156 |
) { |
| 157 |
assert!(MonthIter::new(start).rev().any(|m| m == target)); |
| 158 |
} |
| 159 |
|
| 160 |
#[apply(all_months)] |
| 161 |
fn rev_any_terminates(start: Month) { |
| 162 |
assert!(!MonthIter::new(start).rev().any(|_| false)); |
| 163 |
} |
| 164 |
|
| 165 |
#[apply(all_months)] |
| 166 |
fn rev_all_checks_all_months( |
| 167 |
start: Month, |
| 168 |
#[values( |
| 169 |
January, February, March, April, May, June, July, August, September, October, November, |
| 170 |
December |
| 171 |
)] |
| 172 |
excludes: Month, |
| 173 |
) { |
| 174 |
assert!(!MonthIter::new(start).rev().all(|m| m != excludes)); |
| 175 |
} |
| 176 |
|
| 177 |
#[apply(all_months)] |
| 178 |
fn rev_all_terminates(start: Month) { |
| 179 |
assert!(MonthIter::new(start).rev().all(|_| true)); |
| 180 |
} |