diff --git a/Sources/Rubicon/Generator/InitGenerator.swift b/Sources/Rubicon/Generator/InitGenerator.swift index 1018e7e..81a67c8 100644 --- a/Sources/Rubicon/Generator/InitGenerator.swift +++ b/Sources/Rubicon/Generator/InitGenerator.swift @@ -45,7 +45,9 @@ final class InitGeneratorImpl: InitGenerator { private func makeInitArgument(from variable: VarDeclaration, isAddingDefaultValueToOptionalsEnabled: Bool) -> String { let defaultValue = isAddingDefaultValueToOptionalsEnabled && variable.type.isOptional ? " = nil" : "" - let declaration = ArgumentDeclaration(name: variable.identifier, type: variable.type) + let prefix = variable.type.isOptional ? [] : variable.type.prefix + let type = TypeDeclaration(name: variable.type.name, isOptional: variable.type.isOptional, prefix: prefix) + let declaration = ArgumentDeclaration(name: variable.identifier, type: type) return argumentGenerator.makeCode(from: declaration) + defaultValue } } diff --git a/Tests/RubiconTests/Generator/InitGeneratorTests.swift b/Tests/RubiconTests/Generator/InitGeneratorTests.swift index a0b8f58..8c77f1f 100644 --- a/Tests/RubiconTests/Generator/InitGeneratorTests.swift +++ b/Tests/RubiconTests/Generator/InitGeneratorTests.swift @@ -61,7 +61,10 @@ final class InitGeneratorTests: XCTestCase { initialize(accessLevel: .public) let result = sut.makeCode( - with: [.makeStub(), .makeStub(type: .makeStub(isOptional: true))], + with: [ + .makeStub(type: .makeStub(prefix: [.escaping])), + .makeStub(type: .makeStub(isOptional: true, prefix: [.escaping])) + ], isAddingDefaultValueToOptionalsEnabled: false ) @@ -72,7 +75,8 @@ final class InitGeneratorTests: XCTestCase { "}", ]) XCTAssertEqual(argumentGeneratorSpy.makeCode.count, 2) - XCTAssertEqual(argumentGeneratorSpy.makeCode.first?.declaration, .makeStub(label: nil, name: "identifier", type: .makeStub())) + XCTAssertEqual(argumentGeneratorSpy.makeCode.first?.declaration, .makeStub(label: nil, name: "identifier", type: .makeStub(prefix: [.escaping]))) + XCTAssertEqual(argumentGeneratorSpy.makeCode.last?.declaration, .makeStub(label: nil, name: "identifier", type: .makeStub(isOptional: true, prefix: []))) } func test_givenOptionalVariableAndIsAddingDefaultValueToOptionalsEnabled_whenMakeCode_thenMakeInit() { diff --git a/Tests/RubiconTests/Integration/SpyIntegrationTests.swift b/Tests/RubiconTests/Integration/SpyIntegrationTests.swift index 13cb6ea..28fff7f 100644 --- a/Tests/RubiconTests/Integration/SpyIntegrationTests.swift +++ b/Tests/RubiconTests/Integration/SpyIntegrationTests.swift @@ -55,7 +55,7 @@ final class SpyIntegrationTests: XCTestCase { "-var continueFromScreenId = [ContinueFromScreenId]()", "-var continueFromId = [ContinueFromId]()", "", - "-init(name: String? = nil, color: Int, loadThrowBlock: @escaping (() throws -> Void)? = nil, loadReturn: Int, isFullReturn: Bool, downloadThrowBlock: @escaping (() throws -> Void)? = nil, downloadReturn: [String]) {", + "-init(name: String? = nil, color: Int, loadThrowBlock: (() throws -> Void)? = nil, loadReturn: Int, isFullReturn: Bool, downloadThrowBlock: (() throws -> Void)? = nil, downloadReturn: [String]) {", "--self.name = name", "--self.color = color", "--self.loadThrowBlock = loadThrowBlock", diff --git a/Tests/RubiconTests/Integration/StubIntegrationTests.swift b/Tests/RubiconTests/Integration/StubIntegrationTests.swift index 4e5e940..e8a647e 100644 --- a/Tests/RubiconTests/Integration/StubIntegrationTests.swift +++ b/Tests/RubiconTests/Integration/StubIntegrationTests.swift @@ -29,7 +29,7 @@ final class StubIntegrationTests: XCTestCase { "-var downloadThrowBlock: (() throws -> Void)?", "-var downloadReturn: [String]", "", - "-init(name: String? = nil, color: Int, loadThrowBlock: @escaping (() throws -> Void)? = nil, loadReturn: Int, isFullReturn: Bool, downloadThrowBlock: @escaping (() throws -> Void)? = nil, downloadReturn: [String]) {", + "-init(name: String? = nil, color: Int, loadThrowBlock: (() throws -> Void)? = nil, loadReturn: Int, isFullReturn: Bool, downloadThrowBlock: (() throws -> Void)? = nil, downloadReturn: [String]) {", "--self.name = name", "--self.color = color", "--self.loadThrowBlock = loadThrowBlock",