Skip to content

Commit ef3660c

Browse files
authored
Make Snapshot possible to shows a little better form of text representation (#106)
1 parent c499171 commit ef3660c

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

Sources/Atoms/Core/AtomCache.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
@MainActor
2-
internal protocol AtomCacheProtocol: CustomStringConvertible {
2+
internal protocol AtomCacheProtocol {
33
associatedtype Node: Atom
44

55
var atom: Node { get set }
66
var value: Node.Loader.Value { get set }
77
}
88

9-
internal extension AtomCacheProtocol {
9+
internal struct AtomCache<Node: Atom>: AtomCacheProtocol, CustomStringConvertible {
10+
var atom: Node
11+
var value: Node.Loader.Value
12+
1013
var description: String {
1114
"\(value)"
1215
}
1316
}
14-
15-
internal struct AtomCache<Node: Atom>: AtomCacheProtocol {
16-
var atom: Node
17-
var value: Node.Loader.Value
18-
}

Sources/Atoms/Core/AtomKey.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
internal struct AtomKey: Hashable {
1+
internal struct AtomKey: Hashable, CustomStringConvertible {
22
private let key: AnyHashable
33
private let type: ObjectIdentifier
44
private let scopeKey: ScopeKey?
55
private let anyAtomType: Any.Type
66

7-
var debugLabel: String {
7+
var description: String {
88
let atomLabel = String(describing: anyAtomType)
99

1010
if let scopeKey {
11-
return atomLabel + "-scoped:\(scopeKey.debugLabel)"
11+
return atomLabel + "-scoped:\(scopeKey)"
1212
}
1313
else {
1414
return atomLabel

Sources/Atoms/Core/ScopeKey.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
@usableFromInline
2-
internal struct ScopeKey: Hashable {
2+
internal struct ScopeKey: Hashable, CustomStringConvertible {
33
final class Token {}
44

55
private let identifier: ObjectIdentifier
66

7-
var debugLabel: String {
7+
@usableFromInline
8+
var description: String {
89
String(hashValue, radix: 36, uppercase: false)
910
}
1011

Sources/Atoms/Snapshot.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ public struct Snapshot: CustomStringConvertible {
6969
var statements = Set<String>()
7070

7171
for key in caches.keys {
72-
statements.insert(key.debugLabel.quoted)
72+
statements.insert(key.description.quoted)
7373

7474
if let children = graph.children[key] {
7575
for child in children {
76-
statements.insert("\(key.debugLabel.quoted) -> \(child.debugLabel.quoted)")
76+
statements.insert("\(key.description.quoted) -> \(child.description.quoted)")
7777
}
7878
}
7979

8080
if let subscriptions = subscriptions[key]?.values {
8181
for subscription in subscriptions {
8282
let label = "line:\(subscription.location.line)".quoted
8383
statements.insert("\(subscription.location.fileID.quoted) [style=filled]")
84-
statements.insert("\(key.debugLabel.quoted) -> \(subscription.location.fileID.quoted) [label=\(label)]")
84+
statements.insert("\(key.description.quoted) -> \(subscription.location.fileID.quoted) [label=\(label)]")
8585
}
8686
}
8787
}

Tests/AtomsTests/Core/AtomKeyTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class AtomKeyTests: XCTestCase {
4646
let key0 = AtomKey(atom)
4747
let key1 = AtomKey(atom, scopeKey: scopeKey)
4848

49-
XCTAssertEqual(key0.debugLabel, "TestAtom<Int>")
50-
XCTAssertEqual(key1.debugLabel, "TestAtom<Int>-scoped:\(scopeKey.debugLabel)")
49+
XCTAssertEqual(key0.description, "TestAtom<Int>")
50+
XCTAssertEqual(key1.description, "TestAtom<Int>-scoped:\(scopeKey.description)")
5151
}
5252
}

Tests/AtomsTests/SnapshotTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ final class SnapshotTests: XCTestCase {
9999
"TestAtom<Value2>" -> "TestAtom<Value3>"
100100
"TestAtom<Value3>"
101101
"TestAtom<Value3>" -> "Module/View.swift" [label="line:10"]
102-
"TestAtom<Value4>-scoped:\(scopeKey.debugLabel)"
103-
"TestAtom<Value4>-scoped:\(scopeKey.debugLabel)" -> "Module/View.swift" [label="line:10"]
102+
"TestAtom<Value4>-scoped:\(scopeKey.description)"
103+
"TestAtom<Value4>-scoped:\(scopeKey.description)" -> "Module/View.swift" [label="line:10"]
104104
}
105105
"""
106106
)

0 commit comments

Comments
 (0)