| 1 | //! Utility functions around the regexes we use for parsing rrule strings. |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#}; |
| 4 | |
| 5 | use regexrust-analyzer cargo regex 1.11.1 crate/::{Capturesrust-analyzer cargo regex 1.11.1 regex/string/Captures#, Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#}; |
| 6 | |
| 7 | use superrust-analyzer cargo rrule 0.14.0 parser/::{content_linerust-analyzer cargo rrule 0.14.0 parser/content_line/::PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#}; |
| 8 | |
| 9 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 10 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) struct ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 11 | pub yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year.: i32, |
| 12 | pub monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month.: u32, |
| 13 | pub dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day.: u32, |
| 14 | pub timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ParsedDateStringTimerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#>, |
| 15 | pub flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags.: ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#, |
| 16 | } |
| 17 | |
| 18 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 19 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) struct ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags# { |
| 20 | pub zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set.: bool, |
| 21 | } |
| 22 | |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 24 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) struct ParsedDateStringTimerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime# { |
| 25 | pub hourrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#hour.: u32, |
| 26 | pub minrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#min.: u32, |
| 27 | pub secrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#sec.: u32, |
| 28 | } |
| 29 | |
| 30 | fn get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().<T: FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#>( |
| 31 | captures: &Capturesrust-analyzer cargo regex 1.11.1 regex/string/Captures#, |
| 32 | idx: usize, |
| 33 | val: &str, |
| 34 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 35 | captures |
| 36 | .getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(idx) |
| 37 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimeFormatrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeFormat#(val.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 38 | .as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().() |
| 39 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 40 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimeFormatrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeFormat#(val.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 41 | } |
| 42 | |
| 43 | impl ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 44 | /// Parses a date string with format `YYYYMMDD(THHMMSSZ)` where the part in parentheses |
| 45 | /// is optional. It returns [`ParsedDateString`]. |
| 46 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn from_ical_datetimerust-analyzer cargo rrule 0.14.0 parser/regex/impl#[ParsedDateString]from_ical_datetime().(val: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo rrule 0.14.0 parser/regex/impl#[ParsedDateString], ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 47 | static DATESTR_RErust-analyzer cargo rrule 0.14.0 parser/regex/DATESTR_RE.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#<Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#> = OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]new().(); |
| 48 | |
| 49 | let captures = DATESTR_RErust-analyzer cargo rrule 0.14.0 parser/regex/DATESTR_RE. |
| 50 | .get_or_initrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]get_or_init().(|| { |
| 51 | Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#::newrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]new().( |
| 52 | r"(?m)^([0-9]{4})([0-9]{2})([0-9]{2})(T([0-9]{2})([0-9]{2})([0-9]{2})(Z?))?$", |
| 53 | ) |
| 54 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("DATESTR_RE must compile") |
| 55 | }) |
| 56 | .capturesrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]captures().(val) |
| 57 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::InvalidDateTimeFormatrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#InvalidDateTimeFormat#(val.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 58 | |
| 59 | let year = get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().(&captures, 1, val)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 60 | let month = get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().(&captures, 2, val)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 61 | let day = get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().(&captures, 3, val)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 62 | |
| 63 | // Check if time part is captured |
| 64 | let time = if captures.getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(4).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 65 | let hour = get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().(&captures, 5, val)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 66 | let min = get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().(&captures, 6, val)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 67 | let sec = get_datetime_capturesrust-analyzer cargo rrule 0.14.0 parser/regex/get_datetime_captures().(&captures, 7, val)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 68 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ParsedDateStringTimerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime# { hourrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#hour., minrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#min., secrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#sec. }) |
| 69 | } else { |
| 70 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 71 | }; |
| 72 | |
| 73 | let zulu_timezone_set = match captures.getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(8) { |
| 74 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(part) => part.as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."Z", |
| 75 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => false, |
| 76 | }; |
| 77 | let flags = ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags# { zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set. }; |
| 78 | |
| 79 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo rrule 0.14.0 parser/regex/impl#[ParsedDateString] { |
| 80 | yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year., |
| 81 | monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month., |
| 82 | dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day., |
| 83 | timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time., |
| 84 | flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags., |
| 85 | }) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /// Get the line property name, the `RRULE:`, `EXRULE:` etc part. |
| 90 | pub(craterust-analyzer cargo rrule 0.14.0 crate/) fn get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name().(val: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#>, ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#> { |
| 91 | static PARSE_PROPERTY_NAME_RErust-analyzer cargo rrule 0.14.0 parser/regex/PARSE_PROPERTY_NAME_RE.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#<Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#> = OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]new().(); |
| 92 | |
| 93 | PARSE_PROPERTY_NAME_RErust-analyzer cargo rrule 0.14.0 parser/regex/PARSE_PROPERTY_NAME_RE. |
| 94 | .get_or_initrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]get_or_init().(|| { |
| 95 | Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#::newrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]new().(r"(?m)^([A-Z]+?)[:;]").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("PARSE_PROPERTY_NAME_RE regex must compile") |
| 96 | }) |
| 97 | .capturesrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]captures().(val) |
| 98 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|captures| captures.getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(1)) |
| 99 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|name| PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::from_strrust-analyzer cargo rrule 0.14.0 parser/content_line/impl#[PropertyName][FromStr]from_str().(name.as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().())) |
| 100 | .transposerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<Result<T, E>>`]transpose().() |
| 101 | } |
| 102 | |
| 103 | #[cfg(test)] |
| 104 | mod testsrust-analyzer cargo rrule 0.14.0 parser/regex/tests/ { |
| 105 | use craterust-analyzer cargo rrule 0.14.0 crate/::parserrust-analyzer cargo rrule 0.14.0 parser/::{content_linerust-analyzer cargo rrule 0.14.0 parser/content_line/::PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#, regexrust-analyzer cargo rrule 0.14.0 parser/regex/::get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name()., ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#}; |
| 106 | |
| 107 | use superrust-analyzer cargo rrule 0.14.0 parser/regex/::{ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#, ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#, ParsedDateStringTimerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#}; |
| 108 | |
| 109 | const GARBAGE_INPUTSrust-analyzer cargo rrule 0.14.0 parser/regex/tests/GARBAGE_INPUTS.: [&str; 4] = ["", " ", "fasfa!2414", "-20101017T120000Z"]; |
| 110 | |
| 111 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 112 | fn parses_valid_datestrings_correctlyrust-analyzer cargo rrule 0.14.0 parser/regex/tests/parses_valid_datestrings_correctly().() { |
| 113 | let tests = [ |
| 114 | ( |
| 115 | "20101017T120000Z", |
| 116 | ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 117 | yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year.: 2010, |
| 118 | monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month.: 10, |
| 119 | dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day.: 17, |
| 120 | timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ParsedDateStringTimerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime# { |
| 121 | hourrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#hour.: 12, |
| 122 | minrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#min.: 0, |
| 123 | secrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#sec.: 0, |
| 124 | }), |
| 125 | flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags.: ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags# { |
| 126 | zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set.: true, |
| 127 | }, |
| 128 | }, |
| 129 | ), |
| 130 | ( |
| 131 | "20101017", |
| 132 | ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 133 | yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year.: 2010, |
| 134 | monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month.: 10, |
| 135 | dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day.: 17, |
| 136 | timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 137 | flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags.: ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags# { |
| 138 | zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set.: false, |
| 139 | }, |
| 140 | }, |
| 141 | ), |
| 142 | ( |
| 143 | "20220101T121049Z", |
| 144 | ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 145 | yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year.: 2022, |
| 146 | monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month.: 1, |
| 147 | dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day.: 1, |
| 148 | timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ParsedDateStringTimerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime# { |
| 149 | hourrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#hour.: 12, |
| 150 | minrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#min.: 10, |
| 151 | secrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringTime#sec.: 49, |
| 152 | }), |
| 153 | flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags.: ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags# { |
| 154 | zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set.: true, |
| 155 | }, |
| 156 | }, |
| 157 | ), |
| 158 | ( |
| 159 | "20220101", |
| 160 | ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString# { |
| 161 | yearrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#year.: 2022, |
| 162 | monthrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#month.: 1, |
| 163 | dayrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#day.: 1, |
| 164 | timerust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#time.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 165 | flagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#flags.: ParsedDateStringFlagsrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags# { |
| 166 | zulu_timezone_setrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateStringFlags#zulu_timezone_set.: false, |
| 167 | }, |
| 168 | }, |
| 169 | ), |
| 170 | ]; |
| 171 | for (input, expected_output) in tests { |
| 172 | let output = ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#::from_ical_datetimerust-analyzer cargo rrule 0.14.0 parser/regex/impl#[ParsedDateString]from_ical_datetime().(input); |
| 173 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expected_output)); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 178 | fn rejects_invalid_datestringsrust-analyzer cargo rrule 0.14.0 parser/regex/tests/rejects_invalid_datestrings().() { |
| 179 | let tests = [ |
| 180 | GARBAGE_INPUTSrust-analyzer cargo rrule 0.14.0 parser/regex/tests/GARBAGE_INPUTS..to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(), |
| 181 | [ |
| 182 | "-20101017T120000Z", |
| 183 | "20101017T", |
| 184 | "201010177", |
| 185 | "20101017T1200", |
| 186 | "210101017T1200", |
| 187 | ] |
| 188 | .to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(), |
| 189 | ] |
| 190 | .concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().(); |
| 191 | for input in tests { |
| 192 | let res = ParsedDateStringrust-analyzer cargo rrule 0.14.0 parser/regex/ParsedDateString#::from_ical_datetimerust-analyzer cargo rrule 0.14.0 parser/regex/impl#[ParsedDateString]from_ical_datetime().(input); |
| 193 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 198 | fn parses_property_name_from_linerust-analyzer cargo rrule 0.14.0 parser/regex/tests/parses_property_name_from_line().() { |
| 199 | let tests = [ |
| 200 | ( |
| 201 | "RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30", |
| 202 | PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::RRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#RRule#, |
| 203 | ), |
| 204 | ( |
| 205 | "EXRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30", |
| 206 | PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::ExRulerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#ExRule#, |
| 207 | ), |
| 208 | ( |
| 209 | "DTSTART;TZID=America/Everywhere:20120251T023000Z\nFREQ=DAILY;INTERVAL=1;", |
| 210 | PropertyNamerust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#::DtStartrust-analyzer cargo rrule 0.14.0 parser/content_line/PropertyName#DtStart#, |
| 211 | ), |
| 212 | ]; |
| 213 | for (input, expected_output) in tests { |
| 214 | let output = get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name().(input); |
| 215 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected_output))); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 220 | fn parses_line_without_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/tests/parses_line_without_property_name().() { |
| 221 | let tests = [ |
| 222 | GARBAGE_INPUTSrust-analyzer cargo rrule 0.14.0 parser/regex/tests/GARBAGE_INPUTS..to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(), |
| 223 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 224 | "FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30", |
| 225 | "TZID=America/Everywhere:20120251T023000Z\nFREQ=DAILY;INTERVAL=1;", |
| 226 | ], |
| 227 | ] |
| 228 | .concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().(); |
| 229 | for input in tests { |
| 230 | let res = get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name().(input); |
| 231 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(res, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 236 | fn rejects_line_with_invalid_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/tests/rejects_line_with_invalid_property_name().() { |
| 237 | let tests = [ |
| 238 | ( |
| 239 | "RRULES:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30", |
| 240 | ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::UnrecognizedPropertyNamerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#UnrecognizedPropertyName#("RRULES".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 241 | ), |
| 242 | ( |
| 243 | "START;TZID=America/Everywhere:20120251T023000Z\nFREQ=DAILY;INTERVAL=1;", |
| 244 | ParseErrorrust-analyzer cargo rrule 0.14.0 parser/error/ParseError#::UnrecognizedPropertyNamerust-analyzer cargo rrule 0.14.0 parser/error/ParseError#UnrecognizedPropertyName#("START".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 245 | ), |
| 246 | ]; |
| 247 | for (input, expected_output) in tests { |
| 248 | let output = get_property_namerust-analyzer cargo rrule 0.14.0 parser/regex/get_property_name().(input); |
| 249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(expected_output)); |
| 250 | } |
| 251 | } |
| 252 | } |