Skip to content

Commit

Permalink
code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkowalski87 committed Nov 10, 2023
1 parent 6091c97 commit 7bf440e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@attached(peer, names: arbitrary)
public macro Parametrize<T>(input: [T]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro")
public macro Parametrize<I>(input: [I]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro")

@attached(peer, names: arbitrary)
public macro Parametrize<I, O>(input: [I], output: [O]) = #externalMacro(module: "XCTestParametrizedMacroMacros", type: "ParametrizeMacro")
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum ParametrizeMacroError: Error, CustomStringConvertible {
case functionInputParamTypeMissing
case functionBodyEmpty
case macroAttributeNotAnArray
case macroAttributeMismatchSizeInputOutputArray
case macroAttributeArraysMismatchSize

var description: String {
switch self {
Expand All @@ -19,8 +19,8 @@ enum ParametrizeMacroError: Error, CustomStringConvertible {
case .functionBodyEmpty:
return "Function must have a body."
case .macroAttributeNotAnArray:
return "Parametrize macro requires at least one attribute as array of input values."
case .macroAttributeMismatchSizeInputOutputArray:
return "Parametrize macro requires at least one attribute as array of input/output values."
case .macroAttributeArraysMismatchSize:
return "Size of the input array and output array should be the same."
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct TestMethodsFactory {
let input = inputValues.map { $0 }
let output = outputValues.map { $0 }
guard input.count == output.count else {
throw ParametrizeMacroError.macroAttributeMismatchSizeInputOutputArray
throw ParametrizeMacroError.macroAttributeArraysMismatchSize
}
return try zip(input, output).map { input, output in
"""
Expand Down
4 changes: 2 additions & 2 deletions Tests/XCTestParametrizedMacroTests/AttachmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class AttachmentTests: XCTestCase {
}
""",
diagnostics: [
DiagnosticSpec(message: "Parametrize macro requires at least one attribute as array of input values.", line: 2, column: 5)
DiagnosticSpec(message: "Parametrize macro requires at least one attribute as array of input/output values.", line: 2, column: 5)
],
macros: testMacros
)
Expand All @@ -157,7 +157,7 @@ final class AttachmentTests: XCTestCase {
}
""",
diagnostics: [
DiagnosticSpec(message: "Parametrize macro requires at least one attribute as array of input values.", line: 2, column: 5)
DiagnosticSpec(message: "Parametrize macro requires at least one attribute as array of input/output values.", line: 2, column: 5)
],
macros: testMacros
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class InputOutputParametersTests: XCTestCase {
"Parametrize": ParametrizeMacro.self,
]

func testParametrizeInputOutput_SingleObject() throws {
func testParametrizeInputOutput_SingleInts() throws {
assertMacroExpansion(
"""
struct TestStruct {
Expand Down
26 changes: 0 additions & 26 deletions Tests/XCTestParametrizedMacroTests/SimpleValuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,30 +271,4 @@ final class SimpleValuesTests: XCTestCase {
)
}

func testParametrizeInputOutput_SingleObject() throws {
assertMacroExpansion(
"""
struct TestStruct {
@Parametrize(input: [3], output: [9])
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_N_3_Result_9() throws {
let n: Int = 3
let result: Int = 9
XCTAssertEqual(pow2(n), result)
}
}
""",
macros: testMacros
)
}
}

0 comments on commit 7bf440e

Please sign in to comment.