Skip to content

Commit

Permalink
🐛 fix: incorrect PlantUMLScript when @unchecked Sendable present in S…
Browse files Browse the repository at this point in the history
…wift code

resolves #76
  • Loading branch information
MarcoEidinger committed Nov 11, 2023
1 parent 8e46455 commit 3ae71a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ class PlantUMLContext {
var index = 0

func addLinking(item: SyntaxStructure, parent: SyntaxStructure) {
let linkTo = parent.name?.removeAngleBracketsWithContent() ?? "___"
var linkTo = parent.name?.removeAngleBracketsWithContent() ?? "___"

// escape names like "@unchecked Sendable" for PlantUML
if linkTo.starts(with: "@") {
linkTo = "\"\(linkTo)\""
}

guard skipLinking(element: parent, basedOn: configuration.relationships.inheritance?.exclude) == false else { return }
let namedConnection = (uniqElementAndTypes[linkTo] != nil) ? "\(uniqElementAndTypes[linkTo] ?? "--ERROR--")" : "inherits"
var linkTypeKey = item.fullName! + "LinkType"
Expand Down
11 changes: 11 additions & 0 deletions Tests/SwiftPlantUMLFrameworkTests/PlantUMLContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ final class PlantUMLContextTests: XCTestCase {

XCTAssertEqual(context.connections.count, 0)
}

func testAddLinkingEscapeName() {
let superclass = SyntaxStructure(kind: .class, name: "@unchecked Sendable")
let subclass = SyntaxStructure(kind: .class, name: "Yoo")
let context = PlantUMLContext()

_ = context.uniqName(item: subclass, relationship: "inherits")
context.addLinking(item: subclass, parent: superclass)

XCTAssertEqual(context.connections.first!, #""@unchecked Sendable" <|-- Yoo : inherits"#)
}
}

0 comments on commit 3ae71a5

Please sign in to comment.