From 428d560e2a05a2a20140b9b22bae118cc6e2803e Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 17 Jan 2016 00:08:46 -0800 Subject: [PATCH] Add tests for call expr parsing --- src/parser.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 381bce1..fe5e177 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -29,7 +29,7 @@ pub struct Function { pub body: Vec, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Prototype { pub name: String, pub args: Vec @@ -327,11 +327,32 @@ mod tests { } } + #[test] + fn call_parse_test() { + use super::ASTNode::*; + use super::Expression::*; + use super::Function; + + parsetest!( + "fn a() 1 + 2 end", + [FuncNode(Function {prototype: Prototype { name: ref name, args: ref args }, body: ref body})], + match &body[..] { [BinExp(_, box Number(1.0), box Number(2.0))] => true, _ => false } + && name == "a" && match &args[..] { [] => true, _ => false } + ); + + parsetest!( + "fn a(x,y) 1 + 2 end", + [FuncNode(Function {prototype: Prototype { name: ref name, args: ref args }, body: ref body})], + match &body[..] { [BinExp(_, box Number(1.0), box Number(2.0))] => true, _ => false } + && name == "a" && *args == ["x","y"] + ); + } + #[test] fn expression_parse_test() { use super::ASTNode::*; use super::Expression::*; - parsetest!("a", [ASTNode::ExprNode(Expression::Variable(ref s))], s == "a"); + parsetest!("a", [ExprNode(Variable(ref s))], s == "a"); parsetest!("a + b", [ExprNode(BinExp(ref plus, box Variable(ref a), box Variable(ref b)))], plus == "+" && a == "a" && b == "b");