fbaad010ab
6 test files covering: - test_arithmetic_statements (9 samples) - test_control_statements (6 samples) - test_file_statements (6 samples) - test_inspect_statements (3 samples) - test_move_statements (5 samples) - test_perform_statements (3 samples) - test_search_statements (2 samples) All 34/34 pass. Full regression: 691 passed (0 new failures).
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""L0 测试 — COBOL 算术语句解析 + 数据生成验证"""
|
|
|
|
from pathlib import Path
|
|
import pytest
|
|
|
|
from cobol_testgen import extract_structure, generate_data
|
|
|
|
FIXTURES = Path(__file__).parents[3] / "test-data" / "cobol" / "statement_arithmetic"
|
|
|
|
SAMPLE_CHECKS = [
|
|
("ST-ADD-TO", {"has_divide": False}, True),
|
|
("ST-ADD-GIVING", {"has_divide": False}, True),
|
|
("ST-ADD-ROUNDED", {"has_divide": False}, True),
|
|
("ST-SUB-FROM", {"has_divide": False}, True),
|
|
("ST-SUB-GIVING", {"has_divide": False}, True),
|
|
("ST-MUL-BY", {"has_divide": False}, True),
|
|
("ST-MUL-GIVING", {"has_divide": False}, True),
|
|
("ST-DIV-BY-GIVING", {"has_divide": True, "divide_constants": []}, True),
|
|
("ST-COMPLEX", {"has_divide": False}, True),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("name,expected,expect_data", SAMPLE_CHECKS,
|
|
ids=[c[0] for c in SAMPLE_CHECKS])
|
|
def test_arithmetic_statement(name, expected, expect_data):
|
|
path = FIXTURES / f"{name}.cbl"
|
|
assert path.exists(), f"Missing sample: {path}"
|
|
source = path.read_text("utf-8")
|
|
|
|
struct = extract_structure(source)
|
|
assert struct is not None
|
|
assert struct.get("total_paragraphs", 0) > 0
|
|
|
|
for key, val in expected.items():
|
|
assert struct.get(key) == val, f"{name}: expected {key}={val}, got {struct.get(key)}"
|
|
|
|
if expect_data:
|
|
data = generate_data(source, struct)
|
|
assert len(data) >= 1, f"{name}: generate_data returned empty"
|