use ifc_model::EntityId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ViolationKind {
Dimensionality,
Degenerate,
Disagreement,
OutOfRange,
WrongType,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RuleViolation {
pub entity: EntityId,
pub type_name: String,
pub rule: &'static str,
pub kind: ViolationKind,
pub detail: String,
}
impl RuleViolation {
pub fn new(
entity: EntityId,
type_name: impl Into<String>,
rule: &'static str,
kind: ViolationKind,
detail: impl Into<String>,
) -> Self {
Self {
entity,
type_name: type_name.into(),
rule,
kind,
detail: detail.into(),
}
}
}
impl std::fmt::Display for RuleViolation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{} {} violates {}: {}",
self.entity, self.type_name, self.rule, self.detail
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_names_the_schema_rule_and_the_entity() {
let v = RuleViolation::new(
EntityId(4711),
"IFCAXIS2PLACEMENT3D",
"AxisToRefDirPosition",
ViolationKind::Degenerate,
"Axis is parallel to RefDirection",
);
let text = v.to_string();
assert!(text.contains("#4711"), "{text}");
assert!(text.contains("AxisToRefDirPosition"), "{text}");
assert!(text.contains("parallel"), "{text}");
}
}