From 1f0db6255b8931d8f7774b5f0a945695318313eb Mon Sep 17 00:00:00 2001 From: progrm_jarvis Date: Sat, 16 May 2020 12:02:51 +0000 Subject: [PATCH] test(parser): add `basic_math_parened` test --- --- a/crates/jsonnet-parser/src/lib.rs +++ b/crates/jsonnet-parser/src/lib.rs @@ -188,6 +188,18 @@ pub mod tests { use super::{expr::*, parse}; + fn basic_math_expression() -> Expr { + Expr::BinaryOp( + Box::new(Expr::Num(2.0)), + BinaryOp::Add, + Box::new(Expr::BinaryOp( + Box::new(Expr::Num(2.0)), + BinaryOp::Mul, + Box::new(Expr::Num(2.0)), + )), + ) + } + #[test] fn empty_object() { assert_eq!(parse("{}").unwrap(), Expr::Obj(ObjBody::MemberList(vec![]))); @@ -211,16 +223,17 @@ #[test] fn basic_math_with_indents() { + assert_eq!(parse("2 + 2 * 2 ").unwrap(), basic_math_expression()); + } + + #[test] + fn basic_math_parened() { assert_eq!( - parse("2 + 2 * 2 ").unwrap(), + parse("2+(2+2*2)").unwrap(), Expr::BinaryOp( Box::new(Expr::Num(2.0)), BinaryOp::Add, - Box::new(Expr::BinaryOp( - Box::new(Expr::Num(2.0)), - BinaryOp::Mul, - Box::new(Expr::Num(2.0)), - )), + Box::new(Expr::Parened(Box::new(basic_math_expression()))), ) ); } -- gitstuff