Tests for type annotations

This commit is contained in:
greg 2017-09-29 19:10:37 -07:00
parent 98169bd352
commit 9214f36c04

View File

@ -960,11 +960,15 @@ mod parse_tests {
($var:expr) => { Variable(Rc::new($var.to_string())) } ($var:expr) => { Variable(Rc::new($var.to_string())) }
} }
macro_rules! exprstatement { 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 { macro_rules! ex {
($expr_type:expr) => { Expression($expr_type, None) } ($expr_type:expr) => { Expression($expr_type, None) }
} }
macro_rules! ty {
($name:expr) => { TypeAnno::Singleton { name: Rc::new($name.to_string()), params: vec![] } };
}
#[test] #[test]
fn parsing_number_literals_and_binexps() { fn parsing_number_literals_and_binexps() {
@ -1088,6 +1092,18 @@ mod parse_tests {
params: vec![], params: vec![],
})) })])); })) })]));
parse_test!("a : Int", AST(vec![
exprstatement!(var!("a"), ty!("Int"))
]));
parse_test!("a : Option<Int>", AST(vec![
exprstatement!(var!("a"), TypeAnno::Singleton { name: rc!(Option), params: vec![ty!("Int")] })
]));
parse_test!("a : KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >", AST(vec![
exprstatement!(var!("a"), TypeAnno::Singleton { name: rc!(KoreanBBQSpecifier), params: vec![
ty!("Kimchi"), TypeAnno::Singleton { name: rc!(Option), params: vec![ty!("Bulgogi")] }
] })
]));
} }
} }