From 4c2f18b7c9222a30e24b47daeb8e6aed48aef2cb Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 5 May 2020 16:52:46 -0400 Subject: [PATCH] Update parser bin_expr testing to be more consistent with the rest of the tests Signed-off-by: Alek Ratzloff --- src/syn/parser.rs | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/syn/parser.rs b/src/syn/parser.rs index 59d1041..f642c4b 100644 --- a/src/syn/parser.rs +++ b/src/syn/parser.rs @@ -62,7 +62,7 @@ impl<'t> Parser<'t> { } //////////////////////////////////////////////////////////////////////////////// -// Parsing functions +// Expression parsing //////////////////////////////////////////////////////////////////////////////// macro_rules! bin_expr { @@ -500,29 +500,17 @@ mod test { #[test] fn test_bin_expr() { test_parser!( - { - let mut parser = Parser::try_from( - r#"x + 2 - 1 + 2 * 3 - 4 / 5 - 1+2*3-4/5 - 1 - -1 * 8 - 1--1*8 - 1 + 1 == 2 - 3 >= 1 + 2 - "#, - ) - .unwrap(); - parser.set_skip_newlines(true).unwrap(); - parser - }, - // x + 2 + Parser::try_from("x + 2").unwrap(), next_expr, bin_expr( base_expr(BaseExprKind::Ident), BinOp::Plus, base_expr(BaseExprKind::Num) - ), - // 1 + 2 * 3 - 4 / 5 + ) + ); + + test_parser!( + Parser::try_from("1 + 2 * 3 - 4 / 5").unwrap(), next_expr, bin_expr( base_expr(BaseExprKind::Num), @@ -540,9 +528,11 @@ mod test { base_expr(BaseExprKind::Num) ) ) - ), - // - // 1+2*3-4/5 + ) + ); + + test_parser!( + Parser::try_from("1+2*3-4/5").unwrap(), next_expr, bin_expr( base_expr(BaseExprKind::Num), @@ -560,8 +550,11 @@ mod test { base_expr(BaseExprKind::Num) ) ) - ), - // 1 - -1 * 8 + ) + ); + + test_parser!( + Parser::try_from("1 - -1 * 8").unwrap(), next_expr, bin_expr( base_expr(BaseExprKind::Num), @@ -571,8 +564,11 @@ mod test { BinOp::Times, base_expr(BaseExprKind::Num) ) - ), - // 1--1*8 + ) + ); + + test_parser!( + Parser::try_from("1--1*8").unwrap(), next_expr, bin_expr( base_expr(BaseExprKind::Num), @@ -582,8 +578,11 @@ mod test { BinOp::Times, base_expr(BaseExprKind::Num) ) - ), - // 1 + 1 == 2 + ) + ); + + test_parser!( + Parser::try_from("1 + 1 == 2").unwrap(), next_expr, bin_expr( bin_expr( @@ -593,8 +592,11 @@ mod test { ), BinOp::EqEq, base_expr(BaseExprKind::Num) - ), - // 3 >= 1 + 2 + ) + ); + + test_parser!( + Parser::try_from("3 >= 1 + 2").unwrap(), next_expr, bin_expr( base_expr(BaseExprKind::Num), @@ -634,8 +636,8 @@ mod test { 1, x, [ + :key, 'value', - :value, ], :sym )").unwrap(), @@ -644,8 +646,8 @@ mod test { base_expr(BaseExprKind::Num), base_expr(BaseExprKind::Ident), base_expr(BaseExprKind::List(vec![ - base_expr(BaseExprKind::Str), base_expr(BaseExprKind::Sym), + base_expr(BaseExprKind::Str), ])), base_expr(BaseExprKind::Sym), ]))