|
1 |
| -// RUN: %target-run-simple-swift | FileCheck %s |
| 1 | +// RUN: %target-run-simple-swift |
2 | 2 | // REQUIRES: executable_test
|
3 | 3 |
|
| 4 | +import StdlibUnittest |
| 5 | + |
| 6 | +let TypeNameTests = TestSuite("TypeName") |
| 7 | + |
4 | 8 | class C {}
|
5 | 9 | struct S {}
|
6 | 10 | enum E {}
|
@@ -30,108 +34,124 @@ struct GS<T : AssociatedTypes> {}
|
30 | 34 | enum GE<T : AssociatedTypes> {}
|
31 | 35 | class GC2<T : AssociatedTypes, U : AssociatedTypes> {}
|
32 | 36 |
|
33 |
| -func printTypeName(_ t: Any.Type) { print(_typeName(t)) } |
34 |
| - |
35 |
| -printTypeName(Int.self) // CHECK: Swift.Int |
36 |
| -printTypeName(C.self) // CHECK-NEXT: [[THIS:.*]].C |
37 |
| -printTypeName(S.self) // CHECK-NEXT: [[THIS]].S |
38 |
| -printTypeName(E.self) // CHECK-NEXT: [[THIS]].E |
39 |
| -printTypeName(GC<Model>.self) // CHECK-NEXT: [[THIS]].GC<[[THIS]].Model> |
40 |
| -printTypeName(GS<Model>.self) // CHECK-NEXT: [[THIS]].GS<[[THIS]].Model> |
41 |
| -printTypeName(GE<Model>.self) // CHECK-NEXT: [[THIS]].GE<[[THIS]].Model> |
42 |
| -printTypeName(GC2<Model, Model2>.self) // CHECK-NEXT: [[THIS]].GC2<[[THIS]].Model, [[THIS]].Model2> |
43 |
| - |
44 |
| -printTypeName(P.self) // CHECK-NEXT: [[THIS]].P |
45 |
| -typealias PP2 = protocol<P, P2> |
46 |
| -printTypeName(PP2.self) // CHECK-NEXT: protocol<[[THIS]].P, [[THIS]].P2> |
47 |
| -printTypeName(Any.self) // CHECK-NEXT: protocol<> |
48 |
| - |
49 |
| -typealias F = () -> () |
50 |
| -typealias F2 = () -> () -> () |
51 |
| -typealias F3 = (() -> ()) -> () |
52 |
| - |
53 |
| -printTypeName(F.self) // CHECK-NEXT: (()) -> () |
54 |
| -printTypeName(F2.self) // CHECK-NEXT: (()) -> (()) -> () |
55 |
| -printTypeName(F3.self) // CHECK-NEXT: (((()) -> ())) -> () |
56 |
| - |
57 |
| - |
58 |
| -#if _runtime(_ObjC) |
59 |
| -typealias B = @convention(block) () -> () |
60 |
| -typealias B2 = () -> @convention(block) () -> () |
61 |
| -typealias B3 = (@convention(block) () -> ()) -> () |
62 |
| -printTypeName(B.self) |
63 |
| -printTypeName(B2.self) |
64 |
| -printTypeName(B3.self) |
65 |
| -#else |
66 |
| -print("@convention(block) (()) -> ()") |
67 |
| -print("(()) -> @convention(block) (()) -> ()") |
68 |
| -print("((@convention(block) (()) -> ())) -> ()") |
69 |
| -#endif |
70 |
| -// CHECK-NEXT: @convention(block) (()) -> () |
71 |
| -// CHECK-NEXT: (()) -> @convention(block) (()) -> () |
72 |
| -// CHECK-NEXT: ((@convention(block) (()) -> ())) -> () |
73 |
| - |
74 |
| -printTypeName(F.Type.self) // CHECK-NEXT: ((()) -> ()).Type |
75 |
| -printTypeName(C.Type.self) // CHECK-NEXT: [[THIS]].C.Type |
76 |
| -printTypeName(C.Type.Type.self) // CHECK-NEXT: [[THIS]].C.Type.Type |
77 |
| -printTypeName(Any.Type.self) // CHECK-NEXT: protocol<>.Type |
78 |
| -printTypeName(Any.Protocol.self) // CHECK-NEXT: protocol<>.Protocol |
79 |
| -printTypeName(AnyObject.self) // CHECK-NEXT: {{^}}Swift.AnyObject{{$}} |
80 |
| -printTypeName(AnyClass.self) // CHECK-NEXT: {{^}}Swift.AnyObject.Type{{$}} |
81 |
| -printTypeName((AnyObject?).self) // CHECK-NEXT: {{^}}Swift.Optional<Swift.AnyObject>{{$}} |
82 |
| - |
83 |
| -printTypeName(Void.self) // CHECK-NEXT: () |
84 |
| -typealias Tup = (Any, F, C) |
85 |
| -printTypeName(Tup.self) // CHECK-NEXT: (protocol<>, (()) -> (), [[THIS]].C) |
86 |
| - |
87 |
| -typealias IF = (inout Int) -> () |
88 |
| -typealias IF2 = (inout Int) -> (inout Int) -> () |
89 |
| -typealias IF3 = ((inout Int) -> ()) -> () |
90 |
| -typealias IF3a = (inout ((Int) -> ())) -> () |
91 |
| -typealias IF3b = (inout ((Int) -> ())) -> () |
92 |
| -typealias IF3c = ((inout Int) -> ()) -> () |
93 |
| -typealias IF4 = (inout (() -> ())) -> () |
94 |
| -typealias IF5 = (inout Int, Any) -> () |
95 |
| - |
96 |
| -printTypeName(IF.self) // CHECK-NEXT: (inout Swift.Int) -> () |
97 |
| -printTypeName(IF2.self) // CHECK-NEXT: (inout Swift.Int) -> (inout Swift.Int) -> () |
98 |
| -printTypeName(IF3.self) // CHECK-NEXT: (((inout Swift.Int) -> ())) -> () |
99 |
| -printTypeName(IF3a.self) // CHECK-NEXT: (inout ((Swift.Int) -> ())) -> () |
100 |
| -printTypeName(IF3b.self) // CHECK-NEXT: (inout ((Swift.Int) -> ())) -> () |
101 |
| -printTypeName(IF3c.self) // CHECK-NEXT: (((inout Swift.Int) -> ())) -> () |
102 |
| -printTypeName(IF4.self) // CHECK-NEXT: (inout ((()) -> ())) -> () |
103 |
| -printTypeName(IF5.self) // CHECK-NEXT: (inout Swift.Int, protocol<>) -> () |
104 |
| - |
105 |
| -func curry1() { |
106 |
| - |
| 37 | +TypeNameTests.test("Prints") { |
| 38 | + expectEqual("Swift.Int", _typeName(Int.self)) |
| 39 | + expectEqual("main.C", _typeName(C.self)) |
| 40 | + expectEqual("main.S", _typeName(S.self)) |
| 41 | + expectEqual("main.E", _typeName(E.self)) |
| 42 | + expectEqual("main.GC<main.Model>", |
| 43 | + _typeName(GC<Model>.self)) |
| 44 | + expectEqual("main.GS<main.Model>", |
| 45 | + _typeName(GS<Model>.self)) |
| 46 | + expectEqual("main.GE<main.Model>", |
| 47 | + _typeName(GE<Model>.self)) |
| 48 | + expectEqual("main.GC2<main.Model, main.Model2>", |
| 49 | + _typeName(GC2<Model, Model2>.self)) |
| 50 | + |
| 51 | + expectEqual("main.P", _typeName(P.self)) |
| 52 | + typealias PP2 = protocol<P, P2> |
| 53 | + expectEqual("protocol<main.P, main.P2>", |
| 54 | + _typeName(PP2.self)) |
| 55 | + expectEqual("protocol<>", _typeName(Any.self)) |
| 56 | + |
| 57 | + typealias F = () -> () |
| 58 | + typealias F2 = () -> () -> () |
| 59 | + typealias F3 = (() -> ()) -> () |
| 60 | + |
| 61 | + expectEqual("(()) -> ()", _typeName(F.self)) |
| 62 | + expectEqual("(()) -> (()) -> ()", _typeName(F2.self)) |
| 63 | + expectEqual("(((()) -> ())) -> ()", _typeName(F3.self)) |
| 64 | + |
| 65 | + #if _runtime(_ObjC) |
| 66 | + typealias B = @convention(block) () -> () |
| 67 | + typealias B2 = () -> @convention(block) () -> () |
| 68 | + typealias B3 = (@convention(block) () -> ()) -> () |
| 69 | + expectEqual("@convention(block) (()) -> ()", _typeName(B.self)) |
| 70 | + expectEqual("(()) -> @convention(block) (()) -> ()", |
| 71 | + _typeName(B2.self)) |
| 72 | + expectEqual("((@convention(block) (()) -> ())) -> ()", |
| 73 | + _typeName(B3.self)) |
| 74 | + #endif |
| 75 | + |
| 76 | + expectEqual("((()) -> ()).Type", _typeName(F.Type.self)) |
| 77 | + expectEqual("main.C.Type", _typeName(C.Type.self)) |
| 78 | + expectEqual("main.C.Type.Type", _typeName(C.Type.Type.self)) |
| 79 | + expectEqual("protocol<>.Type", _typeName(Any.Type.self)) |
| 80 | + expectEqual("protocol<>.Protocol", _typeName(Any.Protocol.self)) |
| 81 | + expectEqual("Swift.AnyObject", _typeName(AnyObject.self)) |
| 82 | + expectEqual("Swift.AnyObject.Type", _typeName(AnyClass.self)) |
| 83 | + expectEqual("Swift.Optional<Swift.AnyObject>", |
| 84 | + _typeName((AnyObject?).self)) |
| 85 | + expectEqual("()", _typeName(Void.self)) |
| 86 | + |
| 87 | + |
| 88 | + typealias Tup = (Any, F, C) |
| 89 | + expectEqual("(protocol<>, (()) -> (), main.C)", |
| 90 | + _typeName(Tup.self)) |
107 | 91 | }
|
108 | 92 |
|
109 |
| -func curry1Throws() throws { |
110 |
| - |
| 93 | +TypeNameTests.test("Inout") { |
| 94 | + typealias IF = (inout Int) -> () |
| 95 | + typealias IF2 = (inout Int) -> (inout Int) -> () |
| 96 | + typealias IF3 = ((inout Int) -> ()) -> () |
| 97 | + typealias IF3a = (inout ((Int) -> ())) -> () |
| 98 | + typealias IF3b = (inout ((Int) -> ())) -> () |
| 99 | + typealias IF3c = ((inout Int) -> ()) -> () |
| 100 | + typealias IF4 = (inout (() -> ())) -> () |
| 101 | + typealias IF5 = (inout Int, Any) -> () |
| 102 | + |
| 103 | + expectEqual("(inout Swift.Int) -> ()", _typeName(IF.self)) |
| 104 | + expectEqual("(inout Swift.Int) -> (inout Swift.Int) -> ()", |
| 105 | + _typeName(IF2.self)) |
| 106 | + expectEqual("(((inout Swift.Int) -> ())) -> ()", |
| 107 | + _typeName(IF3.self)) |
| 108 | + expectEqual("(inout ((Swift.Int) -> ())) -> ()", |
| 109 | + _typeName(IF3a.self)) |
| 110 | + expectEqual("(inout ((Swift.Int) -> ())) -> ()", |
| 111 | + _typeName(IF3b.self)) |
| 112 | + expectEqual("(((inout Swift.Int) -> ())) -> ()", |
| 113 | + _typeName(IF3c.self)) |
| 114 | + expectEqual("(inout ((()) -> ())) -> ()", |
| 115 | + _typeName(IF4.self)) |
| 116 | + expectEqual("(inout Swift.Int, protocol<>) -> ()", |
| 117 | + _typeName(IF5.self)) |
111 | 118 | }
|
112 | 119 |
|
113 |
| -func curry2() -> () -> () { |
114 |
| - return curry1 |
115 |
| -} |
| 120 | +TypeNameTests.test("Functions") { |
| 121 | + func curry1() { |
116 | 122 |
|
117 |
| -func curry2Throws() throws -> () -> () { |
118 |
| - return curry1 |
119 |
| -} |
| 123 | + } |
120 | 124 |
|
121 |
| -func curry3() -> () throws -> () { |
122 |
| - return curry1Throws |
123 |
| -} |
| 125 | + func curry1Throws() throws { |
124 | 126 |
|
125 |
| -func curry3Throws() throws -> () throws -> () { |
126 |
| - return curry1Throws |
127 |
| -} |
| 127 | + } |
128 | 128 |
|
129 |
| -printTypeName(curry1.dynamicType) // CHECK-NEXT: (()) -> () |
| 129 | + func curry2() -> () -> () { |
| 130 | + return curry1 |
| 131 | + } |
130 | 132 |
|
131 |
| -printTypeName(curry2.dynamicType) // CHECK-NEXT: (()) -> (()) -> () |
| 133 | + func curry2Throws() throws -> () -> () { |
| 134 | + return curry1 |
| 135 | + } |
132 | 136 |
|
133 |
| -printTypeName(curry2Throws.dynamicType) // CHECK-NEXT: (()) throws -> (()) -> () |
| 137 | + func curry3() -> () throws -> () { |
| 138 | + return curry1Throws |
| 139 | + } |
134 | 140 |
|
135 |
| -printTypeName(curry3.dynamicType) // CHECK-NEXT: (()) -> (()) throws -> () |
| 141 | + func curry3Throws() throws -> () throws -> () { |
| 142 | + return curry1Throws |
| 143 | + } |
| 144 | + |
| 145 | + expectEqual("(()) -> ()", |
| 146 | + _typeName(curry1.dynamicType)) |
| 147 | + expectEqual("(()) -> (()) -> ()", |
| 148 | + _typeName(curry2.dynamicType)) |
| 149 | + expectEqual("(()) throws -> (()) -> ()", |
| 150 | + _typeName(curry2Throws.dynamicType)) |
| 151 | + expectEqual("(()) -> (()) throws -> ()", |
| 152 | + _typeName(curry3.dynamicType)) |
| 153 | + expectEqual("(()) throws -> (()) throws -> ()", |
| 154 | + _typeName(curry3Throws.dynamicType)) |
| 155 | +} |
136 | 156 |
|
137 |
| -printTypeName(curry3Throws.dynamicType) // CHECK-NEXT: (()) throws -> (()) throws -> () |
| 157 | +runAllTests() |
0 commit comments