44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use prometeu_compiler::ir_core::const_pool::{ConstPool, ConstantValue};
|
|
use prometeu_compiler::ir_core::ids::ConstId;
|
|
|
|
#[test]
|
|
fn test_const_pool_deduplication() {
|
|
let mut pool = ConstPool::new();
|
|
|
|
let id1 = pool.insert(ConstantValue::Int(42));
|
|
let id2 = pool.insert(ConstantValue::String("hello".to_string()));
|
|
let id3 = pool.insert(ConstantValue::Int(42));
|
|
|
|
assert_eq!(id1, id3);
|
|
assert_ne!(id1, id2);
|
|
assert_eq!(pool.constants.len(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn test_const_pool_deterministic_assignment() {
|
|
let mut pool = ConstPool::new();
|
|
|
|
let id0 = pool.insert(ConstantValue::Int(10));
|
|
let id1 = pool.insert(ConstantValue::Int(20));
|
|
let id2 = pool.insert(ConstantValue::Int(30));
|
|
|
|
assert_eq!(id0, ConstId(0));
|
|
assert_eq!(id1, ConstId(1));
|
|
assert_eq!(id2, ConstId(2));
|
|
}
|
|
|
|
#[test]
|
|
fn test_const_pool_serialization() {
|
|
let mut pool = ConstPool::new();
|
|
pool.insert(ConstantValue::Int(42));
|
|
pool.insert(ConstantValue::String("test".to_string()));
|
|
pool.insert(ConstantValue::Float(3.14));
|
|
|
|
let json = serde_json::to_string_pretty(&pool).unwrap();
|
|
|
|
// Check for deterministic shape in JSON
|
|
assert!(json.contains("\"Int\": 42"));
|
|
assert!(json.contains("\"String\": \"test\""));
|
|
assert!(json.contains("\"Float\": 3.14"));
|
|
}
|