A test for type annotation

This commit is contained in:
greg 2017-09-28 00:45:36 -07:00
parent f48adbd9bf
commit c20f93e18c

View File

@ -900,6 +900,7 @@ mod parse_tests {
use super::{AST, Expression, Statement, Operation, TypeBody, Variant, parse, tokenize}; use super::{AST, Expression, Statement, Operation, TypeBody, Variant, parse, tokenize};
use super::Statement::*; use super::Statement::*;
use super::Declaration::*; use super::Declaration::*;
use super::TypeAnno;
use super::ExpressionType::*; use super::ExpressionType::*;
macro_rules! rc { macro_rules! rc {
@ -951,18 +952,12 @@ mod parse_tests {
parse_test!("1 && 2", AST(vec![exprstatement!(binexp!("&&", IntLiteral(1), IntLiteral(2)))])); parse_test!("1 && 2", AST(vec![exprstatement!(binexp!("&&", IntLiteral(1), IntLiteral(2)))]));
parse_test!("1 + 2 * 3 + 4", AST(vec![exprstatement!( parse_test!("1 + 2 * 3 + 4", AST(vec![exprstatement!(
binexp!("+", binexp!("+",
binexp!("+", IntLiteral(1), binexp!("+", IntLiteral(1), binexp!("*", IntLiteral(2), IntLiteral(3))),
binexp!("*", IntLiteral(2), IntLiteral(3)) IntLiteral(4)))]));
),
IntLiteral(4)
)
)]));
parse_test!("(1 + 2) * 3", AST(vec! parse_test!("(1 + 2) * 3", AST(vec!
[ [exprstatement!(binexp!("*", binexp!("+", IntLiteral(1), IntLiteral(2)), IntLiteral(3)))]));
exprstatement!(binexp!("*", binexp!("+", IntLiteral(1), IntLiteral(2)), IntLiteral(3)))
]));
parse_test!(".1 + .2", AST(vec![exprstatement!(binexp!("+", FloatLiteral(0.1), FloatLiteral(0.2)))])); parse_test!(".1 + .2", AST(vec![exprstatement!(binexp!("+", FloatLiteral(0.1), FloatLiteral(0.2)))]));
} }
@ -1047,4 +1042,13 @@ mod parse_tests {
Some(vec![exprstatement!(Variable(rc!(c)))])))]) Some(vec![exprstatement!(Variable(rc!(c)))])))])
); );
} }
#[test]
fn parsing_type_annotations() {
parse_test!("const a = b : Int", AST(vec![
Declaration(Binding { name: rc!(a), constant: true, expr:
Expression(var!("b"), Some(TypeAnno(rc!(Int)))) })]));
}
} }