From 9214f36c0416312639da90955e31377f94596fbf Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 29 Sep 2017 19:10:37 -0700 Subject: [PATCH] Tests for type annotations --- src/schala_lang/parsing.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 3a7c03a..7cd8c82 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -960,11 +960,15 @@ mod parse_tests { ($var:expr) => { Variable(Rc::new($var.to_string())) } } macro_rules! exprstatement { - ($expr_type:expr) => { Statement::ExpressionStatement(Expression($expr_type, None)) } + ($expr_type:expr) => { Statement::ExpressionStatement(Expression($expr_type, None)) }; + ($expr_type:expr, $type_anno:expr) => { Statement::ExpressionStatement(Expression($expr_type, Some($type_anno))) }; } macro_rules! ex { ($expr_type:expr) => { Expression($expr_type, None) } } + macro_rules! ty { + ($name:expr) => { TypeAnno::Singleton { name: Rc::new($name.to_string()), params: vec![] } }; + } #[test] fn parsing_number_literals_and_binexps() { @@ -1088,6 +1092,18 @@ mod parse_tests { params: vec![], })) })])); + parse_test!("a : Int", AST(vec![ + exprstatement!(var!("a"), ty!("Int")) + ])); + parse_test!("a : Option", AST(vec![ + exprstatement!(var!("a"), TypeAnno::Singleton { name: rc!(Option), params: vec![ty!("Int")] }) + ])); + + parse_test!("a : KoreanBBQSpecifier >", AST(vec![ + exprstatement!(var!("a"), TypeAnno::Singleton { name: rc!(KoreanBBQSpecifier), params: vec![ + ty!("Kimchi"), TypeAnno::Singleton { name: rc!(Option), params: vec![ty!("Bulgogi")] } + ] }) + ])); } }