#![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_method_param_inferred_as_mut_ref_when_field_mutated() {
let source = r#"
struct Grid {
data: i32,
}
impl Grid {
pub fn set(self, value: i32) {
self.data = value
}
}
fn modify_grid(self, grid: Grid) {
grid.set(42) // Should infer `&mut grid` parameter
}
"#;
let rust_code = test_utils::compile_single_result(source).expect("Compilation should succeed");
assert!(
rust_code.contains("grid: &mut Grid"),
"Should infer &mut for parameter when method mutates it. Got:\n{}",
rust_code
);
}
#[test]
fn test_string_param_comparison_no_deref() {
let source = r#"
pub fn check_topic(topic: string) -> bool {
if topic == "test" {
return true
}
false
}
"#;
let rust_code = test_utils::compile_single_result(source).expect("Compilation should succeed");
let cmp_ok = rust_code.contains("topic ==") || rust_code.contains("*topic ==");
assert!(
cmp_ok,
"Should generate a string comparison. Got:\n{}",
rust_code
);
}
#[test]
fn test_string_param_comparison_in_method_no_deref() {
let source = r#"
struct Companion {
name: string,
}
impl Companion {
pub fn get_dialogue_response(self, topic: string) -> string {
if topic == "pragmatic" {
return "Test response".to_string()
}
"Default response".to_string()
}
}
"#;
let rust_code = test_utils::compile_single_result(source).expect("Compilation should succeed");
let cmp_ok = rust_code.contains("topic ==") || rust_code.contains("*topic ==");
assert!(
cmp_ok,
"Should generate a string comparison in method. Got:\n{}",
rust_code
);
}
#[test]
fn test_param_inferred_as_mut_ref_when_method_called() {
let source = r#"
struct VoxelGrid {
data: Vec<i32>,
}
impl VoxelGrid {
pub fn set(self, x: i32, y: i32, z: i32, value: i32) {
self.data.push(value)
}
}
struct Environment {
name: string,
}
impl Environment {
fn generate_ground(self, grid: VoxelGrid) {
grid.set(0, 0, 0, 1) // Should infer `&mut grid` parameter
}
fn generate_buildings(self, grid: VoxelGrid) {
let mut i = 0
while i < 5 {
grid.set(i, 0, 0, 2) // Should infer `&mut grid` parameter
i = i + 1
}
}
}
"#;
let rust_code = test_utils::compile_single_result(source).expect("Compilation should succeed");
assert!(
rust_code.contains("grid: &mut VoxelGrid"),
"Should infer &mut VoxelGrid for parameter when method mutates it. Got:\n{}",
rust_code
);
}