ifc_validate/where_rule/
engine.rs1use ifc_model::Model;
4use ifc_schema::Schema;
5
6use super::budget::Budget;
7use super::builtin;
8use super::registry::{self, Support};
9use crate::report::{Finding, Path, Report};
10
11pub fn evaluate(model: &Model, schema: &Schema, budget: Budget, report: &mut Report) {
18 evaluate_except(model, schema, budget, report, &|_| false, false);
19}
20
21pub(crate) fn evaluate_except(
28 model: &Model,
29 schema: &Schema,
30 budget: Budget,
31 report: &mut Report,
32 superseded: &dyn Fn(&str) -> bool,
33 express: bool,
34) {
35 if let Some(version) = schema.version().filter(|_| !express) {
39 if !registry::RULES
40 .iter()
41 .any(|entry| entry.applies_to(schema) && entry.id != registry::UNIQUE_GLOBAL_ID)
42 {
43 report.push(Finding::unsupported(
44 "where.release",
45 Path::File,
46 format!(
47 "no WHERE rule is registered for {}; structural and type checks \
48 ran against its own tables, WHERE rules were not evaluated",
49 version.release_id()
50 ),
51 ));
52 return;
53 }
54 }
55 for entry in registry::implemented() {
56 if entry.applies_to(schema) && !superseded(entry.id) {
57 let dispatched = builtin::run(entry, model, schema, report);
58 debug_assert!(dispatched, "{} has no native implementation", entry.id);
59 }
60 }
61
62 for entry in registry::unsupported() {
63 if report.findings().len() >= budget.max_findings {
64 report.mark_truncated();
65 return;
66 }
67 let Support::Unsupported(reason) = entry.support else {
68 continue;
69 };
70 if !entry.applies_to(schema) || superseded(entry.id) {
71 continue;
72 }
73 if let Some(entity) = entry.entity {
76 if !model_contains(model, schema, entity) {
77 continue;
78 }
79 }
80 report.push(Finding::unsupported(entry.id, Path::File, reason));
81 }
82}
83
84fn model_contains(model: &Model, schema: &Schema, entity: &str) -> bool {
86 model
87 .type_histogram()
88 .iter()
89 .any(|(name, _)| schema.is_a(name, entity))
90}
91
92#[cfg(all(test, feature = "ifc4"))]
93mod intermediate_release_tests {
94 use super::*;
95 use crate::report::Severity;
96
97 #[test]
101 fn an_unscoped_release_reports_that_where_rules_did_not_run() {
102 for schema in [ifc_schema::ifc4x1(), ifc_schema::ifc4x2()] {
103 let mut report = Report::new();
104 evaluate(&Model::new(), schema, Budget::default(), &mut report);
105 let findings = report.findings();
106 assert_eq!(findings.len(), 1, "{}", schema.name());
107 assert_eq!(findings[0].rule, "where.release");
108 assert_eq!(findings[0].severity, Severity::Unsupported);
109 }
110 let mut report = Report::new();
111 evaluate(
112 &Model::new(),
113 ifc_schema::ifc4(),
114 Budget::default(),
115 &mut report,
116 );
117 assert!(report.findings().iter().all(|f| f.rule != "where.release"));
118 }
119}