-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge branch 'filter-by-regex' #57
Changes from all commits
ae65e35
de2c685
ce7b940
0f4bba8
cbbc80a
bcd64a9
5a19321
fd01ce7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "check-regex-filtering" | ||
version = "0.1.0" | ||
authors = ["Philip Daniels <Philip.Daniels1971@gmail.com>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
chrono = "0.4" | ||
chrono-tz = { path = "../../", default-features = false } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/// This test is compiled by the Github workflows with the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks fantastic, exactly what I hoped for. Could you either either document the way that this checks the recursive timezone check, or change the filter to filter out something that would only be filtered out if the filter applied recursively? For example, changing the filter to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a few more tests and some comments explaining what I think should be included and excluded. This stuff does get tricky...if we take your example of 'Europe' for example you get some Asian timezones - because of Istanbul! It all depends what's in the links, and I guess that is subject to change so we should be careful of how restrictive we are. |
||
/// filter regex set thusly: CHRONO_TZ_BUILD_TIMEZONES="(Europe/London|GMT)" | ||
/// | ||
/// We use it to check two things: | ||
/// 1) That the compiled chrono-tz contains the correct timezones (a compilation | ||
/// failure will result if it doesn't). | ||
/// 2) That the compiled chrono-tz DOES NOT contain other, non-matched, | ||
/// timezones. This is rather trickier to do without triggering a compilation | ||
/// failure: we try our best by looking over the TZ_VARIANTS array to try and | ||
/// ascertain if it contains anything obviously wrong. | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use chrono::offset::TimeZone; | ||
use chrono_tz::{Europe, Europe::London, Tz, TZ_VARIANTS}; | ||
use std::str::FromStr; | ||
|
||
#[test] | ||
fn london_compiles() { | ||
// This line will be a compilation failure if the code generation | ||
// mistakenly excluded Europe::London. | ||
let _london_time = London.ymd(2013, 12, 25).and_hms(14, 0, 0); | ||
assert_eq!("Europe/London", London.name()); | ||
|
||
// Since London is included, converting from the corresponding | ||
// string representation should also work. | ||
assert_eq!(Tz::from_str("Europe/London"), Ok(London)); | ||
|
||
// We did not explicitly ask for Isle Of Man or Belfast in our regex, but there is a link | ||
// from Europe::London to Isle_of_Man and Belfast (amongst others) | ||
// so these conversions should also work. | ||
assert_eq!(Tz::from_str("Europe/Isle_of_Man"), Ok(Europe::Isle_of_Man)); | ||
assert_eq!(Tz::from_str("Europe/Belfast"), Ok(Europe::Belfast)); | ||
} | ||
|
||
#[test] | ||
fn excluded_things_are_missing() { | ||
// Timezones from outside Europe should not be included. | ||
// We can't test all possible strings, here we just handle a | ||
// representative set. | ||
assert!(Tz::from_str("Australia/Melbourne").is_err()); | ||
assert!(Tz::from_str("Indian/Maldives").is_err()); | ||
assert!(Tz::from_str("Mexico/BajaSur").is_err()); | ||
assert!(Tz::from_str("Pacific/Kwajalein").is_err()); | ||
assert!(Tz::from_str("US/Central").is_err()); | ||
|
||
// The link table caused us to include some extra items from the UK (see | ||
// `london_compiles()`), but it should NOT include various other timezones | ||
// from around Europe since there is no linkage between them. | ||
assert!(Tz::from_str("Europe/Brussels").is_err()); | ||
assert!(Tz::from_str("Europe/Dublin").is_err()); | ||
assert!(Tz::from_str("Europe/Warsaw").is_err()); | ||
|
||
// Also, entire continents outside Europe should be excluded. | ||
for tz in TZ_VARIANTS.iter() { | ||
assert!(!tz.name().starts_with("Africa")); | ||
assert!(!tz.name().starts_with("Asia")); | ||
assert!(!tz.name().starts_with("Australia")); | ||
assert!(!tz.name().starts_with("Canada")); | ||
assert!(!tz.name().starts_with("Chile")); | ||
assert!(!tz.name().starts_with("Indian")); | ||
assert!(!tz.name().starts_with("Mexico")); | ||
assert!(!tz.name().starts_with("Pacific")); | ||
assert!(!tz.name().starts_with("US")); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work to make this optional, and put it behind a
"filter-timezones"
feature? I'm genuinely not sure if you cancfg(feature = "filter-timezones")
in a build.rs file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't swear to it, but I don't think it's possible. I tried making a commit here and it is easy enough to refactor
chrono-tz
itself to use the feature and conditionally compile out all the relevant regex code, but then using it from the test example doesn't seem to work. I think features are not passed through as one would want. This might be relevant:rust-lang/cargo#5499