-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix typo in @ProvideFixture documentation * Remove redundant argument from initializerReference * Refactor ProvideFixture macro * Merge diagnostics into single type * Simplify FunctionDeclSyntax building * Move testMacro array into own file * Extract MacroExpansionExprSyntax initFixture into helper * Extract wrapInTry into own file
- Loading branch information
1 parent
13daa3a
commit 596426f
Showing
10 changed files
with
157 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Sources/SwiftFixtureMacros/Utilities/DiagnosticMessages.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import SwiftSyntax | ||
import SwiftDiagnostics | ||
|
||
struct DiagnosticMessages: DiagnosticMessage { | ||
let message: String | ||
let diagnosticID: MessageID | ||
let severity: DiagnosticSeverity | ||
|
||
private init( | ||
message: String, | ||
id: String, | ||
severity: DiagnosticSeverity = .error | ||
) { | ||
self.message = message | ||
self.diagnosticID = .init(domain: "SwiftFixture", id: id) | ||
self.severity = severity | ||
} | ||
|
||
static var requiresUnappliedMethodReference: Self { | ||
Self( | ||
message: "Argument must be an unapplied method reference for a static method or initializer", | ||
id: #function | ||
) | ||
} | ||
|
||
static var requiresBaseTypeOfUnappliedMethodReference: Self { | ||
Self( | ||
message: "Unapplied method reference must explicitly define the base type", | ||
id: #function | ||
) | ||
|
||
} | ||
|
||
static var requiresUnappliedMethodReferenceDeclarationNameArgumentList: Self { | ||
Self( | ||
message: "Declaration name argument list must be provided", | ||
id: #function | ||
) | ||
} | ||
|
||
static var unsupportedMember: Self { | ||
Self( | ||
message: "@ProvideFixture cannot be attached to this member", | ||
id: #function | ||
) | ||
} | ||
|
||
static var noInitializers: Self { | ||
Self( | ||
message: "@ProvideFixture requires that at least one initializer is defined", | ||
id: #function | ||
) | ||
} | ||
|
||
static var tooManyInitializers: Self { | ||
Self( | ||
message: "@ProvideFixture is unable to disambiguate between multiple initializers", | ||
id: #function | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Sources/SwiftFixtureMacros/Utilities/ExprSyntaxProtocol+Try.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import SwiftSyntax | ||
|
||
extension ExprSyntaxProtocol { | ||
func wrapInTry(_ wrapInTry: Bool = true) -> ExprSyntaxProtocol { | ||
if wrapInTry { | ||
return TryExprSyntax(expression: self) | ||
} else { | ||
return self | ||
} | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
Sources/SwiftFixtureMacros/Utilities/InitFixtureDiagnostic.swift
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
Sources/SwiftFixtureMacros/Utilities/MacroExpansionExprSyntax+Helpers.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import SwiftSyntax | ||
|
||
extension MacroExpansionExprSyntax { | ||
static func initFixture( | ||
valueProvider: some ExprSyntaxProtocol, | ||
unappliedMethodReference: some ExprSyntaxProtocol | ||
) -> Self { | ||
MacroExpansionExprSyntax(macro: "initFixture", leftParen: .leftParenToken(), rightParen: .rightParenToken()) { | ||
TupleExprElementSyntax( | ||
label: "with", | ||
expression: valueProvider | ||
) | ||
|
||
TupleExprElementSyntax( | ||
label: "using", | ||
expression: unappliedMethodReference | ||
) | ||
} | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
Sources/SwiftFixtureMacros/Utilities/ProvideFixtureDiagnostic.swift
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.