Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/archunitpython/slices/uml/generate_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("'"):
Expand All @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions tests/slices/test_slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down