"""Tests for mutation rules.""" from app.dataset.rules.python.null_pointer import NoneReferenceRule from app.dataset.rules.python.boundary_error import BoundaryErrorRule from app.dataset.rules.python.logic_operator import LogicOperatorRule from app.dataset.rules.registry import get_registry def test_python_none_reference(): src = """def process(data): if data is not None: x = data.upper() return x """ m = NoneReferenceRule().detect_and_mutate(src) assert m is not None assert m.defect_type == "null_pointer" assert "if data is not None" not in m.mutated_source def test_python_boundary_error(): src = """def get(items, i): if i < len(items): return items[i] """ m = BoundaryErrorRule().detect_and_mutate(src) assert m is not None assert "<=" in m.mutated_source def test_python_logic_operator(): src = """def ok(a, b): return a and b """ m = LogicOperatorRule().detect_and_mutate(src) assert m is not None assert " or " in m.mutated_source def test_registry_discovers_rules(): registry = get_registry() assert "python" in registry.all_rules() assert "java" in registry.all_rules() assert "javascript" in registry.all_rules()