Skip to content

Commit 8f5a1ff

Browse files
authored
When linking inheritedType, if the name includes &, separate and link it (#82)
1 parent e2e93e0 commit 8f5a1ff

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/SwiftPlantUMLFramework/Internal/SyntaxStructure+PlantUML.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ extension SyntaxStructure {
3737
private func addLinking(context: PlantUMLContext) {
3838
if inheritedTypes != nil, inheritedTypes!.count > 0 {
3939
inheritedTypes!.forEach { parent in
40-
context.addLinking(item: self, parent: parent)
40+
if parent.name?.contains("&") == true {
41+
parent.name?
42+
.components(separatedBy: "&")
43+
.forEach {
44+
let name = $0.trimmingCharacters(in: .whitespacesAndNewlines)
45+
context.addLinking(item: self, parent: SyntaxStructure(name: name))
46+
}
47+
} else {
48+
context.addLinking(item: self, parent: parent)
49+
}
4150
}
4251
}
4352
}

Tests/SwiftPlantUMLFrameworkTests/PlantUMLScriptTests.swift

+25
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,31 @@ final class PlantUMLScriptTests: XCTestCase {
118118
#endif
119119
}
120120

121+
func testMultipleInheritanceSeparatedByAmpersand() {
122+
let code = """
123+
class MyClass: ProtocolA & ProtocolB {}
124+
"""
125+
let items = SyntaxStructure.create(from: code)!.substructure
126+
let script = PlantUMLScript(items: items!)
127+
let expected = """
128+
@startuml
129+
' STYLE START
130+
hide empty members
131+
skinparam shadowing false
132+
' STYLE END
133+
set namespaceSeparator none
134+
135+
136+
class "MyClass" as MyClass << (C, DarkSeaGreen) >> {
137+
}
138+
ProtocolA <|-- MyClass : inherits
139+
ProtocolB <|-- MyClass : inherits
140+
141+
@enduml
142+
"""
143+
XCTAssertEqual(script.text.noSpacesAndNoLineBreaks, expected.noSpacesAndNoLineBreaks)
144+
}
145+
121146
func getTestFile(named: String = "basics") throws -> URL {
122147
// https://stackoverflow.com/questions/47177036/use-resources-in-unit-tests-with-swift-package-manager
123148
let path = Bundle.module.path(forResource: named, ofType: "txt", inDirectory: "TestData") ?? "nonesense"

0 commit comments

Comments
 (0)