XSD: Adds tests for "minimal conformance"

pull/389/head
Tpt 2 years ago committed by Thomas Tanon
parent cb2c891979
commit 909a906d2a
  1. 27
      lib/oxsdatatypes/src/date_time.rs
  2. 23
      lib/oxsdatatypes/src/decimal.rs
  3. 21
      lib/oxsdatatypes/src/duration.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(())
}
}

@ -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(())
}
}

@ -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(())
}
}

Loading…
Cancel
Save