git.delta.rocks / jrsonnet / refs/commits / 1f0db6255b89

difftreelog

test(parser) add `basic_math_parened` test

progrm_jarvis2020-05-16parent: #67ebf55.patch.diff
in: master

1 file changed

modifiedcrates/jsonnet-parser/src/lib.rsdiffbeforeafterboth
188pub mod tests {188pub mod tests {
189 use super::{expr::*, parse};189 use super::{expr::*, parse};
190
191 fn basic_math_expression() -> Expr {
192 Expr::BinaryOp(
193 Box::new(Expr::Num(2.0)),
194 BinaryOp::Add,
195 Box::new(Expr::BinaryOp(
196 Box::new(Expr::Num(2.0)),
197 BinaryOp::Mul,
198 Box::new(Expr::Num(2.0)),
199 )),
200 )
201 }
190202
191 #[test]203 #[test]
192 fn empty_object() {204 fn empty_object() {
210 }222 }
211223
212 #[test]224 #[test]
213 fn basic_math_with_indents() {225 fn basic_math_with_indents() {
226 assert_eq!(parse("2 + 2 * 2 ").unwrap(), basic_math_expression());
227 }
228
229 #[test]
230 fn basic_math_parened() {
214 assert_eq!(231 assert_eq!(
215 parse("2 + 2 * 2 ").unwrap(),232 parse("2+(2+2*2)").unwrap(),
216 Expr::BinaryOp(233 Expr::BinaryOp(
217 Box::new(Expr::Num(2.0)),234 Box::new(Expr::Num(2.0)),
218 BinaryOp::Add,235 BinaryOp::Add,
219 Box::new(Expr::BinaryOp(236 Box::new(Expr::Parened(Box::new(basic_math_expression()))),
220 Box::new(Expr::Num(2.0)),
221 BinaryOp::Mul,
222 Box::new(Expr::Num(2.0)),
223 )),
224 )237 )
225 );238 );