use super::*;
#[test]
fn test_schema_geometry_categories() {
let schema = IfcSchema::new();
assert_eq!(
schema.geometry_category(&IfcType::IfcExtrudedAreaSolid),
Some(GeometryCategory::SweptSolid)
);
assert_eq!(
schema.geometry_category(&IfcType::IfcBooleanResult),
Some(GeometryCategory::Boolean)
);
assert_eq!(
schema.geometry_category(&IfcType::IfcTriangulatedFaceSet),
Some(GeometryCategory::ExplicitMesh)
);
assert_eq!(
schema.profile_category(&IfcType::IfcRoundedRectangleProfileDef),
Some(ProfileCategory::Parametric)
);
}
#[test]
fn test_parse_index_list_rejects_out_of_range() {
let face = AttributeValue::List(vec![
AttributeValue::Integer(5_000_000_000), AttributeValue::Integer(0), AttributeValue::Integer(-4), ]);
let out = AttributeValue::parse_index_list(&[face]);
assert_eq!(out, vec![u32::MAX, u32::MAX, u32::MAX]);
let ok = AttributeValue::List(vec![
AttributeValue::Integer(1),
AttributeValue::Integer(2),
AttributeValue::Integer(3),
]);
assert_eq!(AttributeValue::parse_index_list(&[ok]), vec![0, 1, 2]);
}
#[test]
fn test_parse_index_list_extreme_i64_values() {
let face = AttributeValue::List(vec![
AttributeValue::Integer(i64::MIN),
AttributeValue::Integer(i64::MAX),
AttributeValue::Integer(4_294_967_297),
]);
let out = AttributeValue::parse_index_list(&[face]);
assert_eq!(out, vec![u32::MAX, u32::MAX, u32::MAX]);
let boundary = AttributeValue::List(vec![
AttributeValue::Integer(4_294_967_295), AttributeValue::Integer(4_294_967_296), AttributeValue::Integer(2),
]);
assert_eq!(
AttributeValue::parse_index_list(&[boundary]),
vec![u32::MAX - 1, u32::MAX, 1]
);
}
#[test]
fn test_attribute_value_conversion() {
let token = Token::EntityRef(123);
let attr = AttributeValue::from_token(&token);
assert_eq!(attr.as_entity_ref(), Some(123));
let token = Token::String(b"test");
let attr = AttributeValue::from_token(&token);
assert_eq!(attr.as_string(), Some("test"));
}
#[test]
fn test_decoded_entity() {
let entity = DecodedEntity::new(
1,
IfcType::IfcWall,
vec![
AttributeValue::EntityRef(2),
AttributeValue::String("Wall-001".to_string()),
AttributeValue::Float(3.5),
],
);
assert_eq!(entity.get_ref(0), Some(2));
assert_eq!(entity.get_string(1), Some("Wall-001"));
assert_eq!(entity.get_float(2), Some(3.5));
}
#[test]
fn test_as_float_with_typed_value() {
let plain_float = AttributeValue::Float(0.5);
assert_eq!(plain_float.as_float(), Some(0.5));
let integer = AttributeValue::Integer(42);
assert_eq!(integer.as_float(), Some(42.0));
let typed_value = AttributeValue::List(vec![
AttributeValue::String("IFCNORMALISEDRATIOMEASURE".to_string()),
AttributeValue::Float(0.5),
]);
assert_eq!(typed_value.as_float(), Some(0.5));
let typed_int = AttributeValue::List(vec![
AttributeValue::String("IFCINTEGER".to_string()),
AttributeValue::Integer(100),
]);
assert_eq!(typed_int.as_float(), Some(100.0));
let regular_list =
AttributeValue::List(vec![AttributeValue::Float(1.0), AttributeValue::Float(2.0)]);
assert_eq!(regular_list.as_float(), None);
let empty_list = AttributeValue::List(vec![]);
assert_eq!(empty_list.as_float(), None);
}