1
0
Fork 0

Expand and adjust function parsing tests

This commit is contained in:
Vili Sinervä 2025-01-29 14:33:25 +02:00
parent c133ced4fc
commit a7adbe0f5b
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
2 changed files with 41 additions and 7 deletions

View file

@ -13,5 +13,5 @@ pub enum Expression<'source> {
Box<Expression<'source>>,
Option<Box<Expression<'source>>>,
),
FunCall(Vec<Box<Expression<'source>>>),
FunCall(&'source str, Vec<Box<Expression<'source>>>),
}

View file

@ -488,8 +488,39 @@ mod tests {
]);
assert_eq!(
result,
FunCall(vec![Box::new(Identifier("a")), Box::new(Identifier("b")),])
FunCall(
"f",
vec![Box::new(Identifier("a")), Box::new(Identifier("b")),]
)
);
let result = parse(&vec![
new_id("f"),
new_punc("("),
new_id("a"),
new_punc(","),
new_int("1"),
new_id("+"),
new_int("2"),
new_punc(")"),
]);
assert_eq!(
result,
FunCall(
"f",
vec![
Box::new(Identifier("a")),
Box::new(BinaryOp(
Box::new(IntLiteral(1)),
"+",
Box::new(IntLiteral(2)),
)),
]
)
);
let result = parse(&vec![new_id("f"), new_punc("("), new_punc(")")]);
assert_eq!(result, FunCall("f", vec![]));
}
#[test]
@ -507,10 +538,13 @@ mod tests {
]);
assert_eq!(
result,
FunCall(vec![
Box::new(Identifier("a")),
Box::new(FunCall(vec![Box::new(Identifier("b"))])),
])
FunCall(
"f",
vec![
Box::new(Identifier("a")),
Box::new(FunCall("g", vec![Box::new(Identifier("b"))])),
]
)
);
}
@ -529,7 +563,7 @@ mod tests {
BinaryOp(
Box::new(IntLiteral(1)),
"+",
Box::new(FunCall(vec![Box::new(Identifier("a"))]))
Box::new(FunCall("f", vec![Box::new(Identifier("a"))]))
)
);
}