Skip to content

Commit

Permalink
test(parser): adapt expression parsing test to new code
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkeeyCat committed May 30, 2024
1 parent 66eaf2b commit 497549f
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,42 +182,35 @@ impl Parser {
#[cfg(test)]
mod test {
use super::Parser;
use crate::lexer::Lexer;
use crate::{
lexer::Lexer,
parser::{precedence::Precedence, BinOp, Expr, ExprBinary, ExprLit, IntLitRepr},
};

#[test]
fn parse_arithmetic_expression() {
let input = "1 * 2 + 3 / (4 + 1);";
let mut parser = Parser::new(Lexer::new(input.to_string()));

//assert_eq!(
// parser.parse_expression(Precedence::default()),
// Expr::Binary(ExprBinary::new(
// BinOp::Add,
// Box::new(Expr::Binary(ExprBinary::new(
// BinOp::Mul,
// Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::from_string(
// "1".to_string()
// )))),
// Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::from_string(
// "2".to_string()
// ))))
// ))),
// Box::new(Expr::Binary(ExprBinary::new(
// BinOp::Div,
// Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::from_string(
// "3".to_string()
// )))),
// Box::new(Expr::Binary(ExprBinary::new(
// BinOp::Add,
// Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::from_string(
// "4".to_string()
// )))),
// Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::from_string(
// "1".to_string()
// )))),
// )))
// )))
// ))
//);
assert_eq!(
parser.expr(Precedence::default() as u8),
Expr::Binary(ExprBinary::new(
BinOp::Add,
Box::new(Expr::Binary(ExprBinary::new(
BinOp::Mul,
Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::try_from("1").unwrap()))),
Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::try_from("2").unwrap())))
))),
Box::new(Expr::Binary(ExprBinary::new(
BinOp::Div,
Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::try_from("3").unwrap()))),
Box::new(Expr::Binary(ExprBinary::new(
BinOp::Add,
Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::try_from("4").unwrap()))),
Box::new(Expr::Lit(ExprLit::Int(IntLitRepr::try_from("1").unwrap()))),
)))
)))
))
);
}
}

0 comments on commit 497549f

Please sign in to comment.