#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "analyzer_tests",
))]
use std::fs;
use tempfile::TempDir;
use windjammer::{build_project, build_project_ext, CompilationTarget};
#[test]
fn test_two_files_with_f32_params_no_conflict_compiler() {
let temp_dir = TempDir::new().unwrap();
let pkg_dir = temp_dir.path().join("pkg");
fs::create_dir_all(&pkg_dir).unwrap();
fs::write(
pkg_dir.join("base.wj"),
r#"
pub struct Base {
pub value: f32,
}
impl Base {
pub fn update(self, dt: f32) {
if self.value > 0.0 {
self.value = self.value - dt
}
}
}
"#,
)
.unwrap();
fs::write(
pkg_dir.join("wrapper.wj"),
r#"
use crate::base::Base
pub struct Wrapper {
pub base: Base,
}
impl Wrapper {
pub fn update(self, dt: f32) {
self.base.update(dt)
}
}
"#,
)
.unwrap();
fs::write(
pkg_dir.join("mod.wj"),
r#"
pub mod base
pub mod wrapper
"#,
)
.unwrap();
let output_dir = temp_dir.path().join("build");
fs::create_dir_all(&output_dir).unwrap();
let result = build_project(&pkg_dir, &output_dir, CompilationTarget::Rust, true);
assert!(
result.is_ok(),
"Module build should succeed. Error: {}",
result.err().unwrap()
);
let base_rs = fs::read_to_string(output_dir.join("base.rs")).unwrap();
assert!(
base_rs.contains("0.0_f32") || base_rs.contains("0.0f32"),
"Literal should be f32 in base.rs. Got:\n{}",
base_rs
);
assert!(
!base_rs.contains("0.0_f64") && !base_rs.contains("0.0f64"),
"Should not have f64 literals in base.rs"
);
let wrapper_rs = fs::read_to_string(output_dir.join("wrapper.rs")).unwrap();
assert!(
wrapper_rs.contains("f32") || wrapper_rs.contains("update"),
"Wrapper should have f32 types or update method"
);
}
#[test]
fn test_mod_wj_entry_point_no_conflict() {
let temp_dir = TempDir::new().unwrap();
let pkg_dir = temp_dir.path().join("pkg");
fs::create_dir_all(&pkg_dir).unwrap();
fs::write(
pkg_dir.join("base.wj"),
r#"
pub struct Base {
pub value: f32,
}
impl Base {
pub fn update(self, dt: f32) {
if self.value > 0.0 {
self.value = self.value - dt
}
}
}
"#,
)
.unwrap();
fs::write(
pkg_dir.join("wrapper.wj"),
r#"
use crate::base::Base
pub struct Wrapper {
pub base: Base,
}
impl Wrapper {
pub fn update(self, dt: f32) {
self.base.update(dt)
}
}
"#,
)
.unwrap();
fs::write(
pkg_dir.join("mod.wj"),
r#"
pub mod base
pub mod wrapper
"#,
)
.unwrap();
let output_dir = temp_dir.path().join("build");
fs::create_dir_all(&output_dir).unwrap();
let mod_wj_path = pkg_dir.join("mod.wj");
let result = build_project_ext(
&mod_wj_path,
&output_dir,
CompilationTarget::Rust,
true,
true, &[],
);
assert!(
result.is_ok(),
"Module build from mod.wj entry should succeed. Error: {}",
result.err().unwrap()
);
let base_rs = fs::read_to_string(output_dir.join("base.rs")).unwrap();
assert!(
base_rs.contains("0.0_f32") || base_rs.contains("0.0f32"),
"Literal should be f32 when built from mod.wj. Got:\n{}",
base_rs
);
}