diff --git a/Sources/SpyableMacro/Factories/SpyFactory.swift b/Sources/SpyableMacro/Factories/SpyFactory.swift index ab2150a..e678ab3 100644 --- a/Sources/SpyableMacro/Factories/SpyFactory.swift +++ b/Sources/SpyableMacro/Factories/SpyFactory.swift @@ -102,10 +102,10 @@ struct SpyFactory { associatedtypeDeclList: assosciatedtypeDeclarations) let variableDeclarations = protocolDeclaration.memberBlock.members - .compactMap { $0.decl.as(VariableDeclSyntax.self) } + .compactMap { $0.decl.as(VariableDeclSyntax.self)?.removingLeadingSpaces } let functionDeclarations = protocolDeclaration.memberBlock.members - .compactMap { $0.decl.as(FunctionDeclSyntax.self) } + .compactMap { $0.decl.as(FunctionDeclSyntax.self)?.removingLeadingSpaces } return try ClassDeclSyntax( name: identifier, @@ -165,3 +165,21 @@ struct SpyFactory { ) } } + +private extension SyntaxProtocol { + /// - Returns: `self` with leading space `Trivia` removed. + var removingLeadingSpaces: Self { + with( + \.leadingTrivia, Trivia( + pieces: leadingTrivia + .filter { + if case .spaces = $0 { + false + } else { + true + } + } + ) + ) + } +} diff --git a/Tests/SpyableMacroTests/Macro/UT_SpyableMacro.swift b/Tests/SpyableMacroTests/Macro/UT_SpyableMacro.swift index 1b99d0c..e343da9 100644 --- a/Tests/SpyableMacroTests/Macro/UT_SpyableMacro.swift +++ b/Tests/SpyableMacroTests/Macro/UT_SpyableMacro.swift @@ -64,7 +64,7 @@ final class UT_SpyableMacro: XCTestCase { } } var underlyingAnyProtocol: (any Codable)! - var secondName: String? + var secondName: String? var added: () -> Void { get { underlyingAdded @@ -74,7 +74,7 @@ final class UT_SpyableMacro: XCTestCase { } } var underlyingAdded: (() -> Void)! - var removed: (() -> Void)? + var removed: (() -> Void)? var logoutCallsCount = 0 var logoutCalled: Bool { return logoutCallsCount > 0 @@ -91,7 +91,7 @@ final class UT_SpyableMacro: XCTestCase { var initializeNameSecondNameReceivedArguments: (name: String, secondName: String?)? var initializeNameSecondNameReceivedInvocations: [(name: String, secondName: String?)] = [] var initializeNameSecondNameClosure: ((String, String?) -> Void)? - func initialize(name: String, secondName: String?) { + func initialize(name: String, secondName: String?) { initializeNameSecondNameCallsCount += 1 initializeNameSecondNameReceivedArguments = (name, secondName) initializeNameSecondNameReceivedInvocations.append((name, secondName)) @@ -104,7 +104,7 @@ final class UT_SpyableMacro: XCTestCase { var fetchConfigThrowableError: (any Error)? var fetchConfigReturnValue: [String: String]! var fetchConfigClosure: (() async throws -> [String: String])? - func fetchConfig() async throws -> [String: String] { + func fetchConfig() async throws -> [String: String] { fetchConfigCallsCount += 1 if let fetchConfigThrowableError { throw fetchConfigThrowableError @@ -123,7 +123,7 @@ final class UT_SpyableMacro: XCTestCase { var fetchDataReceivedInvocations: [(String, count: Int)] = [] var fetchDataReturnValue: (() -> Void)! var fetchDataClosure: (((String, count: Int)) async -> (() -> Void))? - func fetchData(_ name: (String, count: Int)) async -> (() -> Void) { + func fetchData(_ name: (String, count: Int)) async -> (() -> Void) { fetchDataCallsCount += 1 fetchDataReceivedName = (name) fetchDataReceivedInvocations.append((name))