From 2681dbc4f24b47e878309c6ba70c657b454d56bb Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 16 Jan 2017 01:10:06 -0800 Subject: [PATCH] Add test for "a+4" being conterintuitive Also fix Op -> BinOp in tests --- src/parser.rs | 8 ++++---- src/tokenizer.rs | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 443ee52..5264cdf 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -569,16 +569,16 @@ mod tests { fn expression_parse_test() { parsetest!("a", &[ExprNode(Variable(ref s))], **s == "a"); parsetest!("a + b", - &[ExprNode(BinExp(Op::Plus, box Variable(ref a), box Variable(ref b)))], + &[ExprNode(BinExp(BinOp::Add, box Variable(ref a), box Variable(ref b)))], **a == "a" && **b == "b"); parsetest!("a + b * c", - &[ExprNode(BinExp(Op::Plus, box Variable(ref a), box BinExp(Op::Mul, box Variable(ref b), box Variable(ref c))))], + &[ExprNode(BinExp(BinOp::Add, box Variable(ref a), box BinExp(BinOp::Mul, box Variable(ref b), box Variable(ref c))))], **a == "a" && **b == "b" && **c == "c"); parsetest!("a * b + c", - &[ExprNode(BinExp(Op::Plus, box BinExp(Op::Mul, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], + &[ExprNode(BinExp(BinOp::Add, box BinExp(BinOp::Mul, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], **a == "a" && **b == "b" && **c == "c"); parsetest!("(a + b) * c", - &[ExprNode(BinExp(Op::Mul, box BinExp(Op::Plus, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], + &[ExprNode(BinExp(BinOp::Mul, box BinExp(BinOp::Add, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], **a == "a" && **b == "b" && **c == "c"); } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 82e3d8e..e708959 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -180,6 +180,10 @@ mod tests { [NumLiteral(2.3), Operator(OpTok(ref a)), NumLiteral(49.2)], **a == "*"); + token_test!("a+3", + [Identifier(ref a), NumLiteral(3.0)], + **a == "a+"); + assert!(tokenize("2.4.5").is_err()); token_test!("fn my_func(a) { a ? 3[1] }",