Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/winnow-datetime-assert/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0 - 2015-05-14
* Added support for winnow-datetime 0.3.0 objects
* Added assersions for Calendar and TimeZone

## 0.2.0 - 2024-05-04
* Changed parser signatures to meet winnow 0.7 standards
* Removed dependency on galvanic-test which was accidentally left over from some initial design experiments.
Expand Down
6 changes: 3 additions & 3 deletions crates/winnow-datetime-assert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "winnow_datetime_assert"
version = "0.2.0"
version = "0.3.0"
description = "Testing/Benchmarking winnow-datetime parsers"
keywords = [ "iso8601", "date-time", "parser", "winnow" ]
keywords = [ "date-time", "parser", "winnow" ]
categories = [ "parser-implementations", "date-and-time" ]

repository = "https://github.com/soulstompp/winnow-datetime"
Expand All @@ -13,7 +13,7 @@ readme = "README.md"
edition = "2021"

[dependencies]
winnow_datetime = { path = "../winnow-datetime", version = "0.2", features = ["serde"] }
winnow_datetime = { path = "../winnow-datetime", version = "0.3", features = ["serde"] }
libtest-mimic = "0.8.1"
winnow = "0.7"
serde = { version = "1.0", features = ["derive"] }
Expand Down
11 changes: 11 additions & 0 deletions crates/winnow-datetime-assert/data/assertions/calendar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
assertions:
- format: "gregory"
input: "gregory"
expected:
identifier: "gregory"
critical: false
- format: "islamic-umalqura"
input: "islamic-umalqura"
expected:
identifier: "islamic-umalqura"
critical: false
36 changes: 24 additions & 12 deletions crates/winnow-datetime-assert/data/assertions/interval.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,10 @@ assertions:
hour: 7
minute: 42
offset:
offset_hours: 0
offset_minutes: 0
!Fixed
hours: 0
minutes: 0
critical: false
duration:
days: 1
hours: 1
Expand Down Expand Up @@ -549,8 +551,10 @@ assertions:
hour: 7
minute: 42
offset:
offset_hours: 0
offset_minutes: 0
!Fixed
hours: 0
minutes: 0
critical: false
duration:
days: 1
hours: 1
Expand Down Expand Up @@ -634,8 +638,10 @@ assertions:
hour: 7
minute: 42
offset:
offset_hours: 0
offset_minutes: 0
!Fixed
hours: 0
minutes: 0
critical: false
duration:
days: 1
hours: 1
Expand Down Expand Up @@ -727,8 +733,10 @@ assertions:
hour: 15
minute: 42
offset:
offset_hours: 0
offset_minutes: 0
!Fixed
hours: 0
minutes: 0
critical: false
- format: "P1DT1H/%V-W%W-%wT%h"
input: "P1DT1H/2024-W51-7T07"
expected:
Expand Down Expand Up @@ -817,8 +825,10 @@ assertions:
hour: 15
minute: 42
offset:
offset_hours: 0
offset_minutes: 0
!Fixed
hours: 0
minutes: 0
critical: false
- format: "P1DT1H/%Y-%OT%h"
input: "P1DT1H/2024-357T07"
expected:
Expand Down Expand Up @@ -902,8 +912,10 @@ assertions:
hour: 15
minute: 42
offset:
offset_hours: 0
offset_minutes: 0
!Fixed
hours: 0
minutes: 0
critical: false
- format: "%Y/%Y"
input: "2024/2024"
expected:
Expand Down
39 changes: 24 additions & 15 deletions crates/winnow-datetime-assert/data/assertions/offset.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
assertions:
- format: "%Z:%z"
input: "-08:00"
expected:
offset_hours: -8
offset_minutes: 0
expected: !Fixed
hours: -8
minutes: 0
critical: false
- format: "Z"
input: "Z"
expected:
offset_hours: 0
offset_minutes: 0
expected: !Fixed
hours: 0
minutes: 0
critical: false
- format: "z"
input: "z"
expected:
offset_hours: 0
offset_minutes: 0
expected: !Fixed
hours: 0
minutes: 0
critical: false
- format: "-00:00"
input: "-00:00"
expected: !Fixed
hours: 0
minutes: 0
critical: false
- format: "%Z"
input: "-08"
expected:
offset_hours: -8
offset_minutes: 0
expected: !Fixed
hours: -8
minutes: 0
critical: false
- format: "%Z%z"
input: "-0800"
expected:
offset_hours: -8
offset_minutes: 0
expected: !Fixed
hours: -8
minutes: 0
critical: false
14 changes: 14 additions & 0 deletions crates/winnow-datetime-assert/data/assertions/time.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ assertions:
minute: 42
second: 55
millisecond: 800
- format: "%h:%m:%,1s"
input: "07:42:55.8"
expected:
hour: 7
minute: 42
second: 55
millisecond: 800
- format: "%h:%m:%,2s"
input: "07:42:55.87"
expected:
hour: 7
minute: 42
second: 55
millisecond: 870
- format: "%h:%m:%.2s"
input: "07:42:55.87"
expected:
Expand Down
61 changes: 61 additions & 0 deletions crates/winnow-datetime-assert/data/assertions/time_zone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
assertions:
- format: "%Z:%z"
input: "-08:00"
expected:
!Fixed
offset:
!Fixed
hours: -8
minutes: 0
critical: false

