Update parser bin_expr testing to be more consistent with the rest of the tests

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-05-05 16:52:46 -04:00
parent 5622eb96bc
commit 4c2f18b7c9

View File

@@ -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),
]))