|
1 | | -import XCTest |
| 1 | +import Testing |
2 | 2 | import JavaScriptKit |
3 | 3 |
|
4 | 4 | @JS struct GenericRTPoint { |
@@ -65,166 +65,169 @@ import JavaScriptKit |
65 | 65 | @JSFunction static func box<T: BridgedSwiftGenericBridgeable>(_ value: T) throws(JSException) -> T |
66 | 66 | } |
67 | 67 |
|
68 | | -class ImportGenericAPITests: XCTestCase { |
69 | | - func testGenericRoundTripScalars() throws { |
70 | | - XCTAssertEqual(try jsGenericRoundTrip(42), 42) |
71 | | - XCTAssertEqual(try jsGenericRoundTrip(-7), -7) |
72 | | - XCTAssertEqual(try jsGenericRoundTrip(3.5), 3.5) |
73 | | - XCTAssertEqual(try jsGenericRoundTrip(Float(1.25)), Float(1.25)) |
74 | | - XCTAssertEqual(try jsGenericRoundTrip(true), true) |
75 | | - XCTAssertEqual(try jsGenericRoundTrip(false), false) |
76 | | - XCTAssertEqual(try jsGenericRoundTrip("hello"), "hello") |
77 | | - XCTAssertEqual(try jsGenericRoundTrip(""), "") |
78 | | - } |
79 | | - |
80 | | - func testGenericRoundTripNumerics() throws { |
81 | | - XCTAssertEqual(try jsGenericRoundTrip(Int8(-5)), Int8(-5)) |
82 | | - XCTAssertEqual(try jsGenericRoundTrip(Int8.min), Int8.min) |
83 | | - XCTAssertEqual(try jsGenericRoundTrip(Int8.max), Int8.max) |
84 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt8(200)), UInt8(200)) |
85 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt8.max), UInt8.max) |
86 | | - XCTAssertEqual(try jsGenericRoundTrip(Int16(-1000)), Int16(-1000)) |
87 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt16(60000)), UInt16(60000)) |
88 | | - XCTAssertEqual(try jsGenericRoundTrip(Int32(-123456)), Int32(-123456)) |
89 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt32(3_000_000_000)), UInt32(3_000_000_000)) |
90 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt32.max), UInt32.max) |
91 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt(42)), UInt(42)) |
92 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt(4_000_000_000)), UInt(4_000_000_000)) |
93 | | - XCTAssertEqual(try jsGenericRoundTrip(Int64(-9_000_000_000)), Int64(-9_000_000_000)) |
94 | | - XCTAssertEqual(try jsGenericRoundTrip(Int64.min), Int64.min) |
95 | | - XCTAssertEqual(try jsGenericRoundTrip(Int64.max), Int64.max) |
96 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt64(18_000_000_000_000_000_000)), UInt64(18_000_000_000_000_000_000)) |
97 | | - XCTAssertEqual(try jsGenericRoundTrip(UInt64.max), UInt64.max) |
98 | | - } |
99 | | - |
100 | | - func testGenericRoundTripJSValue() throws { |
| 68 | +@Suite struct ImportGenericAPITests { |
| 69 | + @Test func genericRoundTripScalars() throws { |
| 70 | + #expect(try jsGenericRoundTrip(42) == 42) |
| 71 | + #expect(try jsGenericRoundTrip(-7) == -7) |
| 72 | + #expect(try jsGenericRoundTrip(3.5) == 3.5) |
| 73 | + #expect(try jsGenericRoundTrip(Float(1.25)) == Float(1.25)) |
| 74 | + #expect(try jsGenericRoundTrip(true) == true) |
| 75 | + #expect(try jsGenericRoundTrip(false) == false) |
| 76 | + #expect(try jsGenericRoundTrip("hello") == "hello") |
| 77 | + #expect(try jsGenericRoundTrip("") == "") |
| 78 | + } |
| 79 | + |
| 80 | + @Test func genericRoundTripNumerics() throws { |
| 81 | + #expect(try jsGenericRoundTrip(Int8(-5)) == Int8(-5)) |
| 82 | + #expect(try jsGenericRoundTrip(Int8.min) == Int8.min) |
| 83 | + #expect(try jsGenericRoundTrip(Int8.max) == Int8.max) |
| 84 | + #expect(try jsGenericRoundTrip(UInt8(200)) == UInt8(200)) |
| 85 | + #expect(try jsGenericRoundTrip(UInt8.max) == UInt8.max) |
| 86 | + #expect(try jsGenericRoundTrip(Int16(-1000)) == Int16(-1000)) |
| 87 | + #expect(try jsGenericRoundTrip(UInt16(60000)) == UInt16(60000)) |
| 88 | + #expect(try jsGenericRoundTrip(Int32(-123456)) == Int32(-123456)) |
| 89 | + #expect(try jsGenericRoundTrip(UInt32(3_000_000_000)) == UInt32(3_000_000_000)) |
| 90 | + #expect(try jsGenericRoundTrip(UInt32.max) == UInt32.max) |
| 91 | + #expect(try jsGenericRoundTrip(UInt(42)) == UInt(42)) |
| 92 | + #expect(try jsGenericRoundTrip(UInt(4_000_000_000)) == UInt(4_000_000_000)) |
| 93 | + #expect(try jsGenericRoundTrip(Int64(-9_000_000_000)) == Int64(-9_000_000_000)) |
| 94 | + #expect(try jsGenericRoundTrip(Int64.min) == Int64.min) |
| 95 | + #expect(try jsGenericRoundTrip(Int64.max) == Int64.max) |
| 96 | + #expect(try jsGenericRoundTrip(UInt64(18_000_000_000_000_000_000)) == UInt64(18_000_000_000_000_000_000)) |
| 97 | + #expect(try jsGenericRoundTrip(UInt64.max) == UInt64.max) |
| 98 | + } |
| 99 | + |
| 100 | + @Test func genericRoundTripJSValue() throws { |
101 | 101 | let number = try jsGenericRoundTrip(JSValue.number(3.5)) |
102 | | - XCTAssertEqual(number.number, 3.5) |
| 102 | + #expect(number.number == 3.5) |
103 | 103 | let string = try jsGenericRoundTrip(JSValue.string("hi")) |
104 | | - XCTAssertEqual(string.string, "hi") |
| 104 | + #expect(string.string == "hi") |
105 | 105 | let boolean = try jsGenericRoundTrip(JSValue.boolean(true)) |
106 | | - XCTAssertEqual(boolean.boolean, true) |
107 | | - XCTAssertTrue(try jsGenericRoundTrip(JSValue.null).isNull) |
108 | | - XCTAssertTrue(try jsGenericRoundTrip(JSValue.undefined).isUndefined) |
| 106 | + #expect(boolean.boolean == true) |
| 107 | + #expect(try jsGenericRoundTrip(JSValue.null).isNull) |
| 108 | + #expect(try jsGenericRoundTrip(JSValue.undefined).isUndefined) |
109 | 109 | let object = JSObject.global.Object.function!.new() |
110 | 110 | object.tag = 7 |
111 | 111 | let roundTripped = try jsGenericRoundTrip(JSValue.object(object)) |
112 | | - XCTAssertEqual(roundTripped.object?.tag.number, 7) |
| 112 | + #expect(roundTripped.object?.tag.number == 7) |
113 | 113 | } |
114 | 114 |
|
115 | | - func testGenericWrappedRoundTrip() throws { |
116 | | - XCTAssertEqual(try jsGenericArrayRoundTrip([1, 2, 3]), [1, 2, 3]) |
117 | | - XCTAssertEqual(try jsGenericArrayRoundTrip(["a", "b"]), ["a", "b"]) |
118 | | - XCTAssertEqual(try jsGenericArrayRoundTrip([Int]()), []) |
119 | | - XCTAssertEqual(try jsGenericOptionalRoundTrip(Optional<Int>.some(7)), 7) |
120 | | - XCTAssertEqual(try jsGenericOptionalRoundTrip(Optional<Int>.none), nil) |
121 | | - XCTAssertEqual(try jsGenericOptionalRoundTrip(Optional<String>.some("hi")), "hi") |
| 115 | + @Test func genericWrappedRoundTrip() throws { |
| 116 | + #expect(try jsGenericArrayRoundTrip([1, 2, 3]) == [1, 2, 3]) |
| 117 | + #expect(try jsGenericArrayRoundTrip(["a", "b"]) == ["a", "b"]) |
| 118 | + #expect(try jsGenericArrayRoundTrip([Int]()) == []) |
| 119 | + #expect(try jsGenericOptionalRoundTrip(Optional<Int>.some(7)) == 7) |
| 120 | + #expect(try jsGenericOptionalRoundTrip(Optional<Int>.none) == nil) |
| 121 | + #expect(try jsGenericOptionalRoundTrip(Optional<String>.some("hi")) == "hi") |
122 | 122 | let outcome = try jsGenericOptionalRoundTrip(Optional<GenericRTOutcome>.some(.ok(code: 5))) |
123 | 123 | guard case .some(.ok(let code)) = outcome else { |
124 | | - return XCTFail("expected .ok") |
| 124 | + Issue.record("expected .ok") |
| 125 | + return |
125 | 126 | } |
126 | | - XCTAssertEqual(code, 5) |
127 | | - XCTAssertNil(try jsGenericOptionalRoundTrip(Optional<GenericRTOutcome>.none)) |
128 | | - XCTAssertEqual(try jsGenericDictRoundTrip(["x": 1, "y": 2]), ["x": 1, "y": 2]) |
129 | | - XCTAssertEqual(try jsGenericDictRoundTrip([String: String]()), [:]) |
130 | | - } |
131 | | - |
132 | | - func testGenericRoundTripEnums() throws { |
133 | | - XCTAssertEqual(try jsGenericRoundTrip(GenericRTColor.red), .red) |
134 | | - XCTAssertEqual(try jsGenericRoundTrip(GenericRTColor.blue), .blue) |
135 | | - XCTAssertEqual(try jsGenericRoundTrip(GenericRTMode.dark), .dark) |
136 | | - XCTAssertEqual(try jsGenericRoundTrip(GenericRTMode.light).rawValue, "light") |
137 | | - XCTAssertEqual(try jsGenericRoundTrip(GenericRTLevel.high), .high) |
| 127 | + #expect(code == 5) |
| 128 | + #expect(try jsGenericOptionalRoundTrip(Optional<GenericRTOutcome>.none) == nil) |
| 129 | + #expect(try jsGenericDictRoundTrip(["x": 1, "y": 2]) == ["x": 1, "y": 2]) |
| 130 | + #expect(try jsGenericDictRoundTrip([String: String]()) == [:]) |
| 131 | + } |
| 132 | + |
| 133 | + @Test func genericRoundTripEnums() throws { |
| 134 | + #expect(try jsGenericRoundTrip(GenericRTColor.red) == .red) |
| 135 | + #expect(try jsGenericRoundTrip(GenericRTColor.blue) == .blue) |
| 136 | + #expect(try jsGenericRoundTrip(GenericRTMode.dark) == .dark) |
| 137 | + #expect(try jsGenericRoundTrip(GenericRTMode.light).rawValue == "light") |
| 138 | + #expect(try jsGenericRoundTrip(GenericRTLevel.high) == .high) |
138 | 139 | let outcome = try jsGenericRoundTrip(GenericRTOutcome.ok(code: 42)) |
139 | 140 | guard case .ok(let code) = outcome else { |
140 | | - return XCTFail("expected .ok") |
| 141 | + Issue.record("expected .ok") |
| 142 | + return |
141 | 143 | } |
142 | | - XCTAssertEqual(code, 42) |
| 144 | + #expect(code == 42) |
143 | 145 | let failure = try jsGenericRoundTrip(GenericRTOutcome.fail(message: "boom")) |
144 | 146 | guard case .fail(let message) = failure else { |
145 | | - return XCTFail("expected .fail") |
| 147 | + Issue.record("expected .fail") |
| 148 | + return |
146 | 149 | } |
147 | | - XCTAssertEqual(message, "boom") |
| 150 | + #expect(message == "boom") |
148 | 151 | } |
149 | 152 |
|
150 | | - func testGenericRoundTripStruct() throws { |
| 153 | + @Test func genericRoundTripStruct() throws { |
151 | 154 | let point = try jsGenericRoundTrip(GenericRTPoint(x: 1, y: 2)) |
152 | | - XCTAssertEqual(point.x, 1) |
153 | | - XCTAssertEqual(point.y, 2) |
| 155 | + #expect(point.x == 1) |
| 156 | + #expect(point.y == 2) |
154 | 157 | } |
155 | 158 |
|
156 | | - func testGenericRoundTripNestedStruct() throws { |
| 159 | + @Test func genericRoundTripNestedStruct() throws { |
157 | 160 | let metadata = try jsGenericRoundTrip(GenericRTNamespace.Metadata(label: "alpha", count: 7)) |
158 | | - XCTAssertEqual(metadata.label, "alpha") |
159 | | - XCTAssertEqual(metadata.count, 7) |
| 161 | + #expect(metadata.label == "alpha") |
| 162 | + #expect(metadata.count == 7) |
160 | 163 | } |
161 | 164 |
|
162 | | - func testGenericParse() throws { |
| 165 | + @Test func genericParse() throws { |
163 | 166 | let point: GenericRTPoint = try jsGenericParsePoint("{\"x\": 10, \"y\": 20}") |
164 | | - XCTAssertEqual(point.x, 10) |
165 | | - XCTAssertEqual(point.y, 20) |
| 167 | + #expect(point.x == 10) |
| 168 | + #expect(point.y == 20) |
166 | 169 | let n: Int = try jsGenericParsePoint("42") |
167 | | - XCTAssertEqual(n, 42) |
| 170 | + #expect(n == 42) |
168 | 171 | let string: String = try jsGenericParsePoint("\"hi\"") |
169 | | - XCTAssertEqual(string, "hi") |
| 172 | + #expect(string == "hi") |
170 | 173 | } |
171 | 174 |
|
172 | | - func testGenericPickFirstMultiUse() throws { |
173 | | - XCTAssertEqual(try jsImportPickFirst(10, 20) as Int, 10) |
174 | | - XCTAssertEqual(try jsImportPickFirst("a", "b") as String, "a") |
| 175 | + @Test func genericPickFirstMultiUse() throws { |
| 176 | + #expect(try jsImportPickFirst(10, 20) as Int == 10) |
| 177 | + #expect(try jsImportPickFirst("a", "b") as String == "a") |
175 | 178 | let firstPoint = try jsImportPickFirst(GenericRTPoint(x: 1, y: 2), GenericRTPoint(x: 3, y: 4)) |
176 | | - XCTAssertEqual(firstPoint.x, 1) |
177 | | - XCTAssertEqual(firstPoint.y, 2) |
| 179 | + #expect(firstPoint.x == 1) |
| 180 | + #expect(firstPoint.y == 2) |
178 | 181 | } |
179 | 182 |
|
180 | | - func testGenericMakeReturnOnly() throws { |
| 183 | + @Test func genericMakeReturnOnly() throws { |
181 | 184 | let made: Int = try jsImportMakeInt() |
182 | | - XCTAssertEqual(made, 123) |
| 185 | + #expect(made == 123) |
183 | 186 | } |
184 | 187 |
|
185 | | - func testGenericCombineSecondMultiParameter() throws { |
186 | | - XCTAssertEqual(try jsImportCombineSecond(7, "hello") as String, "hello") |
187 | | - XCTAssertEqual(try jsImportCombineSecond("x", 9) as Int, 9) |
| 188 | + @Test func genericCombineSecondMultiParameter() throws { |
| 189 | + #expect(try jsImportCombineSecond(7, "hello") as String == "hello") |
| 190 | + #expect(try jsImportCombineSecond("x", 9) as Int == 9) |
188 | 191 | let point = try jsImportCombineSecond(42, GenericRTPoint(x: 5, y: 6)) |
189 | | - XCTAssertEqual(point.x, 5) |
190 | | - XCTAssertEqual(point.y, 6) |
| 192 | + #expect(point.x == 5) |
| 193 | + #expect(point.y == 6) |
191 | 194 | } |
192 | 195 |
|
193 | | - func testGenericRoundTripHeapObjectClass() throws { |
| 196 | + @Test func genericRoundTripHeapObjectClass() throws { |
194 | 197 | let box = ImportGenericBox(value: 314) |
195 | | - XCTAssertEqual(box.get(), 314) |
| 198 | + #expect(box.get() == 314) |
196 | 199 | let sameBox = try jsGenericRoundTripClass(box) |
197 | | - XCTAssertEqual(sameBox.get(), 314) |
| 200 | + #expect(sameBox.get() == 314) |
198 | 201 | sameBox.value = 271 |
199 | | - XCTAssertEqual(box.get(), 271) |
| 202 | + #expect(box.get() == 271) |
200 | 203 | } |
201 | 204 |
|
202 | | - func testGenericMixedConsecutiveCalls() throws { |
203 | | - XCTAssertEqual(try jsGenericRoundTrip(1), 1) |
204 | | - XCTAssertEqual(try jsGenericRoundTrip("two"), "two") |
205 | | - XCTAssertEqual(try jsGenericRoundTrip(3.0), 3.0) |
| 205 | + @Test func genericMixedConsecutiveCalls() throws { |
| 206 | + #expect(try jsGenericRoundTrip(1) == 1) |
| 207 | + #expect(try jsGenericRoundTrip("two") == "two") |
| 208 | + #expect(try jsGenericRoundTrip(3.0) == 3.0) |
206 | 209 | let p = try jsGenericRoundTrip(GenericRTPoint(x: 4, y: 5)) |
207 | | - XCTAssertEqual(p.x, 4) |
208 | | - XCTAssertEqual(p.y, 5) |
| 210 | + #expect(p.x == 4) |
| 211 | + #expect(p.y == 5) |
209 | 212 | } |
210 | 213 |
|
211 | | - func testImportGenericInstanceMethod() throws { |
| 214 | + @Test func importGenericInstanceMethod() throws { |
212 | 215 | let consumer = try ImportGenericConsumer() |
213 | | - XCTAssertEqual(try consumer.identity(42), 42) |
214 | | - XCTAssertEqual(try consumer.identity(-7), -7) |
215 | | - XCTAssertEqual(try consumer.identity("hi"), "hi") |
216 | | - XCTAssertEqual(try consumer.identity(true), true) |
217 | | - XCTAssertEqual(try consumer.identity(false), false) |
| 216 | + #expect(try consumer.identity(42) == 42) |
| 217 | + #expect(try consumer.identity(-7) == -7) |
| 218 | + #expect(try consumer.identity("hi") == "hi") |
| 219 | + #expect(try consumer.identity(true) == true) |
| 220 | + #expect(try consumer.identity(false) == false) |
218 | 221 | let point = try consumer.identity(GenericRTPoint(x: 3, y: 4)) |
219 | | - XCTAssertEqual(point.x, 3) |
220 | | - XCTAssertEqual(point.y, 4) |
| 222 | + #expect(point.x == 3) |
| 223 | + #expect(point.y == 4) |
221 | 224 | } |
222 | 225 |
|
223 | | - func testImportGenericStaticMethod() throws { |
224 | | - XCTAssertEqual(try ImportGenericConsumer.box(7), 7) |
225 | | - XCTAssertEqual(try ImportGenericConsumer.box("s"), "s") |
226 | | - XCTAssertEqual(try ImportGenericConsumer.box(true), true) |
| 226 | + @Test func importGenericStaticMethod() throws { |
| 227 | + #expect(try ImportGenericConsumer.box(7) == 7) |
| 228 | + #expect(try ImportGenericConsumer.box("s") == "s") |
| 229 | + #expect(try ImportGenericConsumer.box(true) == true) |
227 | 230 | let color = try ImportGenericConsumer.box(GenericRTColor.green) |
228 | | - XCTAssertEqual(color, .green) |
| 231 | + #expect(color == .green) |
229 | 232 | } |
230 | 233 | } |
0 commit comments