- format: "Z"
input: "Z"
expected:
!Fixed
offset:
!LocalUnknown
critical: false

- format: "z"
input: "z"
expected:
!Fixed
offset:
!LocalUnknown
critical: false

- format: "-00:00"
input: "-00:00"
expected:
!Fixed
offset:
!LocalUnknown
critical: false

- format: "%Z"
input: "-08"
expected:
!Fixed
offset:
!Fixed
hours: -8
minutes: 0
critical: false

- format: "%Z%z"
input: "-0800"
expected:
!Fixed
offset:
!Fixed
hours: -8
minutes: 0
critical: false
- format: "America/Los_Angeles"
input: "America/Los_Angeles"
expected:
!Named
zone:
identifier: "America/Los_Angeles"
critical: false
40 changes: 40 additions & 0 deletions crates/winnow-datetime-assert/src/calendar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::{FormatAssertion, FormatAssertionBuilder, FormatCoverage, FormatCoverageBuilder};
use serde::Deserialize;
use winnow_datetime::types::Calendar;

#[derive(Debug, Deserialize)]
pub struct CalendarAssertion {
assertions: Vec<FormatAssertion<Calendar>>,
}

impl FormatAssertionBuilder<Calendar> for CalendarAssertion {
fn piece() -> &'static str {
"calendar"
}

fn base_assertions(&self) -> Vec<FormatAssertion<Calendar>> {
self.assertions.clone()
}

fn assertions(&self) -> Vec<FormatAssertion<Calendar>> {
self.base_assertions()
}
}

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct CalendarCoverage {
pub coverage: Vec<FormatCoverage<Calendar>>,
}

impl FormatCoverageBuilder<Calendar> for CalendarCoverage {
fn piece() -> &'static str {
"calendar"
}
fn base_coverage(&self) -> Vec<FormatCoverage<Calendar>> {
self.coverage.clone()
}

fn coverage(&self) -> Vec<FormatCoverage<Calendar>> {
vec![]
}
}
38 changes: 34 additions & 4 deletions crates/winnow-datetime-assert/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::Deserialize;
use std::collections::HashMap;
use std::path::PathBuf;

mod clippy;
Expand All @@ -21,6 +22,13 @@ pub use offset::{OffsetAssertion, OffsetCoverage};
pub mod time;
pub use time::{TimeAssertion, TimeCoverage};

pub mod calendar;
pub mod time_zone;

pub use time_zone::{TimeZoneAssertion, TimeZoneCoverage};

pub use calendar::{CalendarAssertion, CalendarCoverage};

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct FormatAssertion<T> {
pub format: String,
Expand All @@ -47,12 +55,34 @@ pub trait FormatAssertionBuilder<T> {

fn base_assertions(&self) -> Vec<FormatAssertion<T>>;
fn assertions(&self) -> Vec<FormatAssertion<T>>;

fn base_assertion_map(&self) -> HashMap<String, T>
where
T: Clone,
{
self.base_assertions()
.into_iter()
.map(|a| (a.format, a.expected))
.collect()
}
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
pub enum Exception<T> {
Specific { value: T },
Unspecified,
}

impl<T> Default for Exception<T> {
fn default() -> Self {
Exception::Unspecified
}
}

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct FormatCoverage<T> {
pub format: String,
pub exception: Option<T>,
pub exception: Exception<T>,
pub complete: bool,
}

Expand Down Expand Up @@ -118,9 +148,9 @@ macro_rules! define_format_tests {
.into_iter()
.fold((vec![], vec![]), |(mut covered, mut uncovered), a| {
if let Some(c) = coverages.iter().find(|f| f.format == a.format) {
if let Some(e) = c.exception {
if let Exception::Specific { value: e } = &c.exception {
let mut a = a.clone();
a.expected = e;
a.expected = e.clone();
covered.push(a);
} else {
covered.push(a);
Expand Down Expand Up @@ -169,7 +199,7 @@ macro_rules! define_format_tests {
let result = parse_input(&mut assertion.input.as_str());

// If covered, the result must match the expected value
if result != Ok(assertion.expected) {
if result != Ok(assertion.expected.clone()) {
return Err(Failed::from(format!(
"Covered format mismatch: {}\nExpected: {:?}\nGot: {:?}",
assertion.format, assertion.expected, result
Expand Down
Loading
Loading