use prometeu_compiler::ir_core::*; use serde_json; #[test] fn test_ir_core_manual_construction() { let mut const_pool = ConstPool::new(); const_pool.insert(ConstantValue::String("hello".to_string())); let program = Program { const_pool, 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), 0), ], terminator: Terminator::Return, }], }], }], }; let json = serde_json::to_string_pretty(&program).unwrap(); // Snapshot check for deterministic shape let expected = r#"{ "const_pool": { "constants": [ { "String": "hello" } ] }, "modules": [ { "name": "main", "functions": [ { "id": 10, "name": "entry", "blocks": [ { "id": 0, "instrs": [ { "PushConst": 0 }, { "Call": [ 11, 0 ] } ], "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"); }