Files
cobol-java-v3/test-data/s21_cond_fix_verify.py
T
NB-076 e5ab3baa46 提升:37/37基准程序全量解析+O(N)路径枚举+运行时gcov验证
## 核心变更

### 1. 新PROCEDURE DIVISION解析器(procedure_parser.py)
- 行级状态机替换旧的BrParser regex解析器
- 覆盖:IF/ELSE/END-IF(嵌套)、EVALUATE/WHEN/ALSO、
  PERFORM UNTIL/VARYING、READ/AT END/NOT AT END、
  SORT/MERGE、GO TO DEPENDING ON
- 之前:3/37程序有分支检测  →  现在:37/37全部有分支
- 速度:~20ms/程序,纯规则引擎

### 2. 桥接层(pipeline_bridge.py)
- 新解析器为主,旧解析器3秒超时兜底
- 自动选取分支数更多的结果

### 3. 线性路径枚举(design_mcdc.py)
- 替换旧的Cartesian积路径枚举(O(2^N))为每决策点独立枚举(O(N))
- 28-sysin: 162分支仅163条路径(之前需截断到60DP)
- 消除了500路径硬上限和60DP截断

### 4. 条件解析修复(cond.py)
- NOT运算符规范化:X NOT = 5 → X <> 5
- 88-level反向:NOT WS-EOF-Y → parent <> value
- 裸字段引用:NOT WS-EOF → WS-EOF <> 'Y'
- 验证:1182个IF条件中0个NOT污染

### 5. 约束字段过滤(__init__.py)
- OF限定词剥离:STD-KEY OF MASTER-REC → STD-KEY
- 下标字段解析:WS-ITEM(SUB) → WS-ITEM
- 跳过不在fields_dict中的字段(group item/伪影)

### 6. 预处理器增强(read.py)
- VALUE ALL剥离(VALUE ALL '*' → VALUE '*')
- &续行合并(COBOL多行字符串拼接)
- PIC小数点点→V转换(Z(9)9.99. → Z(9)9V99.)
- 缺少点号补全

### 7. Grammar修复(grammar.lark)
- OCCURS 1 TIME支持(原只认TIMES)
- USAGE IS COMP支持(可选IS)
- $符号在PICTURE_STRING中
- 无NAME条款支持(clause+)

### 8. Flatfile写入(flatfile.py)
- 多记录FD支持(选字段最多的记录)
- Path类型强制转换
- 回退零值记录

### 9. Bug修复
- trace_to_root空列表保护(core.py)

### 10. 测试套件(S16-S21)
- S16: 全量基准程序端到端
- S17: gcov运行时对比
- S18/S19: 桥接器验证
- S20: DISPLAY插桩运行时验证+gcov分支覆盖率
- S21: 条件解析修复验证
- 全部17/17回归测试通过

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 23:41:22 +08:00

66 lines
2.3 KiB
Python

"""S21: Verify condition parsing fix and constraint field filter"""
import sys, os, re
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
P=0;F=0
def ck(v,m=""): global P,F; (P:=P+1) if v else (F:=F+1, print(f" FAIL {m}"))
from cobol_testgen.cond import parse_single_condition
print("=== Issue 1: NOT operator swallowed into field name ===")
tests = [
('WS-FILE-OUT-STATUS NOT = "00"', ('WS-FILE-OUT-STATUS', '<>', '00')),
('WS-COUNT NOT > 5', ('WS-COUNT', '<=', '5')),
('WS-VAL NOT < 10', ('WS-VAL', '>=', '10')),
('AMOUNT = 100', ('AMOUNT', '=', '100')),
('WS-FLAG NOT = "Y"', ('WS-FLAG', '<>', 'Y')),
]
for text, expected in tests:
result = parse_single_condition(text, None)
ok = result == expected
ck(ok, f"parse_single_condition({text!r})\n expected {expected}\n got {result}")
if ok:
print(f" OK: {text!r}{result}")
else:
print(f" {text!r}")
print(f" expected: {expected}")
print(f" got: {result}")
print("\n=== Issue 2: Bare NOT field reference ===")
tests2 = [
('NOT WS-EOF', ('WS-EOF', '<>', 'Y')),
('WS-EOF', ('WS-EOF', '=', 'Y')),
]
for text, expected in tests2:
result = parse_single_condition(text, None)
ok = result == expected
ck(ok, f"parse_single_condition({text!r})\n expected {expected}\n got {result}")
if ok:
print(f" OK: {text!r}{result}")
else:
print(f" {text!r} -> {result} (expected {expected})")
print("\n=== Issue 2: 88-level resolution ===")
fields88 = [
{'name': 'WS-EOF-Y', 'is_88': True, 'parent': 'WS-EOF', 'value': 'Y'},
{'name': 'STATUS-OK', 'is_88': True, 'parent': 'WS-STATUS', 'value': '00'},
]
tests3 = [
('WS-EOF-Y', ('WS-EOF', '=', 'Y')),
('NOT WS-EOF-Y', ('WS-EOF', '<>', 'Y')),
('STATUS-OK', ('WS-STATUS', '=', '00')),
('NOT STATUS-OK', ('WS-STATUS', '<>', '00')),
]
for text, expected in tests3:
result = parse_single_condition(text, fields88)
ok = result == expected
ck(ok, f"parse({text!r})\n expected {expected}\n got {result}")
if ok:
print(f" OK: {text!r}{result}")
else:
print(f" {text!r} -> {result} (expected {expected})")
print(f"\n{'='*40}")
print(f"S21: {P} PASS / {F} FAIL")
if F > 0: sys.exit(1)