use ifc_alignment::{linear_element, linear_positioning_element};
use ifc_model::{Entity, Model, Transaction, Value};
use ifc_schema::{ifc4, ifc4x3};
const GUID: &str = "1hqA$QMHj8nB$JURcqgIm7";
#[test]
fn a_linear_element_needs_no_placement() {
let mut model = Model::default();
let mut tx = Transaction::new(&model);
let id = linear_element(&mut tx, GUID, Some("Carriageway"), None).expect("linear element");
tx.commit(&mut model).expect("commit");
let staged = model.get(id).expect("staged");
assert_eq!(staged.type_name.as_ref(), "IFCLINEARELEMENT");
assert_eq!(staged.attributes.len(), 7, "product arity");
assert_eq!(
staged.attributes[5],
Value::Null,
"ObjectPlacement stays absent",
);
}
#[test]
fn a_positioning_element_requires_its_placement() {
let mut model = Model::default();
let mut tx = Transaction::new(&model);
let placement = tx.create(Entity::new("IFCLOCALPLACEMENT", vec![Value::Null; 2]));
let id =
linear_positioning_element(&mut tx, GUID, None, placement).expect("positioning element");
tx.commit(&mut model).expect("commit");
let staged = model.get(id).expect("staged");
assert_eq!(staged.type_name.as_ref(), "IFCLINEARPOSITIONINGELEMENT",);
assert_eq!(staged.attributes[5], Value::Ref(placement));
}
#[test]
fn a_malformed_global_id_is_refused() {
let model = Model::default();
let mut tx = Transaction::new(&model);
let placement = tx.create(Entity::new("IFCLOCALPLACEMENT", vec![Value::Null; 2]));
assert!(linear_element(&mut tx, "short", None, None).is_err());
assert!(linear_positioning_element(&mut tx, "short", None, placement).is_err(),);
}
#[test]
fn both_are_ifc4x3_additions() {
for name in ["IfcLinearElement", "IfcLinearPositioningElement"] {
assert!(
ifc4().entity(name).is_none(),
"{name} should be absent from IFC4",
);
assert_eq!(
ifc4x3().attribute_names(name).len(),
7,
"{name} arity drifted from the schema",
);
}
assert_eq!(
ifc4x3().attribute_names("IfcLinearElement")[5],
"ObjectPlacement",
"slot 5 is the placement the rule talks about",
);
}