test(joinir): Phase 88 - Fail-Fast validation for non-const i update
- Add test: rejects_non_const_then_i_update - Validates that continue pattern requires `i = i + const` form - Ensures Fail-Fast behavior for unsupported step patterns Impact: - 60 normalized_dev tests PASS (+1) - Fail-Fast 仕様固定(非 const の i 更新を拒否) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -313,6 +313,65 @@ fn test_phase88_jsonparser_unescape_string_step2_min_canonical_matches_structure
|
||||
assert_eq!(canonical, JoinValue::Int(5));
|
||||
}
|
||||
|
||||
/// Phase 88: Continue 側の `i` 更新は `i = i + const` のみに限定して Fail-Fast する。
|
||||
#[test]
|
||||
fn test_phase88_jsonparser_unescape_string_step2_min_rejects_non_const_then_i_update() {
|
||||
use std::any::Any;
|
||||
|
||||
fn panic_message(payload: Box<dyn Any + Send>) -> String {
|
||||
if let Some(s) = payload.downcast_ref::<&str>() {
|
||||
return (*s).to_string();
|
||||
}
|
||||
if let Some(s) = payload.downcast_ref::<String>() {
|
||||
return s.clone();
|
||||
}
|
||||
"<non-string panic payload>".to_string()
|
||||
}
|
||||
|
||||
// then 側の `i = i + n`(const ではない)を入れて、Fail-Fast を確認する。
|
||||
let program_json = serde_json::json!({
|
||||
"version": 0,
|
||||
"kind": "Program",
|
||||
"defs": [{
|
||||
"type": "FunctionDef",
|
||||
"name": "jsonparser_unescape_string_step2_min",
|
||||
"params": ["n"],
|
||||
"body": { "type": "Block", "body": [
|
||||
{ "type": "Local", "name": "i", "expr": { "type": "Int", "value": 0 } },
|
||||
{ "type": "Local", "name": "acc", "expr": { "type": "Int", "value": 0 } },
|
||||
{ "type": "Loop",
|
||||
"cond": { "type": "Compare", "op": "<", "lhs": { "type": "Var", "name": "i" }, "rhs": { "type": "Var", "name": "n" } },
|
||||
"body": [
|
||||
{ "type": "If",
|
||||
"cond": { "type": "Compare", "op": "<", "lhs": { "type": "Var", "name": "i" }, "rhs": { "type": "Var", "name": "n" } },
|
||||
"then": [
|
||||
{ "type": "Local", "name": "i", "expr": { "type": "Binary", "op": "+", "lhs": { "type": "Var", "name": "i" }, "rhs": { "type": "Var", "name": "n" } } },
|
||||
{ "type": "Continue" }
|
||||
],
|
||||
"else": []
|
||||
},
|
||||
{ "type": "Local", "name": "acc", "expr": { "type": "Binary", "op": "+", "lhs": { "type": "Var", "name": "acc" }, "rhs": { "type": "Int", "value": 0 } } },
|
||||
{ "type": "Local", "name": "i", "expr": { "type": "Binary", "op": "+", "lhs": { "type": "Var", "name": "i" }, "rhs": { "type": "Int", "value": 1 } } }
|
||||
]
|
||||
},
|
||||
{ "type": "Return", "expr": { "type": "Var", "name": "acc" } }
|
||||
]}
|
||||
}]
|
||||
});
|
||||
|
||||
let res = std::panic::catch_unwind(|| {
|
||||
let mut lowerer = nyash_rust::mir::join_ir::frontend::AstToJoinIrLowerer::new();
|
||||
lowerer.lower_program_json(&program_json);
|
||||
});
|
||||
assert!(res.is_err(), "expected fail-fast panic");
|
||||
let msg = panic_message(res.err().unwrap());
|
||||
assert!(
|
||||
msg.contains("then i update of form (i + const)"),
|
||||
"unexpected panic message: {}",
|
||||
msg
|
||||
);
|
||||
}
|
||||
|
||||
/// Phase 48-C: JsonParser _parse_object continue skip_ws canonical route should match Structured
|
||||
#[test]
|
||||
fn test_normalized_pattern4_jsonparser_parse_object_continue_skip_ws_canonical_matches_structured()
|
||||
|
||||
Reference in New Issue
Block a user