#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "codegen_tests",
))]
use std::process::Command;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_struct_init_with_array_fields() {
let code = r#"
struct GpuVertex {
position: [f32; 3],
color: [f32; 4],
}
fn main() {
let x = 1.0;
let y = 2.0;
let z = 3.0;
let vertex = GpuVertex {
position: [x, y, z],
color: [1.0, 0.0, 0.0, 1.0],
};
}
"#;
let _tmp = tempfile::tempdir().unwrap();
let test_dir = _tmp.path().join(format!(
"wj_test_struct_init_{}_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos(),
std::process::id()
));
std::fs::create_dir_all(&test_dir).unwrap();
std::fs::write(test_dir.join("main.wj"), code).unwrap();
let wj_binary = env!("CARGO_BIN_EXE_wj");
let output = Command::new(wj_binary)
.arg("build")
.arg("--no-cargo")
.arg("main.wj")
.current_dir(&test_dir)
.output()
.expect("Failed to run wj");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let generated_code = std::fs::read_to_string(test_dir.join("build/main.rs"))
.expect("Failed to read generated code");
if !output.status.success() {
panic!(
"Compilation failed!\nstdout: {}\nstderr: {}\ngenerated:\n{}",
stdout, stderr, generated_code
);
}
assert!(
generated_code.contains("position: ["),
"Generated code should contain 'position: [' for struct field initialization"
);
assert!(
generated_code.contains("color: ["),
"Generated code should contain 'color: [' for struct field initialization"
);
assert!(
!generated_code.contains("GpuVertex;"),
"Generated code should not have incomplete struct initialization (GpuVertex;)"
);
}