forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebuggerSupport.swift
102 lines (83 loc) · 2.78 KB
/
DebuggerSupport.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
struct StructWithMembers {
var a = 1
var b = "Hello World"
}
class ClassWithMembers {
var a = 1
var b = "Hello World"
}
class ClassWithMirror: CustomReflectable {
var customMirror: Mirror {
return Mirror(self, children: ["a" : 1, "b" : "Hello World"])
}
}
#if _runtime(_ObjC)
struct DontBridgeThisStruct {
var message = "Hello World"
}
extension DontBridgeThisStruct : _ObjectiveCBridgeable {
typealias _ObjectiveCType = AnyObject
func _bridgeToObjectiveC() -> _ObjectiveCType {
fatalError("tried to bridge DontBridgeThisStruct")
}
static func _forceBridgeFromObjectiveC(
_ source: _ObjectiveCType,
result: inout DontBridgeThisStruct?
) {
result = nil
}
static func _conditionallyBridgeFromObjectiveC(
_ source: _ObjectiveCType,
result: inout DontBridgeThisStruct?
) -> Bool {
result = nil
return false
}
static func _unconditionallyBridgeFromObjectiveC(_ source: _ObjectiveCType?)
-> DontBridgeThisStruct {
return DontBridgeThisStruct()
}
}
#endif
let StringForPrintObjectTests = TestSuite("StringForPrintObject")
StringForPrintObjectTests.test("StructWithMembers") {
let printed = _DebuggerSupport.stringForPrintObject(StructWithMembers())
expectEqual(printed, "▿ StructWithMembers\n - a : 1\n - b : \"Hello World\"\n")
}
#if _runtime(_ObjC)
StringForPrintObjectTests.test("ClassWithMembers") {
let printed = _DebuggerSupport.stringForPrintObject(ClassWithMembers())
expectTrue(printed.hasPrefix("<ClassWithMembers: 0x"))
}
#endif
StringForPrintObjectTests.test("ClassWithMirror") {
let printed = _DebuggerSupport.stringForPrintObject(ClassWithMirror())
expectEqual(printed, "▿ ClassWithMirror\n - a : 1\n - b : \"Hello World\"\n")
}
StringForPrintObjectTests.test("Array") {
let printed = _DebuggerSupport.stringForPrintObject([1,2,3,4])
expectEqual(printed, "▿ 4 elements\n - 0 : 1\n - 1 : 2\n - 2 : 3\n - 3 : 4\n")
}
StringForPrintObjectTests.test("Dictionary") {
let printed = _DebuggerSupport.stringForPrintObject([1:2])
expectEqual("▿ 1 element\n ▿ 0 : 2 elements\n - key : 1\n - value : 2\n",
printed)
}
StringForPrintObjectTests.test("NilOptional") {
let printed = _DebuggerSupport.stringForPrintObject(nil as Int?)
expectEqual(printed, "nil\n")
}
StringForPrintObjectTests.test("SomeOptional") {
let printed = _DebuggerSupport.stringForPrintObject(3 as Int?)
expectEqual(printed, "▿ Optional<Int>\n - some : 3\n")
}
#if _runtime(_ObjC)
StringForPrintObjectTests.test("DontBridgeThisStruct") {
let printed = _DebuggerSupport.stringForPrintObject(DontBridgeThisStruct())
expectEqual(printed, "▿ DontBridgeThisStruct\n - message : \"Hello World\"\n")
}
#endif
runAllTests()