1
0
Fork 0

Add tests for future parser features

This commit is contained in:
Vili Sinervä 2025-01-28 16:47:11 +02:00
parent ffc0e812a2
commit ca5204d4b2
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
2 changed files with 39 additions and 1 deletions

View file

@ -3,7 +3,7 @@
pub enum Expression<'source> {
IntLiteral(u32),
BoolLiteral(bool),
Indentifier(String),
Identifier(&'source str),
BinaryOp(
Box<Expression<'source>>,
&'source str,

View file

@ -120,4 +120,42 @@ mod tests {
BinaryOp(Box::new(IntLiteral(4)), "-", Box::new(IntLiteral(56)))
);
}
#[test]
fn test_binary_op_identifier() {
let result = parse(&vec![new_id("a"), new_id("+"), new_int("1")]);
assert_eq!(
result,
BinaryOp(Box::new(Identifier("a")), "+", Box::new(IntLiteral(1)))
);
let result = parse(&vec![new_int("1"), new_id("-"), new_id("a")]);
assert_eq!(
result,
BinaryOp(Box::new(IntLiteral(1)), "-", Box::new(Identifier("a")))
);
}
#[test]
fn test_binary_op_multiple() {
let result = parse(&vec![
new_int("1"),
new_id("+"),
new_int("2"),
new_id("-"),
new_int("3"),
]);
assert_eq!(
result,
BinaryOp(
Box::new(IntLiteral(1)),
"+",
Box::new(BinaryOp(
Box::new(IntLiteral(2)),
"-",
Box::new(IntLiteral(3))
))
)
);
}
}