From af8c00dedbbe692e82e9ea967d0b62844b656df3 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Wed, 17 Dec 2025 02:12:34 +0900 Subject: [PATCH] test(joinir): add break condition extraction SSOT tests --- .../break_condition_analyzer.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/mir/loop_pattern_detection/break_condition_analyzer.rs b/src/mir/loop_pattern_detection/break_condition_analyzer.rs index 21e53566..6fbe2183 100644 --- a/src/mir/loop_pattern_detection/break_condition_analyzer.rs +++ b/src/mir/loop_pattern_detection/break_condition_analyzer.rs @@ -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 {