Debian Codegraph @

src/tests/common.rs

raw symbols SCIP
1 #![cfg(test)]
2 #![allow(dead_code)]
3
4 use craterust-analyzer cargo rrule 0.14.0 crate/::{corerust-analyzer cargo rrule 0.14.0 core/::Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#, RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#, RRuleErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#, RRuleSetrust-analyzer cargo rrule 0.14.0 core/rruleset/RRuleSet#, Unvalidatedrust-analyzer cargo rrule 0.14.0 core/Unvalidated#};
5 use chronorust-analyzer cargo chrono 0.4.40 crate/::{DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#, TimeZonerust-analyzer cargo chrono 0.4.40 offset/TimeZone#};
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
7
8 pub fn ymd_hmsrust-analyzer cargo rrule 0.14.0 tests/common/ymd_hms().(
9 year: i32,
10 month: u32,
11 day: u32,
12 hour: u32,
13 minute: u32,
14 second: u32,
15 ) -> DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#> {
16 Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#::UTCrust-analyzer cargo rrule 0.14.0 core/timezone/impl#[Tz]UTC.
17 .with_ymd_and_hmsrust-analyzer cargo chrono 0.4.40 offset/TimeZone#with_ymd_and_hms().(year, month, day, hour, minute, second)
18 .unwraprust-analyzer cargo chrono 0.4.40 offset/impl#[`LocalResult<T>`]unwrap().()
19 }
20
21 pub fn test_recurring_rrulerust-analyzer cargo rrule 0.14.0 tests/common/test_recurring_rrule().(
22 rrule: RRulerust-analyzer cargo rrule 0.14.0 core/rrule/RRule#<Unvalidatedrust-analyzer cargo rrule 0.14.0 core/Unvalidated#>,
23 limited: bool,
24 dt_start: DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>,
25 expected_dates: &[DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>],
26 ) {
27 let rrule_set = rrule
28 .buildrust-analyzer cargo rrule 0.14.0 core/rrule/impl#[`RRule<Unvalidated>`]build().(dt_start)
29 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| match e {
30 RRuleErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#::ParserErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#ParserError#(e) => e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
31 RRuleErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#::ValidationErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#ValidationError#(e) => e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
32 RRuleErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#::IterErrorrust-analyzer cargo rrule 0.14.0 error/RRuleError#IterError#(e) => e,
33 })
34 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
35 let res = if limited {
36 rrule_set.allrust-analyzer cargo rrule 0.14.0 core/rruleset/impl#[RRuleSet]all().(u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX.).datesrust-analyzer cargo rrule 0.14.0 core/rruleset/RRuleResult#dates.
37 } else {
38 rrule_set.all_uncheckedrust-analyzer cargo rrule 0.14.0 core/rruleset/impl#[RRuleSet]all_unchecked().()
39 };
40
41 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Actual: {:?}", res);
42 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Expected: {:?}", expected_dates);
43 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
44 res.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
45 expected_dates.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(),
46 "Expected number of returned dates to be equal to the expected"
47 );
48
49 for (actual, expected) in res.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(expected_dates) {
50 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expected);
51 }
52 }
53
54 #[allow(clippy::needless_pass_by_value)]
55 pub fn test_recurring_rrule_setrust-analyzer cargo rrule 0.14.0 tests/common/test_recurring_rrule_set().(rrule_set: RRuleSetrust-analyzer cargo rrule 0.14.0 core/rruleset/RRuleSet#, expected_dates: &[DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>]) {
56 let res = rrule_set.allrust-analyzer cargo rrule 0.14.0 core/rruleset/impl#[RRuleSet]all().(u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX.).datesrust-analyzer cargo rrule 0.14.0 core/rruleset/RRuleResult#dates.;
57
58 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Actual: {:?}", res);
59 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Expected: {:?}", expected_dates);
60 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
61 res.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
62 expected_dates.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(),
63 "Expected number of returned dates to be equal to the expected"
64 );
65
66 for (actual, expected) in res.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(expected_dates) {
67 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(actual, expected);
68 }
69 }
70
71 /// Print and compare 2 lists of dates and panic it they are not the same.
72 pub fn check_occurrencesrust-analyzer cargo rrule 0.14.0 tests/common/check_occurrences().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#>(occurrences: &[DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>], expected: &[S]) {
73 let formatter = |dt: &DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#<Tzrust-analyzer cargo rrule 0.14.0 core/timezone/Tz#>| -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(" \"{}\",\n", dt.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().()) };
74 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
75 "Given: [\n{}]\nExpected: {:#?}",
76 occurrences.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(formatter).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>(),
77 expected
78 );
79 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(occurrences.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), expected.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), "List sizes don't match");
80 for (given, expected) in occurrences.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(expected.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) {
81 let exp_datetime = DateTimerust-analyzer cargo chrono 0.4.40 datetime/DateTime#::parse_from_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<FixedOffset>`]parse_from_rfc3339().(expected.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
82 // Compare items and check if in the same offset/timezone
83 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
84 given.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().(),
85 exp_datetime.to_rfc3339rust-analyzer cargo chrono 0.4.40 datetime/impl#[`DateTime<Tz>`]to_rfc3339().(),
86 "Dates not in same timezone"
87 );
88 }
89 }