From 078724755e3cb7ab8670bc4408a31f6faa0cb29b Mon Sep 17 00:00:00 2001 From: Лач Date: Fri, 29 May 2020 07:54:34 +0000 Subject: [PATCH] test(parser): merge new tests --- --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /target + +.idea +.vscode --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true --- a/crates/jsonnet-parser/src/lib.rs +++ b/crates/jsonnet-parser/src/lib.rs @@ -240,10 +240,28 @@ #[cfg(test)] pub mod tests { use super::{expr::*, parse}; + + mod expressions { + use super::*; + + pub fn basic_math() -> Expr { + Expr::BinaryOp( + Box::new(Expr::Num(2.0)), + BinaryOpType::Add, + Box::new(Expr::BinaryOp( + Box::new(Expr::Num(2.0)), + BinaryOpType::Mul, + Box::new(Expr::Num(2.0)), + )), + ) + } + } + #[test] fn empty_object() { - assert_eq!(parse("{}").unwrap(), Expr::Obj(ObjBody::MemberList(vec![])),); + assert_eq!(parse("{}").unwrap(), Expr::Obj(ObjBody::MemberList(vec![]))); } + #[test] fn basic_math() { assert_eq!( @@ -260,6 +278,23 @@ ); } + #[test] + fn basic_math_with_indents() { + assert_eq!(parse("2 + 2 * 2 ").unwrap(), expressions::basic_math()); + } + + #[test] + fn basic_math_parened() { + assert_eq!( + parse("2+(2+2*2)").unwrap(), + Expr::BinaryOp( + Box::new(Expr::Num(2.0)), + BinaryOpType::Add, + Box::new(Expr::Parened(Box::new(expressions::basic_math()))), + ) + ); + } + /// Comments should not affect parsing #[test] fn comments() { -- gitstuff