Skip to content

Commit a82d95b

Browse files
committed
Add test case
1 parent bd16ff7 commit a82d95b

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

Sources/OpenGraphShims/Attribute+Debug.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// Attribute+Debug.swift
33
// OpenGraphShims
44

5+
// Use 4 spaces instead of \t for bettern test case expect
6+
private let tab = " "
7+
58
extension Attribute: Swift.CustomDebugStringConvertible {
69
public var debugDescription: String {
710
_debugDescription(indent: 0)
811
}
912

1013
func _debugDescription(indent: Int) -> String {
11-
let tabs = String(repeating: "\t", count: indent)
14+
let tabs = String(repeating: tab, count: indent)
1215
return #"""
1316
\#(tabs)Attribute<\#(Value.self)> {
1417
\#(identifier._debugDescription(indent: indent + 1))
@@ -23,8 +26,8 @@ extension AnyAttribute: Swift.CustomDebugStringConvertible {
2326
}
2427

2528
func _debugDescription(indent: Int) -> String {
26-
let tabs = String(repeating: "\t", count: indent)
27-
29+
let tabs = String(repeating: tab, count: indent)
30+
2831
guard self != .nil else {
2932
return "\(tabs)AnyAttribute.nil"
3033
}
@@ -69,8 +72,8 @@ extension AnyAttribute: Swift.CustomDebugStringConvertible {
6972

7073
private func _formatBodyValue(_ bodyValue: Any, indent: Int) -> String {
7174
let bodyValueString = String(describing: bodyValue)
72-
let nextTabs = String(repeating: "\t", count: indent + 1)
73-
75+
let nextTabs = String(repeating: tab, count: indent + 1)
76+
7477
// Check if the body value contains attributes
7578
if bodyValueString.contains("Attribute<") {
7679
// Split lines and add proper indentation
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Attribute+DebugTests.swift
3+
// OpenGraphShimsTests
4+
5+
import Testing
6+
import OpenGraphShims
7+
8+
@MainActor
9+
@Suite(.disabled(if: !attributeGraphEnabled, "Subgraph is not implemented on OG"), .graphScope)
10+
struct Attribute_DebugTests {
11+
@Test
12+
func directAttribute() {
13+
let attribute = Attribute(value: 3)
14+
15+
#expect(attribute.debugDescription == #"""
16+
Attribute<Int> {
17+
rawValue: \#(attribute.identifier.rawValue)
18+
graph: \#(attribute.graph)
19+
(direct attribute)
20+
valueType: Int
21+
value: 3
22+
bodyType: External<Int>
23+
bodyValue:
24+
Int
25+
}
26+
"""#)
27+
}
28+
29+
@Test
30+
func indirectAttribute() {
31+
let tuple = Attribute(value: Tuple(first: 1, second: "2"))
32+
let second = tuple[keyPath: \.second]
33+
#expect(second.debugDescription == #"""
34+
Attribute<String> {
35+
rawValue: \#(second.identifier.rawValue)
36+
graph: \#(second.graph)
37+
(indirect attribute)
38+
source attribute:
39+
rawValue: \#(tuple.identifier.rawValue)
40+
graph: \#(tuple.graph)
41+
(direct attribute)
42+
valueType: Tuple<Int, String>
43+
value: Tuple<Int, String>(first: 1, second: "2")
44+
bodyType: External<Tuple<Int, String>>
45+
bodyValue:
46+
Tuple<Int, String>
47+
}
48+
"""#)
49+
}
50+
}

0 commit comments

Comments
 (0)