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:
@@ -62,7 +62,7 @@ impl<'t> Parser<'t> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Parsing functions
|
// Expression parsing
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
macro_rules! bin_expr {
|
macro_rules! bin_expr {
|
||||||
@@ -500,29 +500,17 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_bin_expr() {
|
fn test_bin_expr() {
|
||||||
test_parser!(
|
test_parser!(
|
||||||
{
|
Parser::try_from("x + 2").unwrap(),
|
||||||
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
|
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
base_expr(BaseExprKind::Ident),
|
base_expr(BaseExprKind::Ident),
|
||||||
BinOp::Plus,
|
BinOp::Plus,
|
||||||
base_expr(BaseExprKind::Num)
|
base_expr(BaseExprKind::Num)
|
||||||
),
|
)
|
||||||
// 1 + 2 * 3 - 4 / 5
|
);
|
||||||
|
|
||||||
|
test_parser!(
|
||||||
|
Parser::try_from("1 + 2 * 3 - 4 / 5").unwrap(),
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
base_expr(BaseExprKind::Num),
|
base_expr(BaseExprKind::Num),
|
||||||
@@ -540,9 +528,11 @@ mod test {
|
|||||||
base_expr(BaseExprKind::Num)
|
base_expr(BaseExprKind::Num)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
//
|
);
|
||||||
// 1+2*3-4/5
|
|
||||||
|
test_parser!(
|
||||||
|
Parser::try_from("1+2*3-4/5").unwrap(),
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
base_expr(BaseExprKind::Num),
|
base_expr(BaseExprKind::Num),
|
||||||
@@ -560,8 +550,11 @@ mod test {
|
|||||||
base_expr(BaseExprKind::Num)
|
base_expr(BaseExprKind::Num)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
// 1 - -1 * 8
|
);
|
||||||
|
|
||||||
|
test_parser!(
|
||||||
|
Parser::try_from("1 - -1 * 8").unwrap(),
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
base_expr(BaseExprKind::Num),
|
base_expr(BaseExprKind::Num),
|
||||||
@@ -571,8 +564,11 @@ mod test {
|
|||||||
BinOp::Times,
|
BinOp::Times,
|
||||||
base_expr(BaseExprKind::Num)
|
base_expr(BaseExprKind::Num)
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
// 1--1*8
|
);
|
||||||
|
|
||||||
|
test_parser!(
|
||||||
|
Parser::try_from("1--1*8").unwrap(),
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
base_expr(BaseExprKind::Num),
|
base_expr(BaseExprKind::Num),
|
||||||
@@ -582,8 +578,11 @@ mod test {
|
|||||||
BinOp::Times,
|
BinOp::Times,
|
||||||
base_expr(BaseExprKind::Num)
|
base_expr(BaseExprKind::Num)
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
// 1 + 1 == 2
|
);
|
||||||
|
|
||||||
|
test_parser!(
|
||||||
|
Parser::try_from("1 + 1 == 2").unwrap(),
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
bin_expr(
|
bin_expr(
|
||||||
@@ -593,8 +592,11 @@ mod test {
|
|||||||
),
|
),
|
||||||
BinOp::EqEq,
|
BinOp::EqEq,
|
||||||
base_expr(BaseExprKind::Num)
|
base_expr(BaseExprKind::Num)
|
||||||
),
|
)
|
||||||
// 3 >= 1 + 2
|
);
|
||||||
|
|
||||||
|
test_parser!(
|
||||||
|
Parser::try_from("3 >= 1 + 2").unwrap(),
|
||||||
next_expr,
|
next_expr,
|
||||||
bin_expr(
|
bin_expr(
|
||||||
base_expr(BaseExprKind::Num),
|
base_expr(BaseExprKind::Num),
|
||||||
@@ -634,8 +636,8 @@ mod test {
|
|||||||
1,
|
1,
|
||||||
x,
|
x,
|
||||||
[
|
[
|
||||||
|
:key,
|
||||||
'value',
|
'value',
|
||||||
:value,
|
|
||||||
],
|
],
|
||||||
:sym
|
:sym
|
||||||
)").unwrap(),
|
)").unwrap(),
|
||||||
@@ -644,8 +646,8 @@ mod test {
|
|||||||
base_expr(BaseExprKind::Num),
|
base_expr(BaseExprKind::Num),
|
||||||
base_expr(BaseExprKind::Ident),
|
base_expr(BaseExprKind::Ident),
|
||||||
base_expr(BaseExprKind::List(vec![
|
base_expr(BaseExprKind::List(vec![
|
||||||
base_expr(BaseExprKind::Str),
|
|
||||||
base_expr(BaseExprKind::Sym),
|
base_expr(BaseExprKind::Sym),
|
||||||
|
base_expr(BaseExprKind::Str),
|
||||||
])),
|
])),
|
||||||
base_expr(BaseExprKind::Sym),
|
base_expr(BaseExprKind::Sym),
|
||||||
]))
|
]))
|
||||||
|
|||||||
Reference in New Issue
Block a user