2025-09-03 20:03:45 +09:00
|
|
|
use crate::parser::NyashParser;
|
|
|
|
|
|
|
|
|
|
#[test]
|
2025-09-19 07:58:01 +09:00
|
|
|
fn parse_match_with_block_arm() {
|
2025-09-03 20:03:45 +09:00
|
|
|
let src = r#"
|
|
|
|
|
local x = 2
|
2025-09-19 07:58:01 +09:00
|
|
|
local y = match x {
|
2025-09-03 20:03:45 +09:00
|
|
|
1 => { local a = 10 a }
|
|
|
|
|
2 => { 20 }
|
2025-09-19 07:58:01 +09:00
|
|
|
_ => { 30 }
|
2025-09-03 20:03:45 +09:00
|
|
|
}
|
|
|
|
|
"#;
|
|
|
|
|
let ast = NyashParser::parse_from_string(src).expect("parse ok");
|
2025-09-23 09:00:07 +09:00
|
|
|
// Quick structural check: ensure AST contains MatchExpr and Program nodes inside arms
|
2025-09-03 20:03:45 +09:00
|
|
|
fn find_peek(ast: &crate::ast::ASTNode) -> bool {
|
|
|
|
|
match ast {
|
2025-09-23 09:00:07 +09:00
|
|
|
crate::ast::ASTNode::MatchExpr { arms, else_expr, .. } => {
|
2025-09-03 20:03:45 +09:00
|
|
|
// Expect at least one Program arm
|
|
|
|
|
let has_block = arms.iter().any(|(_, e)| matches!(e, crate::ast::ASTNode::Program { .. }));
|
|
|
|
|
let else_is_block = matches!(**else_expr, crate::ast::ASTNode::Program { .. });
|
|
|
|
|
has_block && else_is_block
|
|
|
|
|
}
|
|
|
|
|
crate::ast::ASTNode::Program { statements, .. } => statements.iter().any(find_peek),
|
|
|
|
|
_ => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert!(find_peek(&ast), "expected peek with block arms in AST");
|
|
|
|
|
}
|