Skip to content

Commit 9b5df14

Browse files
committed
test(integration): cover constraints and DXF round-trip import
Adds three end-to-end tests: one for non-strict constraint warnings, one for the strict-mode failure path, and one that compiles the vivienda example, imports the resulting DXF back into a fresh cadforge project, and recompiles to prove the round-trip is lossless.
1 parent c15219c commit 9b5df14

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

tests/integration.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Integration tests — full pipeline from .cf files to DXF output.
22
33
use cadforge::compiler::compile_project;
4+
use cadforge::importer::import_dxf;
45
use std::fs;
56
use std::path::Path;
67

@@ -194,3 +195,111 @@ color = "#808080"
194195
let content = fs::read_to_string(&path).unwrap();
195196
assert!(content.contains("SOLID"));
196197
}
198+
199+
fn write_constraints_fixture(base: &Path, strict: bool) {
200+
fs::create_dir_all(base).unwrap();
201+
fs::write(
202+
base.join("project.toml"),
203+
format!(
204+
r#"[project]
205+
name = "constraints-fixture"
206+
scale = "1:100"
207+
units = "m"
208+
strict = {strict}
209+
210+
[layers]
211+
parent = {{ file = "parent.cf", locked = false }}
212+
child = {{ file = "child.cf", locked = false }}
213+
214+
[constraints]
215+
child.parent = "parent"
216+
child.belongs_to = "parent"
217+
"#
218+
),
219+
)
220+
.unwrap();
221+
222+
fs::write(
223+
base.join("parent.cf"),
224+
r#"[layer]
225+
name = "parent"
226+
227+
[[rect]]
228+
id = "room-1"
229+
origin = [0.0, 0.0]
230+
width = 2.0
231+
height = 2.0
232+
"#,
233+
)
234+
.unwrap();
235+
236+
fs::write(
237+
base.join("child.cf"),
238+
r#"[layer]
239+
name = "child"
240+
241+
[[rect]]
242+
id = "furn-1"
243+
origin = [3.0, 3.0]
244+
width = 1.0
245+
height = 1.0
246+
belongs_to = "room-1"
247+
"#,
248+
)
249+
.unwrap();
250+
}
251+
252+
#[test]
253+
fn compile_allows_constraint_warnings_when_not_strict() {
254+
let dir = Path::new("/tmp/cadforge_constraints_non_strict");
255+
let _ = fs::remove_dir_all(dir);
256+
write_constraints_fixture(dir, false);
257+
258+
let output = dir.join("output.dxf");
259+
let _ = fs::remove_file(&output);
260+
261+
compile_project(dir, None, None).unwrap();
262+
assert!(
263+
output.exists(),
264+
"output.dxf should be created in non-strict mode"
265+
);
266+
267+
let _ = fs::remove_dir_all(dir);
268+
}
269+
270+
#[test]
271+
fn compile_fails_on_constraint_violation_when_strict() {
272+
let dir = Path::new("/tmp/cadforge_constraints_strict");
273+
let _ = fs::remove_dir_all(dir);
274+
write_constraints_fixture(dir, true);
275+
276+
let result = compile_project(dir, None, None);
277+
assert!(
278+
result.is_err(),
279+
"strict mode should fail on constraint violation"
280+
);
281+
282+
let _ = fs::remove_dir_all(dir);
283+
}
284+
285+
#[test]
286+
fn import_generated_dxf_creates_cadforge_project() {
287+
let source = Path::new("examples/vivienda");
288+
let source_output = source.join("output.dxf");
289+
let _ = fs::remove_file(&source_output);
290+
compile_project(source, None, Some(&source_output)).unwrap();
291+
292+
let imported = Path::new("/tmp/cadforge_import_test");
293+
let _ = fs::remove_dir_all(imported);
294+
import_dxf(&source_output, imported, None).unwrap();
295+
296+
assert!(imported.join("project.toml").exists());
297+
let project_toml = fs::read_to_string(imported.join("project.toml")).unwrap();
298+
assert!(project_toml.contains("[layers]"));
299+
assert!(project_toml.contains("muros"));
300+
301+
compile_project(imported, None, None).unwrap();
302+
assert!(imported.join("output.dxf").exists());
303+
304+
let _ = fs::remove_dir_all(imported);
305+
}

0 commit comments

Comments
 (0)