ifc_lite_export/merged/
entry_points.rs

1// SPDX-License-Identifier: MPL-2.0
2use super::{export_merged_with_stats, MergedOptions};
3
4/// Merge whole models into a STEP file, returning `InvalidData` with the
5/// record diagnostic if conversion is refused.
6pub fn try_export_merged(models: &[&[u8]], opts: &MergedOptions) -> std::io::Result<String> {
7    let (out, stats) = export_merged_with_stats(models, opts);
8    if out.is_empty() {
9        return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, stats.warnings.join("\n")));
10    }
11    Ok(out)
12}
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17
18    #[test]
19    fn fallible_merge_returns_wr22_with_the_record_id_11117() {
20        let source = b"ISO-10303-21;
21HEADER;
22FILE_SCHEMA(('IFC4'));
23ENDSEC;
24DATA;
25#5=IFCPROPERTYBOUNDEDVALUE('Dates',$,IFCDATE('2026-12-01'),$,$,$);
26ENDSEC;
27END-ISO-10303-21;
28";
29        let opts = MergedOptions { schema: Some("IFC2X3".into()), ..Default::default() };
30        let error = try_export_merged(&[source], &opts).unwrap_err();
31        assert_eq!(error.kind(), std::io::ErrorKind::InvalidData);
32        let diagnostic = error.to_string();
33        assert!(diagnostic.contains("#5") && diagnostic.contains("IfcPropertyBoundedValue") && diagnostic.contains("WR22"), "{diagnostic}");
34    }
35}