ifc_lite_testkit/
step.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! In-memory STEP file builder for tests.
6
7/// A complete STEP physical file with a real `FILE_DESCRIPTION`/`FILE_NAME`
8/// header (real files always carry both) declaring `schema` (e.g. `"IFC4"`),
9/// whose `DATA` section is `lines` joined by newlines. Each element of
10/// `lines` (`&[&str]` or `&[String]`) is one entity line, e.g. `"#1=IFCPROJECT(...);"`.
11pub fn step_file<S: AsRef<str>>(schema: &str, lines: &[S]) -> String {
12    let mut out = format!(
13        "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION((''),'2;1');\n\
14         FILE_NAME('','',(''),(''),'','','');\nFILE_SCHEMA(('{schema}'));\nENDSEC;\nDATA;\n"
15    );
16    for line in lines {
17        out.push_str(line.as_ref());
18        out.push('\n');
19    }
20    out.push_str("ENDSEC;\nEND-ISO-10303-21;\n");
21    out
22}
23
24#[cfg(test)]
25mod tests {
26    use super::step_file;
27
28    #[test]
29    fn wraps_lines_in_a_full_header_and_trailer() {
30        let s = step_file("IFC4X3", &["#1=IFCPROJECT($);", "#2=IFCSITE($);"]);
31        assert!(s.starts_with("ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION("));
32        assert!(s.contains("FILE_SCHEMA(('IFC4X3'));"));
33        assert!(s.contains("DATA;\n#1=IFCPROJECT($);\n#2=IFCSITE($);\nENDSEC;\nEND-ISO-10303-21;\n"));
34    }
35}