Tests(MIR): add extern_call console.log lowering test and verbose MIR dump assertion.

This commit is contained in:
Moe Charm
2025-08-25 20:19:04 +09:00
parent 317e6af0bf
commit f665787511

View File

@ -187,6 +187,26 @@ mod tests {
assert!(has_typeop, "Expected TypeOp lowering for print(obj.is(...))"); assert!(has_typeop, "Expected TypeOp lowering for print(obj.is(...))");
} }
#[test]
fn test_lowering_extern_console_log() {
// Build AST: console.log("hi") → ExternCall env.console.log
let ast = ASTNode::Expression {
expr: Box::new(ASTNode::MethodCall {
object: Box::new(ASTNode::Variable { name: "console".to_string(), span: crate::ast::Span::unknown() }),
method: "log".to_string(),
arguments: vec![ ASTNode::Literal { value: LiteralValue::String("hi".to_string()), span: crate::ast::Span::unknown() } ],
span: crate::ast::Span::unknown(),
}),
span: crate::ast::Span::unknown(),
};
let mut compiler = MirCompiler::new();
let result = compiler.compile(ast).expect("compile should succeed");
let dump = MirPrinter::verbose().print_module(&result.module);
assert!(dump.contains("extern_call env.console.log"), "Expected extern_call env.console.log in MIR dump. Got:\n{}", dump);
}
#[test] #[test]
fn test_throw_compilation() { fn test_throw_compilation() {
let mut compiler = MirCompiler::new(); let mut compiler = MirCompiler::new();