From 4137a1a693cca62bd68a35a9a26446d304c7375f Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 28 Feb 2024 17:02:30 -0500 Subject: [PATCH] Improve logic parsing test --- src/parser.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 2f2ae51..57db169 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -158,6 +158,37 @@ mod tests { Expression::Value(ValueNode::Integer(1)) )))) ); + + assert_eq!( + parse(&lex("(x == 1) && (y == 2)").unwrap()).unwrap()[0].0, + Statement::Expression(Expression::Logic(Box::new(Logic::And( + Expression::Logic(Box::new(Logic::Equal( + Expression::Identifier(Identifier::new("x")), + Expression::Value(ValueNode::Integer(1)) + ))), + Expression::Logic(Box::new(Logic::Equal( + Expression::Identifier(Identifier::new("y")), + Expression::Value(ValueNode::Integer(2)) + ))), + )))) + ); + + assert_eq!( + parse(&lex("(x == 1) && (y == 2) && true").unwrap()).unwrap()[0].0, + Statement::Expression(Expression::Logic(Box::new(Logic::And( + Expression::Logic(Box::new(Logic::And( + Expression::Logic(Box::new(Logic::Equal( + Expression::Identifier(Identifier::new("x")), + Expression::Value(ValueNode::Integer(1)) + ))), + Expression::Logic(Box::new(Logic::Equal( + Expression::Identifier(Identifier::new("y")), + Expression::Value(ValueNode::Integer(2)) + ))), + ))), + Expression::Value(ValueNode::Boolean(true)) + )))) + ); } #[test]