diff --git a/src/archunitpython/slices/uml/generate_rules.py b/src/archunitpython/slices/uml/generate_rules.py index de65704..6739444 100644 --- a/src/archunitpython/slices/uml/generate_rules.py +++ b/src/archunitpython/slices/uml/generate_rules.py @@ -37,6 +37,7 @@ def generate_rule(puml_content: str) -> tuple[list[Rule], list[str]]: for line in lines: stripped = line.strip() + # Skip empty lines, comments, @startuml/@enduml if not stripped or stripped.startswith("@") or stripped.startswith("'"): @@ -50,8 +51,9 @@ def generate_rule(puml_content: str) -> tuple[list[Rule], list[str]]: contained_nodes.append(name) continue + without_arrow_direction = re.sub(r"(-+)[a-z]+(-+)>", r"\1\2>", stripped) # Match relationships: [Source] --> [Target] or [Source] -> [Target] - rel_match = re.match(r"\[([^\]]+)\]\s*-+>\s*\[([^\]]+)\]", stripped) + rel_match = re.match(r"\[([^\]]+)\]\s*-+>\s*\[([^\]]+)\]", without_arrow_direction) if rel_match: source = rel_match.group(1).strip() target = rel_match.group(2).strip() diff --git a/tests/slices/test_slices.py b/tests/slices/test_slices.py index 6773069..0aa2d3e 100644 --- a/tests/slices/test_slices.py +++ b/tests/slices/test_slices.py @@ -141,6 +141,20 @@ def test_components_with_colors(self): component [db] [api] -> [db] @enduml +""" + rules, nodes = generate_rule(puml) + assert "api" in nodes + assert "db" in nodes + assert len(rules) == 1 + + + def test_arrow_with_direction(self): + puml = """ +@startuml + component [api] + component [db] + [api] -d-> [db] +@enduml """ rules, nodes = generate_rule(puml) assert "api" in nodes