@@ -94,18 +94,41 @@ func boxedTypeRoundTripsThroughDynamicCasting(original: KnownUnbridged,
94
94
expectEqual(bridged as? String, nil)
95
95
}
96
96
97
+ func tupleCanBeDynamicallyCast(original: (Int, String),
98
+ bridged: AnyObject) {
99
+ expectTrue(original == bridged as! (Int, String))
100
+ }
101
+ func metatypeCanBeDynamicallyCast(original: Int.Type,
102
+ bridged: AnyObject) {
103
+ expectTrue(original == bridged as! Int.Type)
104
+ expectTrue(original == bridged as! Any.Type)
105
+ }
106
+
107
+ func guineaPigFunction() -> Int {
108
+ return 1738
109
+ }
110
+
111
+ func functionCanBeDynamicallyCast(original: () -> Int,
112
+ bridged: AnyObject) {
113
+ expectEqual(original(), (bridged as! () -> Int)())
114
+ expectEqual(original(), try! (bridged as! () throws -> Int)())
115
+ }
116
+
97
117
// We want to exhaustively check all paths through the bridging and dynamic
98
118
// casting infrastructure, so expand out test cases that wrap the different
99
119
// interesting bridging cases in different kinds of existential container.
100
120
%{
101
121
testCases = [
102
- ("classes", "LifetimeTracked(0)", "bridgedObjectPreservesIdentity"),
103
- ("strings", '"vitameatavegamin"', "stringBridgesToEqualNSString"),
104
- ("unbridged type", "KnownUnbridged()", "boxedTypeRoundTripsThroughDynamicCasting"),
122
+ ("classes", "LifetimeTracked(0)", "bridgedObjectPreservesIdentity", True),
123
+ ("strings", '"vitameatavegamin"', "stringBridgesToEqualNSString", True),
124
+ ("unbridged type", "KnownUnbridged()", "boxedTypeRoundTripsThroughDynamicCasting", True),
125
+ ("tuple", '(1, "2")', "tupleCanBeDynamicallyCast", False),
126
+ ("metatype", 'Int.self', "metatypeCanBeDynamicallyCast", False),
127
+ ("function", 'guineaPigFunction', "functionCanBeDynamicallyCast", False),
105
128
]
106
129
}%
107
130
108
- % for testName, valueExpr, testFunc in testCases:
131
+ % for testName, valueExpr, testFunc, conformsToError in testCases:
109
132
BridgeAnything.test("${testName}") {
110
133
do {
111
134
let x = ${valueExpr}
@@ -120,13 +143,15 @@ BridgeAnything.test("${testName}") {
120
143
${testFunc}(original: x, bridged: _bridgeAnythingToObjectiveC(xInAnyInAny))
121
144
${testFunc}(original: x, bridged: _bridgeAnythingNonVerbatimToObjectiveC(xInAnyInAny))
122
145
146
+ % if conformsToError:
123
147
let xInError: Error = x
124
148
${testFunc}(original: x, bridged: _bridgeAnythingToObjectiveC(xInError))
125
149
${testFunc}(original: x, bridged: _bridgeAnythingNonVerbatimToObjectiveC(xInError))
126
150
127
151
let xInErrorInAny = wantonlyWrapInAny(xInError)
128
152
${testFunc}(original: x, bridged: _bridgeAnythingToObjectiveC(xInErrorInAny))
129
153
${testFunc}(original: x, bridged: _bridgeAnythingNonVerbatimToObjectiveC(xInErrorInAny))
154
+ % end
130
155
}
131
156
}
132
157
% end
0 commit comments