diff --git a/src/host_providers/mir_builder.rs b/src/host_providers/mir_builder.rs index 06825bb4..b59638a6 100644 --- a/src/host_providers/mir_builder.rs +++ b/src/host_providers/mir_builder.rs @@ -71,3 +71,64 @@ pub fn program_json_to_mir_json_with_imports(program_json: &str, imports: HashMa } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_imports_resolution() { + // Program JSON with MatI64.new(4, 4) + let program_json = r#"{ + "version": 0, + "kind": "Program", + "body": [ + { + "type": "Local", + "name": "n", + "expr": {"type": "Int", "value": 4} + }, + { + "type": "Local", + "name": "A", + "expr": { + "type": "Method", + "recv": {"type": "Var", "name": "MatI64"}, + "method": "new", + "args": [ + {"type": "Var", "name": "n"}, + {"type": "Var", "name": "n"} + ] + } + }, + { + "type": "Return", + "expr": { + "type": "Method", + "recv": {"type": "Var", "name": "A"}, + "method": "at", + "args": [ + {"type": "Int", "value": 0}, + {"type": "Int", "value": 0} + ] + } + } + ] + }"#; + + // Create imports map + let mut imports = HashMap::new(); + imports.insert("MatI64".to_string(), "MatI64".to_string()); + + // Call with imports + let result = program_json_to_mir_json_with_imports(program_json, imports); + + // Should succeed + assert!(result.is_ok(), "Failed with error: {:?}", result.err()); + + let mir_json = result.unwrap(); + // MIR JSON should contain functions + assert!(mir_json.contains("functions"), "MIR JSON should contain functions"); + eprintln!("[test] MIR JSON generated successfully with MatI64 imports"); + } +}