use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ValidateError {
UnknownSchema(String),
UnbundledSchema(String),
NoSchemaDeclared,
}
impl fmt::Display for ValidateError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownSchema(token) => {
write!(f, "unrecognised schema token {token:?}")
}
Self::UnbundledSchema(token) => {
write!(f, "no schema tables bundled for {token:?}")
}
Self::NoSchemaDeclared => f.write_str("the file declares no schema"),
}
}
}
impl std::error::Error for ValidateError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_two_schema_refusals_are_distinguishable() {
let unknown = ValidateError::UnknownSchema("STEP".into()).to_string();
let unbundled = ValidateError::UnbundledSchema("IFC_FUTURE_PROFILE".into()).to_string();
assert_ne!(unknown, unbundled);
assert!(unbundled.contains("IFC_FUTURE_PROFILE"));
assert!(unknown.contains("STEP"));
}
}