#![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",
))]
#[path = "common/test_utils.rs"]
mod test_utils;
#[test]
fn test_field_assignment_literal() {
let source = r#"
pub struct Vec3 { pub x: f32, pub y: f32, pub z: f32 }
impl Vec3 {
pub fn new(x: f32, y: f32, z: f32) -> Vec3 { Vec3 { x, y, z } }
}
pub struct PhysicsBody { pub velocity: Vec3 }
impl PhysicsBody {
pub fn stop_x(self) {
self.velocity.x = 0.0
}
pub fn stop_z(self) {
self.velocity.z = 0.0
}
}
"#;
let output = test_utils::compile_single(source);
assert!(
output.contains("0.0_f32"),
"self.velocity.x = 0.0 should generate 0.0_f32 (assignment LHS→RHS), got:\n{}",
output
);
assert!(
!output.contains("0.0_f64"),
"Assignment to f32 field should NOT use f64, got:\n{}",
output
);
}
#[test]
fn test_two_level_nested_comparison() {
let source = r#"
pub struct ColorGradingSettings { pub gamma: f32 }
impl ColorGradingSettings {
pub fn new() -> ColorGradingSettings {
ColorGradingSettings { gamma: 1.0 }
}
}
pub struct ColorGrading { pub settings: ColorGradingSettings }
impl ColorGrading {
pub fn needs_gamma_correction(self) -> bool {
self.settings.gamma != 1.0
}
}
"#;
let output = test_utils::compile_single(source);
assert!(
output.contains("1.0_f32"),
"self.settings.gamma != 1.0 should generate 1.0_f32, got:\n{}",
output
);
assert!(
!output.contains("1.0_f64"),
"Two-level nested comparison should NOT use f64, got:\n{}",
output
);
}
#[test]
fn test_three_level_nested_comparison() {
let source = r#"
pub struct Vec3 { pub x: f32, pub y: f32, pub z: f32 }
impl Vec3 {
pub fn new(x: f32, y: f32, z: f32) -> Vec3 { Vec3 { x, y, z } }
}
pub struct Camera { pub position: Vec3 }
impl Camera {
pub fn default() -> Camera {
Camera { position: Vec3::new(0.0, 0.0, 0.0) }
}
}
pub struct QuickStartGame { pub camera: Camera }
impl QuickStartGame {
pub fn is_ready(self) -> bool {
self.camera.position.x != 0.0 || self.camera.position.y != 0.0 || self.camera.position.z != 0.0
}
}
"#;
let output = test_utils::compile_single(source);
assert!(
output.contains("0.0_f32"),
"self.camera.position.x != 0.0 should generate 0.0_f32 (3-level nested), got:\n{}",
output
);
assert!(
!output.contains("0.0_f64"),
"Three-level nested comparison should NOT use f64, got:\n{}",
output
);
}
#[test]
fn test_binary_rhs_field_propagation() {
let source = r#"
pub struct ColorGradingSettings { pub gamma: f32 }
impl ColorGradingSettings {
pub fn new() -> ColorGradingSettings {
ColorGradingSettings { gamma: 1.0 }
}
}
pub struct ColorGrading { pub settings: ColorGradingSettings }
impl ColorGrading {
pub fn compute_inv_gamma(self) -> f32 {
1.0 / self.settings.gamma
}
}
"#;
let output = test_utils::compile_single(source);
assert!(
output.contains("1.0_f32"),
"1.0 / self.settings.gamma should infer 1.0 as f32 (RHS→LHS), got:\n{}",
output
);
}