diff --git a/cobol_testgen/cond.py b/cobol_testgen/cond.py index 2352669..a12b128 100644 --- a/cobol_testgen/cond.py +++ b/cobol_testgen/cond.py @@ -100,10 +100,9 @@ def parse_single_condition(text, fields=None): # Bare field reference (no operator, no NOT): WS-EOF → WS-EOF = 'Y' if re.match(r'^[A-Z][A-Z0-9_-]*(?:\([^)]*\))?\s*$', text, re.IGNORECASE): - bare = __import__('re').match(r'^[A-Z][A-Z0-9_-]*', text, re.IGNORECASE) - if bare: - return (bare.group(0), '=', 'Y') - return (text, '=', 'Y') + bare = re.match(r'^[A-Z][A-Z0-9_-]*', text, re.IGNORECASE) + field = bare.group(0) if bare else text + return (field, '=', 'Y') # Bare NOT field reference (no operator): NOT WS-EOF → WS-EOF <> 'Y' if text.upper().startswith('NOT ') and not re.search(r'(>=|<=|<>|>|<|=)', text): @@ -122,6 +121,9 @@ def parse_single_condition(text, fields=None): if m_inner: inv_op_map = {'=': '<>', '<>': '=', '>': '<=', '<': '>=', '>=': '<', '<=': '>'} f = re.sub(r'\s*([(),])\s*', r'\1', m_inner.group(1)) + bare = re.match(r"^(\w[\w-]*)", f) + if bare: + f = bare.group(1) op = m_inner.group(2) val = m_inner.group(3).strip().strip("'").strip('"') inv = inv_op_map.get(op, op) @@ -163,7 +165,7 @@ def parse_single_condition(text, fields=None): if field.upper().endswith(' NOT'): field = field[:-4].strip() # Strip subscript: WS-KEY-DUP-CNT(WS-J) -> WS-KEY-DUP-CNT - bare_m = __import__('re').match(r'^(\w[\w-]*)', field) + bare_m = re.match(r'^(\w[\w-]*)', field) if bare_m: field = bare_m.group(1) return (field, m.group(2), m.group(3).strip().strip("'").strip('"')) @@ -183,10 +185,9 @@ def parse_single_condition(text, fields=None): # Bare field: WS-EOF (no operator) -> WS-EOF = 'Y' if re.match(r'^[A-Z][A-Z0-9_-]*(?:\([^)]*\))?\s*$', text, re.IGNORECASE): - bare = __import__('re').match(r'^[A-Z][A-Z0-9_-]*', text, re.IGNORECASE) - if bare: - return (bare.group(0), '=', 'Y') - return (text, '=', 'Y') + bare = re.match(r'^[A-Z][A-Z0-9_-]*', text, re.IGNORECASE) + field = bare.group(0) if bare else text + return (field, '=', 'Y') return None diff --git a/cobol_testgen/coverage.py b/cobol_testgen/coverage.py index 011d2a8..2540551 100644 --- a/cobol_testgen/coverage.py +++ b/cobol_testgen/coverage.py @@ -182,14 +182,18 @@ def mark_coverage(decision_points, leaf_stats, branch_paths, fields): def _match_constraint(c, parsed): if len(c) != 4: return False - return (c[0] == parsed[0] and c[1] == parsed[1] + c0 = re.sub(r'\s*\(.*?\)\s*$', '', str(c[0])).strip() + p0 = re.sub(r'\s*\(.*?\)\s*$', '', str(parsed[0])).strip() + return (c0 == p0 and c[1] == parsed[1] and str(c[2]) == str(parsed[2])) def _match_leaf(c, leaf): if len(c) != 4: return False - return (c[0] == leaf.field and c[1] == leaf.op + c0 = re.sub(r'\s*\(.*?\)\s*$', '', str(c[0])).strip() + l0 = re.sub(r'\s*\(.*?\)\s*$', '', str(leaf.field)).strip() + return (c0 == l0 and c[1] == leaf.op and str(c[2]) == str(leaf.value))