1
0
Fork 0

Add tests for omitting semicolons

This commit is contained in:
Vili Sinervä 2025-01-31 18:28:03 +02:00
parent 5d69d05c7b
commit 000fa5b77b
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996

View file

@ -429,3 +429,73 @@ fn test_var_chain() {
fn test_var_embedded() {
parse(&tokenize("if true then var x = 3"));
}
#[test]
fn test_omitting_semicolons() {
let result = parse(&tokenize("{ { a } { b } }"));
assert_eq!(
result,
Block(vec![
Block(vec![Identifier("a")]),
Block(vec![Identifier("b")])
])
);
let result = parse(&tokenize("{ if true then { a } b }"));
assert_eq!(
result,
Block(vec![
Conditional(
bool_ast!(true),
Box::new(Block(vec![Identifier("a")])),
None
),
Block(vec![Identifier("b")]),
])
);
let result = parse(&tokenize("{ if true then { a }; b }"));
assert_eq!(
result,
Block(vec![
Conditional(
bool_ast!(true),
Box::new(Block(vec![Identifier("a")])),
None
),
Block(vec![Identifier("b")]),
])
);
let result = parse(&tokenize("{ if true then { a } else { b } c }"));
assert_eq!(
result,
Block(vec![
Conditional(
bool_ast!(true),
Box::new(Block(vec![Identifier("a")])),
Some(Box::new(Block(vec![Identifier("b")])))
),
Block(vec![Identifier("c")]),
])
);
let result = parse(&tokenize("x = { { f(a) } { b } }"));
assert_eq!(
result,
BinaryOp(
id_ast!("x"),
"=",
Box::new(Block(vec![
Block(vec![FunCall("f", vec![Identifier("a")])]),
Block(vec![Identifier("b")]),
]))
)
);
}
#[test]
#[should_panic]
fn test_omitting_semicolons_invalid() {
parse(&tokenize("{ if true then { a } b c }"));
}