Skip to content

Commit

Permalink
Fix stuct stubs name space collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kryštof Matěj committed Oct 18, 2024
1 parent 78ad731 commit 0bf927f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Sources/Rubicon/Generator/StructStubGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class StructStubGeneratorImpl: StructStubGenerator {
isThrowing: false,
isAsync: false,
isStatic: true,
returnType: TypeDeclaration(name: structType.name, prefix: [], composedType: .plain)
returnType: TypeDeclaration(name: "Self", prefix: [], composedType: .plain)
)
return functionGenerator.makeCode(
from: functionDeclaration,
Expand All @@ -49,11 +49,11 @@ final class StructStubGeneratorImpl: StructStubGenerator {
let variables = structType.variables.enumerated().map{ makeAssigment(of: $1, isLast: $0 == structType.variables.endIndex - 1) }

guard !variables.isEmpty else {
return ["return \(structType.name)()"]
return ["return .init()"]
}

return [
"return \(structType.name)("
"return .init("
] + variables.map(indentationGenerator.indenting) + [
")"
]
Expand Down
6 changes: 3 additions & 3 deletions Tests/RubiconTests/Generator/StructStubGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ final class StructStubGeneratorTests: XCTestCase {
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.isAsync, false)
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.isStatic, true)
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.arguments.count, 0)
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.returnType, .makeStub(name: "StructName"))
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.returnType, .makeStub(name: "Self"))
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.content, [
"return StructName()"
"return .init()"
])
}

Expand All @@ -56,7 +56,7 @@ final class StructStubGeneratorTests: XCTestCase {
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.arguments.first?.type, .makeStub())
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.declaration.arguments.first?.defaultValue, "default")
XCTAssertEqual(functionGeneratorSpy.makeCode.first?.content, [
"return StructName(",
"return .init(",
"-identifier: identifier,",
"-identifier: identifier",
")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ final class StructStubIntegrationTests: XCTestCase {
"--seats: [Seat] = [],",
"--driver: Driver = Carl,",
"--trunk: Trunk = .makeStub()",
"-) -> Car {",
"--return Car(",
"-) -> Self {",
"--return .init(",
"---lenght: lenght,",
"---name: name,",
"---isRed: isRed,",
Expand Down

0 comments on commit 0bf927f

Please sign in to comment.