From f33b3d34820c3534bf54626f4fefb6f0206cbe56 Mon Sep 17 00:00:00 2001 From: CrescentonC Date: Thu, 15 Jul 2021 11:49:23 +0800 Subject: [PATCH] add some test --- .../src/typecheck/expression_inference.rs | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/nac3core/src/typecheck/expression_inference.rs b/nac3core/src/typecheck/expression_inference.rs index 12332790..81f6befb 100644 --- a/nac3core/src/typecheck/expression_inference.rs +++ b/nac3core/src/typecheck/expression_inference.rs @@ -418,22 +418,41 @@ pub mod test { struct S; impl SymbolResolver for S { - fn get_symbol_location(&self, _str: &str) -> Option { - None - } + fn get_symbol_location(&self, _str: &str) -> Option { None } - fn get_symbol_type(&self, _str: &str) -> Option { - None - } + fn get_symbol_type(&self, _str: &str) -> Option { None } - fn get_symbol_value(&self, _str: &str) -> Option { - None - } + fn get_symbol_value(&self, _str: &str) -> Option { None } } InferenceContext::new(primitives::basic_ctx(), Box::new(S{}), FileID(3)) } + #[test] + fn test_i32() { + let mut inferencer = new_ctx(); + let ast: Expr> = Expr { + location: ast::Location::new(0, 0), + custom: None, + node: ast::ExprKind::Constant { + value: ast::Constant::Int(123.into()), + kind: None + } + }; + + let new_ast = inferencer.fold_expr(ast); + assert_eq!( + new_ast, + Ok(ast::Expr { + location: ast::Location::new(0, 0), + custom: Some(inferencer.get_primitive(primitives::INT32_TYPE)), + node: ast::ExprKind::Constant { + value: ast::Constant::Int(123.into()), + kind: None + } + }) + ); + } #[test] fn test_i64() { @@ -530,5 +549,4 @@ pub mod test { } ); } - } \ No newline at end of file