Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Graph+Debug API #106

Merged
merged 1 commit into from
Feb 21, 2025
Merged
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
41 changes: 41 additions & 0 deletions Sources/OpenGraphShims/Graph+Debug.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Graph+Debug.swift
// OpenGraphShims

// FIXME: Update name in OpenGraph
public typealias Graph = OGGraph
public typealias Subgraph = OGSubgraph

#if canImport(Darwin)

import Foundation

@_spi(Debug)
extension Graph {
public var dict: [String: Any]? {
let options = ["format": "graph/dict"] as NSDictionary
guard let description = Graph.description(nil, options: options) else {
return nil

Check warning on line 18 in Sources/OpenGraphShims/Graph+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Graph+Debug.swift#L15-L18

Added lines #L15 - L18 were not covered by tests
}
guard let dictionary = description.takeUnretainedValue() as? NSDictionary else {
return nil

Check warning on line 21 in Sources/OpenGraphShims/Graph+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Graph+Debug.swift#L20-L21

Added lines #L20 - L21 were not covered by tests
}
return dictionary as? [String: Any]

Check warning on line 23 in Sources/OpenGraphShims/Graph+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Graph+Debug.swift#L23

Added line #L23 was not covered by tests
}

// style:
// - bold: empty input/output edge
// - dashed: indirect or has no value
// color:
// - red: is_changed
public var dot: String? {
let options = ["format": "graph/dot"] as NSDictionary
guard let description = Graph.description(self, options: options)
else {
return nil

Check warning on line 35 in Sources/OpenGraphShims/Graph+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Graph+Debug.swift#L31-L35

Added lines #L31 - L35 were not covered by tests
}
return description.takeUnretainedValue() as? String

Check warning on line 37 in Sources/OpenGraphShims/Graph+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Graph+Debug.swift#L37

Added line #L37 was not covered by tests
}
}

#endif