Skip to content

Commit

Permalink
When linking inheritedType, if the name includes &, separate and li…
Browse files Browse the repository at this point in the history
…nk it (#82)
  • Loading branch information
TTOzzi authored Feb 22, 2024
1 parent e2e93e0 commit 8f5a1ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ extension SyntaxStructure {
private func addLinking(context: PlantUMLContext) {
if inheritedTypes != nil, inheritedTypes!.count > 0 {
inheritedTypes!.forEach { parent in
context.addLinking(item: self, parent: parent)
if parent.name?.contains("&") == true {
parent.name?
.components(separatedBy: "&")
.forEach {
let name = $0.trimmingCharacters(in: .whitespacesAndNewlines)
context.addLinking(item: self, parent: SyntaxStructure(name: name))
}
} else {
context.addLinking(item: self, parent: parent)
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions Tests/SwiftPlantUMLFrameworkTests/PlantUMLScriptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ final class PlantUMLScriptTests: XCTestCase {
#endif
}

func testMultipleInheritanceSeparatedByAmpersand() {
let code = """
class MyClass: ProtocolA & ProtocolB {}
"""
let items = SyntaxStructure.create(from: code)!.substructure
let script = PlantUMLScript(items: items!)
let expected = """
@startuml
' STYLE START
hide empty members
skinparam shadowing false
' STYLE END
set namespaceSeparator none
class "MyClass" as MyClass << (C, DarkSeaGreen) >> {
}
ProtocolA <|-- MyClass : inherits
ProtocolB <|-- MyClass : inherits
@enduml
"""
XCTAssertEqual(script.text.noSpacesAndNoLineBreaks, expected.noSpacesAndNoLineBreaks)
}

func getTestFile(named: String = "basics") throws -> URL {
// https://stackoverflow.com/questions/47177036/use-resources-in-unit-tests-with-swift-package-manager
let path = Bundle.module.path(forResource: named, ofType: "txt", inDirectory: "TestData") ?? "nonesense"
Expand Down

0 comments on commit 8f5a1ff

Please sign in to comment.