@@ -251,7 +251,8 @@ public final class InitPackage {
251
251
} else if packageType == . macro {
252
252
pkgParams. append ( """
253
253
dependencies: [
254
- .package(url: " https://github.com/apple/swift-syntax.git " , branch: " main " ),
254
+ // Depend on the latest Swift 5.9 prerelease of SwiftSyntax
255
+ .package(url: " https://github.com/apple/swift-syntax.git " , from: " 509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-10-a " ),
255
256
]
256
257
""" )
257
258
}
@@ -591,32 +592,34 @@ public final class InitPackage {
591
592
]
592
593
593
594
final class \##( moduleName) Tests: XCTestCase {
594
- func testMacro() {
595
- // XCTest Documentation
596
- // https://developer.apple.com/documentation/xctest
597
-
598
- // Test input is a source file containing uses of the macro.
599
- let sf: SourceFileSyntax =
600
- #"""
601
- let a = #stringify(x + y)
602
- let b = #stringify("Hello, \(name)")
603
- """#
604
- let context = BasicMacroExpansionContext.init(
605
- sourceFiles: [sf: .init(moduleName: "MyModule", fullFilePath: "test.swift")]
606
- )
607
-
608
- // Expand the macro to produce a new source file with the
609
- // result of the expansion, and ensure that it has the
610
- // expected source code.
611
- let transformedSF = sf.expand(macros: testMacros, in: context)
612
- XCTAssertEqual(
613
- transformedSF.description,
614
- #"""
615
- let a = (x + y, "x + y")
616
- let b = ("Hello, \(name)", #""Hello, \(name)""#)
617
- """#
618
- )
619
- }
595
+ func testMacro() {
596
+ // XCTest Documentation
597
+ // https://developer.apple.com/documentation/xctest
598
+
599
+ // Test input is a source file containing uses of the macro.
600
+ let sf: SourceFileSyntax =
601
+ #"""
602
+ let a = #stringify(x + y)
603
+ let b = #stringify("Hello, \(name)")
604
+ """#
605
+
606
+ let context = BasicMacroExpansionContext(
607
+ sourceFiles: [sf: .init(moduleName: "MyModule", fullFilePath: "test.swift")]
608
+ )
609
+
610
+ // Expand the macro to produce a new source file with the
611
+ // result of the expansion, and ensure that it has the
612
+ // expected source code.
613
+ let transformedSF = sf.expand(macros: testMacros, in: context)
614
+
615
+ XCTAssertEqual(
616
+ transformedSF.description,
617
+ #"""
618
+ let a = (x + y, "x + y")
619
+ let b = ("Hello, \(name)", #""Hello, \(name)""#)
620
+ """#
621
+ )
622
+ }
620
623
}
621
624
622
625
"""##
@@ -643,23 +646,23 @@ public final class InitPackage {
643
646
///
644
647
/// (x + y, "x + y")
645
648
public struct StringifyMacro: ExpressionMacro {
646
- public static func expansion(
647
- of node: some FreestandingMacroExpansionSyntax,
648
- in context: some MacroExpansionContext
649
- ) -> ExprSyntax {
650
- guard let argument = node.argumentList.first?.expression else {
651
- fatalError("compiler bug: the macro does not have any arguments")
652
- }
649
+ public static func expansion(
650
+ of node: some FreestandingMacroExpansionSyntax,
651
+ in context: some MacroExpansionContext
652
+ ) -> ExprSyntax {
653
+ guard let argument = node.argumentList.first?.expression else {
654
+ fatalError("compiler bug: the macro does not have any arguments")
655
+ }
653
656
654
- return "(\(argument), \(literal: argument.description))"
655
- }
657
+ return "(\(argument), \(literal: argument.description))"
658
+ }
656
659
}
657
660
658
661
@main
659
662
struct \##( moduleName) Plugin: CompilerPlugin {
660
- let providingMacros: [Macro.Type] = [
661
- StringifyMacro.self,
662
- ]
663
+ let providingMacros: [Macro.Type] = [
664
+ StringifyMacro.self,
665
+ ]
663
666
}
664
667
665
668
"""##
0 commit comments