diff --git a/Sources/XCTestParametrizedMacroMacros/MacroDeclarationHelper.swift b/Sources/XCTestParametrizedMacroMacros/MacroDeclarationHelper.swift index dae618d..ef7cf38 100644 --- a/Sources/XCTestParametrizedMacroMacros/MacroDeclarationHelper.swift +++ b/Sources/XCTestParametrizedMacroMacros/MacroDeclarationHelper.swift @@ -8,6 +8,17 @@ struct MacroDeclarationHelper { self.declaration = declaration } + + /// Returns 'TokenSyntax' representing name of the input parameter. + var inputParamName: TokenSyntax? { + declaration.signature.input.parameterList.first?.secondName + } + + /// Returns 'TypeSyntax' representing type of the input object. + var inputParamType: TypeSyntax? { + declaration.signature.input.parameterList.first?.type + } + var firstAttribute: AttributeSyntax? { return declaration.attributes.first?.as(AttributeSyntax.self) } diff --git a/Sources/XCTestParametrizedMacroMacros/XCTestParametrizedMacroMacro.swift b/Sources/XCTestParametrizedMacroMacros/XCTestParametrizedMacroMacro.swift index 3b42951..ee2eda2 100644 --- a/Sources/XCTestParametrizedMacroMacros/XCTestParametrizedMacroMacro.swift +++ b/Sources/XCTestParametrizedMacroMacros/XCTestParametrizedMacroMacro.swift @@ -18,11 +18,11 @@ public struct ParametrizeMacro: PeerMacro { let macroDeclarationHelper = MacroDeclarationHelper(declaration) let funcName = declaration.identifier - guard let inputParamName = declaration.signature.input.parameterList.first?.secondName?.text else { + guard let inputParamName = macroDeclarationHelper.inputParamName?.text else { throw ParametrizeMacroError.functionInputParamSecondNameMissing } - guard let inputParamType = declaration.signature.input.parameterList.first?.type else { + guard let inputParamType = macroDeclarationHelper.inputParamType else { throw ParametrizeMacroError.functionInputParamTypeMissing }