test(joinir): add break condition extraction SSOT tests

This commit is contained in:
nyash-codex
2025-12-17 02:12:34 +09:00
parent bc1a09f2c3
commit af8c00dedb

View File

@ -378,6 +378,53 @@ mod tests {
assert!(result.is_err());
}
#[test]
fn test_extract_break_condition_node_then_break_returns_cond() {
let condition = ASTNode::Variable {
name: "x".to_string(),
span: Span::unknown(),
};
let body = vec![ASTNode::If {
condition: Box::new(condition.clone()),
then_body: vec![ASTNode::Break {
span: Span::unknown(),
}],
else_body: None,
span: Span::unknown(),
}];
let result = BreakConditionAnalyzer::extract_break_condition_node(&body).unwrap();
assert!(matches!(result, ASTNode::Variable { name, .. } if name == "x"));
}
#[test]
fn test_extract_break_condition_node_else_break_returns_not_cond() {
let condition = ASTNode::Variable {
name: "x".to_string(),
span: Span::unknown(),
};
let body = vec![ASTNode::If {
condition: Box::new(condition.clone()),
then_body: vec![],
else_body: Some(vec![ASTNode::Break {
span: Span::unknown(),
}]),
span: Span::unknown(),
}];
let result = BreakConditionAnalyzer::extract_break_condition_node(&body).unwrap();
match result {
ASTNode::UnaryOp {
operator: UnaryOperator::Not,
operand,
..
} => {
assert!(matches!(*operand, ASTNode::Variable { name, .. } if name == "x"));
}
other => panic!("expected UnaryOp::Not, got {:?}", other),
}
}
#[test]
fn test_validate_break_structure_valid() {
let var = ASTNode::Variable {