test(joinir): add break condition extraction SSOT tests
This commit is contained in:
@ -378,6 +378,53 @@ mod tests {
|
|||||||
assert!(result.is_err());
|
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]
|
#[test]
|
||||||
fn test_validate_break_structure_valid() {
|
fn test_validate_break_structure_valid() {
|
||||||
let var = ASTNode::Variable {
|
let var = ASTNode::Variable {
|
||||||
|
|||||||
Reference in New Issue
Block a user