Nilton Constantino 9dc5290f78
pr 02
2026-01-27 13:18:50 +00:00

63 lines
1.5 KiB
Rust

use prometeu_compiler::ir_core::*;
use serde_json;
#[test]
fn test_ir_core_manual_construction() {
let program = Program {
modules: vec![Module {
name: "main".to_string(),
functions: vec![Function {
id: FunctionId(10),
name: "entry".to_string(),
blocks: vec![Block {
id: 0,
instrs: vec![
Instr::PushConst(ConstId(0)),
Instr::Call(FunctionId(11)),
],
terminator: Terminator::Return,
}],
}],
}],
};
let json = serde_json::to_string_pretty(&program).unwrap();
// Snapshot check for deterministic shape
let expected = r#"{
"modules": [
{
"name": "main",
"functions": [
{
"id": 10,
"name": "entry",
"blocks": [
{
"id": 0,
"instrs": [
{
"PushConst": 0
},
{
"Call": 11
}
],
"terminator": "Return"
}
]
}
]
}
]
}"#;
assert_eq!(json, expected);
}
#[test]
fn test_ir_core_ids() {
assert_eq!(serde_json::to_string(&FunctionId(1)).unwrap(), "1");
assert_eq!(serde_json::to_string(&ConstId(2)).unwrap(), "2");
assert_eq!(serde_json::to_string(&TypeId(3)).unwrap(), "3");
}