Skip to content

Commit b2ca4f9

Browse files
Macro tests
1 parent 8d3c223 commit b2ca4f9

File tree

4 files changed

+56
-82
lines changed

4 files changed

+56
-82
lines changed

Plugins/BridgeJS/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// swift-tools-version: 6.0
22

3+
import CompilerPluginSupport
34
import PackageDescription
45

56
let package = Package(

Plugins/BridgeJS/Tests/BridgeJSMacrosTests/JSClassMacroTests.swift

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import SwiftDiagnostics
22
import SwiftSyntax
33
import SwiftSyntaxMacros
44
import SwiftSyntaxMacrosTestSupport
5-
import XCTest
6-
import JavaScriptKitMacros
5+
import Testing
6+
import BridgeJSMacros
77

8-
final class JSClassMacroTests: XCTestCase {
8+
@Suite struct JSClassMacroTests {
99
private let indentationWidth: Trivia = .spaces(4)
1010

11-
func testEmptyStruct() {
11+
@Test func emptyStruct() {
1212
assertMacroExpansion(
1313
"""
1414
@JSClass
@@ -29,7 +29,7 @@ final class JSClassMacroTests: XCTestCase {
2929
)
3030
}
3131

32-
func testStructWithExistingJSObject() {
32+
@Test func structWithExistingJSObject() {
3333
assertMacroExpansion(
3434
"""
3535
@JSClass
@@ -51,7 +51,7 @@ final class JSClassMacroTests: XCTestCase {
5151
)
5252
}
5353

54-
func testStructWithExistingInit() {
54+
@Test func structWithExistingInit() {
5555
assertMacroExpansion(
5656
"""
5757
@JSClass
@@ -75,7 +75,7 @@ final class JSClassMacroTests: XCTestCase {
7575
)
7676
}
7777

78-
func testStructWithBothExisting() {
78+
@Test func structWithBothExisting() {
7979
assertMacroExpansion(
8080
"""
8181
@JSClass
@@ -101,7 +101,7 @@ final class JSClassMacroTests: XCTestCase {
101101
)
102102
}
103103

104-
func testStructWithMembers() {
104+
@Test func structWithMembers() {
105105
assertMacroExpansion(
106106
"""
107107
@JSClass
@@ -125,7 +125,7 @@ final class JSClassMacroTests: XCTestCase {
125125
)
126126
}
127127

128-
func testClass() {
128+
@Test func _class() {
129129
assertMacroExpansion(
130130
"""
131131
@JSClass
@@ -146,7 +146,7 @@ final class JSClassMacroTests: XCTestCase {
146146
)
147147
}
148148

149-
func testEnum() {
149+
@Test func _enum() {
150150
assertMacroExpansion(
151151
"""
152152
@JSClass
@@ -167,7 +167,7 @@ final class JSClassMacroTests: XCTestCase {
167167
)
168168
}
169169

170-
func testActor() {
170+
@Test func _actor() {
171171
assertMacroExpansion(
172172
"""
173173
@JSClass
@@ -188,7 +188,7 @@ final class JSClassMacroTests: XCTestCase {
188188
)
189189
}
190190

191-
func testStructWithDifferentJSObjectName() {
191+
@Test func structWithDifferentJSObjectName() {
192192
assertMacroExpansion(
193193
"""
194194
@JSClass
@@ -212,7 +212,7 @@ final class JSClassMacroTests: XCTestCase {
212212
)
213213
}
214214

215-
func testStructWithDifferentInit() {
215+
@Test func structWithDifferentInit() {
216216
assertMacroExpansion(
217217
"""
218218
@JSClass
@@ -238,7 +238,7 @@ final class JSClassMacroTests: XCTestCase {
238238
)
239239
}
240240

241-
func testStructWithMultipleMembers() {
241+
@Test func structWithMultipleMembers() {
242242
assertMacroExpansion(
243243
"""
244244
@JSClass
@@ -264,7 +264,7 @@ final class JSClassMacroTests: XCTestCase {
264264
)
265265
}
266266

267-
func testStructWithComment() {
267+
@Test func structWithComment() {
268268
assertMacroExpansion(
269269
"""
270270
/// Documentation comment
@@ -286,31 +286,4 @@ final class JSClassMacroTests: XCTestCase {
286286
indentationWidth: indentationWidth
287287
)
288288
}
289-
290-
func testEmptyMacro() {
291-
struct NoOpMacro: MemberMacro {
292-
static func expansion(
293-
of node: AttributeSyntax,
294-
providingMembersOf declaration: some DeclGroupSyntax,
295-
conformingTo protocols: [TypeSyntax],
296-
in context: some MacroExpansionContext
297-
) throws -> [DeclSyntax] {
298-
return []
299-
}
300-
}
301-
302-
assertMacroExpansion(
303-
"""
304-
@NoOp
305-
struct MyClass {
306-
}
307-
""",
308-
expandedSource: """
309-
struct MyClass {
310-
}
311-
""",
312-
macros: ["NoOp": NoOpMacro.self],
313-
indentationWidth: indentationWidth
314-
)
315-
}
316289
}

Plugins/BridgeJS/Tests/BridgeJSMacrosTests/JSFunctionMacroTests.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import SwiftDiagnostics
22
import SwiftSyntax
33
import SwiftSyntaxMacros
44
import SwiftSyntaxMacrosTestSupport
5-
import XCTest
6-
import JavaScriptKitMacros
5+
import Testing
6+
import BridgeJSMacros
77

8-
final class JSFunctionMacroTests: XCTestCase {
8+
@Suite struct JSFunctionMacroTests {
99
private let indentationWidth: Trivia = .spaces(4)
1010

11-
func testTopLevelFunction() {
11+
@Test func topLevelFunction() {
1212
assertMacroExpansion(
1313
"""
1414
@JSFunction
@@ -24,7 +24,7 @@ final class JSFunctionMacroTests: XCTestCase {
2424
)
2525
}
2626

27-
func testTopLevelFunctionVoidReturn() {
27+
@Test func topLevelFunctionVoidReturn() {
2828
assertMacroExpansion(
2929
"""
3030
@JSFunction
@@ -40,7 +40,7 @@ final class JSFunctionMacroTests: XCTestCase {
4040
)
4141
}
4242

43-
func testTopLevelFunctionWithExplicitVoidReturn() {
43+
@Test func topLevelFunctionWithExplicitVoidReturn() {
4444
assertMacroExpansion(
4545
"""
4646
@JSFunction
@@ -56,7 +56,7 @@ final class JSFunctionMacroTests: XCTestCase {
5656
)
5757
}
5858

59-
func testTopLevelFunctionWithEmptyTupleReturn() {
59+
@Test func topLevelFunctionWithEmptyTupleReturn() {
6060
assertMacroExpansion(
6161
"""
6262
@JSFunction
@@ -72,7 +72,7 @@ final class JSFunctionMacroTests: XCTestCase {
7272
)
7373
}
7474

75-
func testTopLevelFunctionThrows() {
75+
@Test func topLevelFunctionThrows() {
7676
assertMacroExpansion(
7777
"""
7878
@JSFunction
@@ -88,7 +88,7 @@ final class JSFunctionMacroTests: XCTestCase {
8888
)
8989
}
9090

91-
func testTopLevelFunctionAsync() {
91+
@Test func topLevelFunctionAsync() {
9292
assertMacroExpansion(
9393
"""
9494
@JSFunction
@@ -104,7 +104,7 @@ final class JSFunctionMacroTests: XCTestCase {
104104
)
105105
}
106106

107-
func testTopLevelFunctionAsyncThrows() {
107+
@Test func topLevelFunctionAsyncThrows() {
108108
assertMacroExpansion(
109109
"""
110110
@JSFunction
@@ -120,7 +120,7 @@ final class JSFunctionMacroTests: XCTestCase {
120120
)
121121
}
122122

123-
func testTopLevelFunctionWithUnderscoreParameter() {
123+
@Test func topLevelFunctionWithUnderscoreParameter() {
124124
assertMacroExpansion(
125125
"""
126126
@JSFunction
@@ -136,7 +136,7 @@ final class JSFunctionMacroTests: XCTestCase {
136136
)
137137
}
138138

139-
func testTopLevelFunctionWithMultipleParameters() {
139+
@Test func topLevelFunctionWithMultipleParameters() {
140140
assertMacroExpansion(
141141
"""
142142
@JSFunction
@@ -152,7 +152,7 @@ final class JSFunctionMacroTests: XCTestCase {
152152
)
153153
}
154154

155-
func testInstanceMethod() {
155+
@Test func instanceMethod() {
156156
assertMacroExpansion(
157157
"""
158158
struct MyClass {
@@ -172,7 +172,7 @@ final class JSFunctionMacroTests: XCTestCase {
172172
)
173173
}
174174

175-
func testStaticMethod() {
175+
@Test func staticMethod() {
176176
assertMacroExpansion(
177177
"""
178178
struct MyClass {
@@ -192,7 +192,7 @@ final class JSFunctionMacroTests: XCTestCase {
192192
)
193193
}
194194

195-
func testClassMethod() {
195+
@Test func classMethod() {
196196
assertMacroExpansion(
197197
"""
198198
class MyClass {
@@ -212,7 +212,7 @@ final class JSFunctionMacroTests: XCTestCase {
212212
)
213213
}
214214

215-
func testInitializer() {
215+
@Test func initializer() {
216216
assertMacroExpansion(
217217
"""
218218
struct MyClass {
@@ -233,7 +233,7 @@ final class JSFunctionMacroTests: XCTestCase {
233233
)
234234
}
235235

236-
func testInitializerThrows() {
236+
@Test func initializerThrows() {
237237
assertMacroExpansion(
238238
"""
239239
struct MyClass {
@@ -254,7 +254,7 @@ final class JSFunctionMacroTests: XCTestCase {
254254
)
255255
}
256256

257-
func testInitializerAsyncThrows() {
257+
@Test func initializerAsyncThrows() {
258258
assertMacroExpansion(
259259
"""
260260
struct MyClass {
@@ -275,7 +275,7 @@ final class JSFunctionMacroTests: XCTestCase {
275275
)
276276
}
277277

278-
func testInitializerWithoutEnclosingType() {
278+
@Test func initializerWithoutEnclosingType() {
279279
assertMacroExpansion(
280280
"""
281281
@JSFunction
@@ -296,7 +296,7 @@ final class JSFunctionMacroTests: XCTestCase {
296296
)
297297
}
298298

299-
func testUnsupportedDeclaration() {
299+
@Test func unsupportedDeclaration() {
300300
assertMacroExpansion(
301301
"""
302302
@JSFunction
@@ -317,7 +317,7 @@ final class JSFunctionMacroTests: XCTestCase {
317317
)
318318
}
319319

320-
func testEnumInstanceMethod() {
320+
@Test func enumInstanceMethod() {
321321
assertMacroExpansion(
322322
"""
323323
enum MyEnum {
@@ -337,7 +337,7 @@ final class JSFunctionMacroTests: XCTestCase {
337337
)
338338
}
339339

340-
func testActorInstanceMethod() {
340+
@Test func actorInstanceMethod() {
341341
assertMacroExpansion(
342342
"""
343343
actor MyActor {
@@ -357,7 +357,7 @@ final class JSFunctionMacroTests: XCTestCase {
357357
)
358358
}
359359

360-
func testFunctionWithExistingBody() {
360+
@Test func functionWithExistingBody() {
361361
assertMacroExpansion(
362362
"""
363363
@JSFunction

0 commit comments

Comments
 (0)