Skip to content
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

parse-zoneinfo: replace rule parser with simple state machine #172

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions parse-zoneinfo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ keywords = ["date", "time", "timezone", "zone", "calendar"]
version = "1.3.1"
default-features = false
features = ["std", "unicode-perl"]

[dev-dependencies]
insta = "1.38"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you added this test. Not sure about it though.

Would it be better to add this test as a separate crate in the workspace?

30 changes: 30 additions & 0 deletions parse-zoneinfo/tests/snapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::error::Error;

use insta::assert_debug_snapshot;

use parse_zoneinfo::line::{Line, LineParser};
use parse_zoneinfo::FILES;

#[ignore]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added #[ignore] here because this test will fail every time we update the tz data. Not sure how big of a pain in the ass that will be to update? Using the cargo-insta tooling it is pretty easy so we might decide to just include this.

#[test]
fn test_parse() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let mut files = vec![];
let parser = LineParser::default();
for file in FILES {
let path = format!("../chrono-tz/tz/{}", file);
let text = std::fs::read_to_string(&path)?;
let mut lines = vec![];
for ln in text.lines() {
dbg!(ln);
match parser.parse_str(ln)? {
Line::Space => continue,
ln => lines.push(format!("{:?}", ln)),
}
}

files.push((file, lines));
}

assert_debug_snapshot!(files);
Ok(())
}
Loading