Skip to content

Commit dff2179

Browse files
committed
Add tests
1 parent ba15ee0 commit dff2179

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

Tests/SwiftSyntaxMacroExpansionTest/AccessorMacroTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import SwiftSyntaxMacros
2525
import SwiftSyntaxMacrosTestSupport
2626
import XCTest
2727

28-
private struct ConstantOneGetter: AccessorMacro {
28+
struct ConstantOneGetter: AccessorMacro {
2929
static func expansion(
3030
of node: AttributeSyntax,
3131
providingAccessorsOf declaration: some DeclSyntaxProtocol,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#if canImport(Testing)
2+
import Testing
3+
import SwiftSyntaxMacrosTestSupport
4+
5+
@Suite("Swift Testing Macro Expansion Tests")
6+
struct SwiftTestingMacroExpansionTests {
7+
@Test("Test Happy Path")
8+
func testHappyPathWorks() {
9+
assertMacroExpansion(
10+
"""
11+
@constantOne
12+
var x: Int /*1*/ // hello
13+
""",
14+
expandedSource: """
15+
var x: Int { /*1*/ // hello
16+
get {
17+
return 1
18+
}
19+
}
20+
""",
21+
macros: ["constantOne": ConstantOneGetter.self],
22+
indentationWidth: .spaces(2)
23+
)
24+
}
25+
26+
@Test("Test Failure")
27+
func failureReportedCorrectly() {
28+
withKnownIssue {
29+
assertMacroExpansion(
30+
"""
31+
@constantOne
32+
var x: Int /*1*/ // hello
33+
""",
34+
expandedSource: """
35+
var x: Int { /*1*/ // hello
36+
get {
37+
return 1
38+
}
39+
}
40+
""",
41+
macros: ["constantOne": ConstantOneGetter.self],
42+
indentationWidth: .spaces(4)
43+
)
44+
} matching: { issue in
45+
issue.description.contains("Macro expansion did not produce the expected expanded source")
46+
}
47+
}
48+
}
49+
#endif

0 commit comments

Comments
 (0)