#![cfg(test)] use super::*; use crate::{symbol_table::SymbolTable, type_inference::TypeContext}; fn build_ir(input: &str) -> ReducedIR { let ast = crate::util::quick_ast(input); let mut symbol_table = SymbolTable::new(); let mut type_context = TypeContext::new(); symbol_table.process_ast(&ast, &mut type_context).unwrap(); let reduced = reduce(&ast, &symbol_table, &type_context); reduced.debug(&symbol_table); reduced } #[test] fn test_ir() { let src = r#" let global_one = 10 + 20 let global_two = "the string hello" fn a_function(i, j, k) { fn nested(x) { x + 10 } i + j * nested(k) } fn another_function(e) { let local_var = 420 e * local_var } another_function() "#; let reduced = build_ir(src); assert_eq!(reduced.functions.len(), 3); } #[test] fn test_methods() { let src = r#" type Thing = Thing impl Thing { fn a_method() { 20 } } let a = Thing 4 + a.a_method() "#; let reduced = build_ir(src); assert_eq!(reduced.functions.len(), 1); }