test(parser): add implicit multiplication tests
added tests: - implicit multiplication between a number + variable - implicit multiplication between two paren groups
This commit is contained in:
1 file changed
+45
@@ -116,3 +116,48 @@ fn test_parser_negative_exponent() {
|
||||
let result = parser::from(tokens).parse();
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parser_implicit_multiply() {
|
||||
let tokens = vec![Token::Number(dec!(5)), Token::Identifier("x".to_owned())];
|
||||
let expected = Expression::Operation(
|
||||
Operator::Multiply,
|
||||
Box::new(Expression::Number(dec!(5))),
|
||||
Box::new(Expression::Variable("x".to_owned())),
|
||||
);
|
||||
|
||||
let result = parser::from(tokens).parse();
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parser_implicit_multiply_group() {
|
||||
let tokens = vec![
|
||||
Token::OpenParen,
|
||||
Token::Number(dec!(5)),
|
||||
Token::Operator(Operator::Add),
|
||||
Token::Number(dec!(5)),
|
||||
Token::CloseParen,
|
||||
Token::OpenParen,
|
||||
Token::Number(dec!(10)),
|
||||
Token::Operator(Operator::Add),
|
||||
Token::Number(dec!(10)),
|
||||
Token::CloseParen,
|
||||
];
|
||||
let expected = Expression::Operation(
|
||||
Operator::Multiply,
|
||||
Box::new(Expression::Operation(
|
||||
Operator::Add,
|
||||
Box::new(Expression::Number(dec!(5))),
|
||||
Box::new(Expression::Number(dec!(5))),
|
||||
)),
|
||||
Box::new(Expression::Operation(
|
||||
Operator::Add,
|
||||
Box::new(Expression::Number(dec!(10))),
|
||||
Box::new(Expression::Number(dec!(10))),
|
||||
)),
|
||||
);
|
||||
|
||||
let result = parser::from(tokens).parse();
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
Reference in new issue
Block a user