Skip to content

Commit

Permalink
Merge pull request #72 from raptorxcz/bugfix/enum
Browse files Browse the repository at this point in the history
Fix enum configuration
  • Loading branch information
raptorxcz authored Jun 24, 2024
2 parents 35f5efc + 67e43e8 commit 15fa080
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
17 changes: 1 addition & 16 deletions Sources/Rubicon/Generator/EnumStubGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ final class EnumStubGeneratorImpl: EnumStubGenerator {
private let extensionGenerator: ExtensionGenerator
private let functionGenerator: FunctionGenerator
private let indentationGenerator: IndentationGenerator
private let defaultValueGenerator: DefaultValueGenerator

init(
extensionGenerator: ExtensionGenerator,
functionGenerator: FunctionGenerator,
indentationGenerator: IndentationGenerator,
defaultValueGenerator: DefaultValueGenerator
indentationGenerator: IndentationGenerator
) {
self.extensionGenerator = extensionGenerator
self.functionGenerator = functionGenerator
self.indentationGenerator = indentationGenerator
self.defaultValueGenerator = defaultValueGenerator
}

func generate(from enumType: EnumDeclaration, functionName: String) -> String {
Expand Down Expand Up @@ -51,16 +48,4 @@ final class EnumStubGeneratorImpl: EnumStubGenerator {
"return \(firstCase)"
]
}

private func makeAssigment(of variable: VarDeclaration, isLast: Bool) -> String {
return "\(variable.identifier): \(variable.identifier)\(isLast ? "" : ",")"
}

private func makeArgument(from varDeclaration: VarDeclaration) -> ArgumentDeclaration {
ArgumentDeclaration(
name: varDeclaration.identifier,
type: varDeclaration.type,
defaultValue: defaultValueGenerator.makeDefaultValue(for: varDeclaration)
)
}
}
24 changes: 18 additions & 6 deletions Sources/Rubicon/Integration/Rubicon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ public struct StructStubConfiguration {
}
}

public struct EnumStubConfiguration {
public let accessLevel: AccessLevel
public let indentStep: String
public let functionName: String

public init(
accessLevel: AccessLevel,
indentStep: String,
functionName: String
) {
self.accessLevel = accessLevel
self.indentStep = indentStep
self.functionName = functionName
}
}

public final class Rubicon {
public init() {}

Expand Down Expand Up @@ -284,7 +300,7 @@ public final class Rubicon {
return EnumParserImpl()
}

public func makeEnumGenerator(for configuration: StructStubConfiguration) -> EnumStubGenerator {
public func makeEnumGenerator(for configuration: EnumStubConfiguration) -> EnumStubGenerator {
let dependencies = makeDependencies(
for: configuration.accessLevel,
indentStep: configuration.indentStep
Expand All @@ -300,11 +316,7 @@ public final class Rubicon {
argumentGenerator: dependencies.argumentGenerator,
indentationGenerator: dependencies.indentationGenerator
),
indentationGenerator: dependencies.indentationGenerator,
defaultValueGenerator: DefaultValueGeneratorImpl(
unknownDefaultType: configuration.defaultValue,
customDefaultTypes: configuration.customDefaultValues
)
indentationGenerator: dependencies.indentationGenerator
)
}
}
5 changes: 1 addition & 4 deletions Tests/RubiconTests/Generator/EnumStubGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ final class EnumStubGeneratorTests: XCTestCase {
private var extensionGeneratorSpy: ExtensionGeneratorSpy!
private var functionGeneratorSpy: FunctionGeneratorSpy!
private var indentationGeneratorStub: IndentationGeneratorStub!
private var defaultValueGeneratorSpy: DefaultValueGeneratorSpy!
private var sut: EnumStubGeneratorImpl!

override func setUp() {
super.setUp()
extensionGeneratorSpy = ExtensionGeneratorSpy(makeReturn: ["extension"])
functionGeneratorSpy = FunctionGeneratorSpy(makeCodeReturn: ["function"])
indentationGeneratorStub = IndentationGeneratorStub()
defaultValueGeneratorSpy = DefaultValueGeneratorSpy(makeDefaultValueReturn: "default")
sut = EnumStubGeneratorImpl(
extensionGenerator: extensionGeneratorSpy,
functionGenerator: functionGeneratorSpy,
indentationGenerator: IndentationGeneratorStub(),
defaultValueGenerator: defaultValueGeneratorSpy
indentationGenerator: IndentationGeneratorStub()
)
}

Expand Down

0 comments on commit 15fa080

Please sign in to comment.