-
Notifications
You must be signed in to change notification settings - Fork 18
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
Clean slate with Winnow 2 #86
base: main
Are you sure you want to change the base?
Conversation
@tertsdiepraam I squashed your commits into a single commit, I hope you don't mind |
ff67b9e
to
85d7574
Compare
Looks cool! A few initial comments to send you in the right direction. One of the reasons for this rewrite is that chrono wasn't cutting it for adding all the items together. Instead we should add all the items together ourselves to really match GNU. It'll require a lot of experimentation, but it'll make the compatibility much better. I think most of the corner cases were around the ends of months. I believe GNU had some overflow behaviour there that chrono didn't. So I recommend first creating a custom datetime struct to manipulate and then mapping that to chrono. Squashing the commit is absolutely fine by the way. Thanks for continuing this! |
5516eed
to
9388e45
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
===========================================
- Coverage 85.93% 62.66% -23.28%
===========================================
Files 6 9 +3
Lines 853 1248 +395
Branches 188 409 +221
===========================================
+ Hits 733 782 +49
- Misses 117 134 +17
- Partials 3 332 +329
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@tertsdiepraam I was looking into the fuzzy testing. I added the code so it generates fuzzy dates with some sanity and caught some problems, I will look into them next. |
fuzz/fuzz_targets/parse_datetime.rs
Outdated
// Testing GNU compatibility by calling date and | ||
// comparing the inputs | ||
|
||
// let fmt = "%Y-%m-%d %H:%M:%S"; | ||
// let mut output: process::Output = std::process::Command::new("date") | ||
// .arg("-d") | ||
// .arg(s) | ||
// .arg(format!("+{fmt}")) | ||
// .output() | ||
// .expect("date command failed"); | ||
// io::stdout().write_all(&output.stdout).unwrap(); | ||
// io::stdout().write_all(&output.stderr).unwrap(); | ||
// output.stdout.pop(); // remove trailing \n | ||
// assert_eq!( | ||
// String::from_utf8(output.stdout).unwrap(), | ||
// d.format(fmt).to_string() | ||
// ); |
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 was testing something like this to determine its compatibility with GNU. The test run GNU date
in and compare the outputs
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.
We could definitely do that with fuzzing! We should still rely on regular tests as well though.
2389d91
to
025808c
Compare
src/lib.rs
Outdated
#[test] | ||
fn chrono_date() { | ||
const FMT: &str = "%Y-%m-%d %H:%M:%S"; | ||
let input = "262144-03-10 00:00:00"; | ||
|
||
// chrono rejects this specific date | ||
assert!(NaiveDate::from_ymd_opt(262144, 3, 10).is_none()); | ||
assert!(chrono::DateTime::parse_from_str(input, FMT).is_err()); | ||
// the parsing works, but hydration fails | ||
assert!(items::parse(&mut input.to_string().as_str()).is_ok()); | ||
assert!(parse_datetime(input).is_err()); | ||
// GNU date works | ||
assert_eq!(make_gnu_date(input, FMT), input); | ||
} |
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.
@tertsdiepraam I found a case where GNU accepts the date, we can parse it and chrono rejects it, more precisely chrono::NaiveDate::from_ymd_opt returns None for this date. I don't know what direction to take from there, chrono keeps getting in the way 😅 ideas? Maybe having a gnu-compatible datetime layer, but that will be a lot of work
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.
307c159
to
a434820
Compare
sorry but some tests are failing:
and needs some rebasing |
I will rebase it But right now I have a problem with Chrono, I'm looking into alternatives like https://time-rs.github.io/book/how-to/create-dates.html |
fb36b99
to
c5b5b9a
Compare
Hello, I updated the PR, some key notes:
Let me know what you think, if this is too bad, or if it is okay for now. I guess that to achieve 100% BTW I was playing with GNU date and I found this behavior
Here
|
9eefad4
to
7a43f13
Compare
Cargo.toml
Outdated
[features] | ||
debug = ["winnow/debug"] | ||
|
||
[[bin]] |
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.
should be done in a different PR, no?
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.
Yes! I added to compare some dates with GNU, I'm removing this
@@ -15,6 +15,9 @@ chrono = { version="0.4", default-features=false, features=["std", "alloc", "clo | |||
[dependencies.parse_datetime] | |||
path = "../" | |||
|
|||
[features] |
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.
same, why in this PR ?
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.
To see the trace output I need build it with winnow/debug/ feature. I tried cargo fuzz --features winnow/debug
but it didn't worked. So I added this debug feature that depends on winnow/debug and I can enable it instead
543d529
to
235086b
Compare
Continuing the rewrite started by @tertsdiepraam #61
lib.rs
keep the same signaturelib.rs
too all they are passing@\d+
formatMMDDhhmm