-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c0719b
commit ad6e977
Showing
8 changed files
with
226 additions
and
31 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
6 changes: 6 additions & 0 deletions
6
Sources/XCTestParametrizedMacro/XCTestParametrizedMacro.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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
@attached(peer, names: arbitrary) | ||
public macro Parametrize<I>(input: [I]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro") | ||
|
||
@attached(peer, names: arbitrary) | ||
public macro Parametrize<I>(input: [I], labels: [String]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro") | ||
|
||
@attached(peer, names: arbitrary) | ||
public macro Parametrize<I, O>(input: [I], output: [O]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro") | ||
|
||
@attached(peer, names: arbitrary) | ||
public macro Parametrize<I, O>(input: [I], output: [O], labels: [String]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro") |
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
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
148 changes: 148 additions & 0 deletions
148
Tests/XCTestParametrizedMacroTests/LabelsParameterTests.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,148 @@ | ||
import SwiftSyntaxMacros | ||
import SwiftSyntaxMacrosTestSupport | ||
import XCTest | ||
|
||
import XCTestParametrizedMacroMacros | ||
|
||
final class LabelsParameterTests: XCTestCase { | ||
|
||
let testMacros: [String: Macro.Type] = [ | ||
"Parametrize": ParametrizeMacro.self, | ||
] | ||
|
||
func testParametrizeInputLabels_OneLabel() throws { | ||
assertMacroExpansion( | ||
""" | ||
struct TestStruct { | ||
@Parametrize(input: [3.1415], labels: ["Pi"]) | ||
func testValidateDouble(input n: Double) { | ||
XCTAssertNotNil(validate_number(n)) | ||
} | ||
} | ||
""", | ||
expandedSource: """ | ||
struct TestStruct { | ||
func testValidateDouble(input n: Double) { | ||
XCTAssertNotNil(validate_number(n)) | ||
} | ||
func testValidateDouble_Pi() throws { | ||
let n: Double = 3.1415 | ||
XCTAssertNotNil(validate_number(n)) | ||
} | ||
} | ||
""", | ||
macros: testMacros | ||
) | ||
} | ||
|
||
func testParametrizeInputOutputLabels_OneLabel() throws { | ||
assertMacroExpansion( | ||
""" | ||
struct TestStruct { | ||
@Parametrize(input: [3], output: [9], labels: ["ThreePowerOfTheTwo"]) | ||
func testPow2(input n: Int, output result: Int) { | ||
XCTAssertEqual(pow2(n),result) | ||
} | ||
} | ||
""", | ||
expandedSource: """ | ||
struct TestStruct { | ||
func testPow2(input n: Int, output result: Int) { | ||
XCTAssertEqual(pow2(n),result) | ||
} | ||
func testPow2_ThreePowerOfTheTwo() throws { | ||
let n: Int = 3 | ||
let result: Int = 9 | ||
XCTAssertEqual(pow2(n), result) | ||
} | ||
} | ||
""", | ||
macros: testMacros | ||
) | ||
} | ||
|
||
func testParametrizeInputOutputLabels_TwoLabels() throws { | ||
assertMacroExpansion( | ||
""" | ||
struct TestStruct { | ||
@Parametrize(input: [3, 4], output: [9, 16], labels: ["ThreePowerOfTheTwo", "FourPowerOfTheTwo"]) | ||
func testPow2(input n: Int, output result: Int) { | ||
XCTAssertEqual(pow2(n),result) | ||
} | ||
} | ||
""", | ||
expandedSource: """ | ||
struct TestStruct { | ||
func testPow2(input n: Int, output result: Int) { | ||
XCTAssertEqual(pow2(n),result) | ||
} | ||
func testPow2_ThreePowerOfTheTwo() throws { | ||
let n: Int = 3 | ||
let result: Int = 9 | ||
XCTAssertEqual(pow2(n), result) | ||
} | ||
func testPow2_FourPowerOfTheTwo() throws { | ||
let n: Int = 4 | ||
let result: Int = 16 | ||
XCTAssertEqual(pow2(n), result) | ||
} | ||
} | ||
""", | ||
macros: testMacros | ||
) | ||
} | ||
|
||
func testParametrizeInputOutputLabels_CustomObjects() throws { | ||
assertMacroExpansion( | ||
""" | ||
struct TestStruct { | ||
@Parametrize( | ||
input: [APIEndpoint.profile, APIEndpoint.transactions, APIEndpoint.order("2345")], | ||
output: ["https://example.com/api/me", | ||
"https://example.com/api/transactions", | ||
"https://example.com/api/order/2345"], | ||
labels: ["profile", | ||
"transactions", | ||
"order"]) | ||
func testEndpointURL(input endpoint: APIEndpoint, output expectedUrl: String) throws { | ||
XCTAssertEqual(endpoint.buildURL?.absoluteString, expectedUrl) | ||
} | ||
} | ||
""", | ||
expandedSource: """ | ||
struct TestStruct { | ||
func testEndpointURL(input endpoint: APIEndpoint, output expectedUrl: String) throws { | ||
XCTAssertEqual(endpoint.buildURL?.absoluteString, expectedUrl) | ||
} | ||
func testEndpointURL_profile() throws { | ||
let endpoint: APIEndpoint = APIEndpoint.profile | ||
let expectedUrl: String = "https://example.com/api/me" | ||
XCTAssertEqual(endpoint.buildURL?.absoluteString, expectedUrl) | ||
} | ||
func testEndpointURL_transactions() throws { | ||
let endpoint: APIEndpoint = APIEndpoint.transactions | ||
let expectedUrl: String = | ||
"https://example.com/api/transactions" | ||
XCTAssertEqual(endpoint.buildURL?.absoluteString, expectedUrl) | ||
} | ||
func testEndpointURL_order() throws { | ||
let endpoint: APIEndpoint = APIEndpoint.order("2345") | ||
let expectedUrl: String = | ||
"https://example.com/api/order/2345" | ||
XCTAssertEqual(endpoint.buildURL?.absoluteString, expectedUrl) | ||
} | ||
} | ||
""", | ||
macros: testMacros | ||
) | ||
} | ||
} | ||
|
||
|