test(mir-builder): add test for imports resolution

Add test_imports_resolution to verify MatI64 imports work correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-14 15:54:57 +09:00
parent 938c92160a
commit 034a7b0a4a

View File

@ -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");
}
}