From a82d374de08460f885c88873e5e3f530fbe892b0 Mon Sep 17 00:00:00 2001 From: Tpt Date: Mon, 20 Feb 2023 17:47:48 +0100 Subject: [PATCH] XSD: Adds tests for "minimal conformance" --- lib/oxsdatatypes/src/date_time.rs | 27 +++++++++++++++++++++++++++ lib/oxsdatatypes/src/decimal.rs | 23 +++++++++++++++++++++++ lib/oxsdatatypes/src/duration.rs | 21 +++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/lib/oxsdatatypes/src/date_time.rs b/lib/oxsdatatypes/src/date_time.rs index 0f3c66b6..48fb91f7 100644 --- a/lib/oxsdatatypes/src/date_time.rs +++ b/lib/oxsdatatypes/src/date_time.rs @@ -2487,4 +2487,31 @@ mod tests { assert!(now < DateTime::from_str("2100-01-01T00:00:00Z")?); Ok(()) } + + #[test] + fn minimally_conformant() -> Result<(), XsdParseError> { + // All minimally conforming processors must support nonnegative year values less than 10000 + // (i.e., those expressible with four digits) in all datatypes which + // use the seven-property model defined in The Seven-property Model (§D.2.1) + // and have a non-absent value for year (i.e. dateTime, dateTimeStamp, date, gYearMonth, and gYear). + assert_eq!(GYear::from_str("9999")?.to_string(), "9999"); + assert_eq!( + DateTime::from_str("9999-12-31T23:59:59Z")?.to_string(), + "9999-12-31T23:59:59Z" + ); + + // All minimally conforming processors must support second values to milliseconds + // (i.e. those expressible with three fraction digits) in all datatypes + // which use the seven-property model defined in The Seven-property Model (§D.2.1) + // and have a non-absent value for second (i.e. dateTime, dateTimeStamp, and time). + assert_eq!( + Time::from_str("00:00:00.678Z")?.to_string(), + "00:00:00.678Z" + ); + assert_eq!( + DateTime::from_str("2000-01-01T00:00:00.678Z")?.to_string(), + "2000-01-01T00:00:00.678Z" + ); + Ok(()) + } } diff --git a/lib/oxsdatatypes/src/decimal.rs b/lib/oxsdatatypes/src/decimal.rs index 3b6ea6af..43a9a8de 100644 --- a/lib/oxsdatatypes/src/decimal.rs +++ b/lib/oxsdatatypes/src/decimal.rs @@ -810,4 +810,27 @@ mod tests { assert!(Decimal::try_from(Double::from(f64::MAX)).is_err()); Ok(()) } + + #[test] + fn minimally_conformant() -> Result<(), ParseDecimalError> { + // All minimally conforming processors must support decimal values whose absolute value can be expressed as i / 10^k, + // where i and k are nonnegative integers such that i < 10^16 and k ≤ 16 (i.e., those expressible with sixteen total digits). + assert_eq!( + Decimal::from_str("1234567890123456")?.to_string(), + "1234567890123456" + ); + assert_eq!( + Decimal::from_str("-1234567890123456")?.to_string(), + "-1234567890123456" + ); + assert_eq!( + Decimal::from_str("0.1234567890123456")?.to_string(), + "0.1234567890123456" + ); + assert_eq!( + Decimal::from_str("-0.1234567890123456")?.to_string(), + "-0.1234567890123456" + ); + Ok(()) + } } diff --git a/lib/oxsdatatypes/src/duration.rs b/lib/oxsdatatypes/src/duration.rs index 6998164e..27f255eb 100644 --- a/lib/oxsdatatypes/src/duration.rs +++ b/lib/oxsdatatypes/src/duration.rs @@ -771,4 +771,25 @@ mod tests { ); Ok(()) } + + #[test] + fn minimally_conformant() -> Result<(), XsdParseError> { + // All minimally conforming processors must support fractional-second duration values + // to milliseconds (i.e. those expressible with three fraction digits). + assert_eq!(Duration::from_str("PT0.001S")?.to_string(), "PT0.001S"); + assert_eq!(Duration::from_str("-PT0.001S")?.to_string(), "-PT0.001S"); + + // All minimally conforming processors must support duration values with months values + // in the range −119999 to 119999 months (9999 years and 11 months) + // and seconds values in the range −31622400 to 31622400 seconds (one leap-year). + assert_eq!( + Duration::from_str("P119999MT31622400S")?.to_string(), + "P9999Y11M366D" + ); + assert_eq!( + Duration::from_str("-P119999MT31622400S")?.to_string(), + "-P9999Y11M366D" + ); + Ok(()) + } }