Skip to content

Commit

Permalink
Move some stuff to cleanup AutoStubbable.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmya committed Aug 1, 2023
1 parent c55a6b6 commit d77a2eb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
14 changes: 1 addition & 13 deletions Sources/Templates/AutoStubbable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Type {
return lines
}
lines.append(contentsOf: initMethodLines.joined(separator: [.emptyLine]))

if initMethods.isEmpty {
lines.append("static func \(stubMethodName(index: 0, count: 1))(".addingIndent())
let availableVariables = storedVariables.filter { !$0.hasDefaultValue }
Expand All @@ -67,18 +67,6 @@ extension Type {
}

// TODO: Move and improve this stuff
extension Type {
var initMethods: [Method] {
methods.filter { ($0.isInitializer || $0.isFailableInitializer) && !$0.isConvenienceInitializer }
}
}

extension Variable {
var hasDefaultValue: Bool {
defaultValue != nil
}
}

func stubMethodName(index: Int, count: Int) -> String {
count > 1 ? "stub\(index)" : "stub"
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/Templates/Extensions/Type+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SourceryRuntime

extension Type {
var initMethods: [Method] {
methods.filter { ($0.isInitializer || $0.isFailableInitializer) && !$0.isConvenienceInitializer }
}
}
4 changes: 4 additions & 0 deletions Sources/Templates/Extensions/Variable+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import SourceryRuntime

extension Variable {
var hasDefaultValue: Bool {
defaultValue != nil
}

func generateMock() -> String {
isMutable ? generateMutableMock() : generateComputedMock()
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Templates/Imports.swifttemplate
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<%- includeFile("Extensions/MethodParameter+Extension.swift") -%>
<%- includeFile("Extensions/Protocol+Extension.swift") -%>
<%- includeFile("Extensions/String+Extension.swift") -%>
<%- includeFile("Extensions/Type+Extension.swift") -%>
<%- includeFile("Extensions/TypeName+Extension.swift") -%>
<%- includeFile("Extensions/Variable+Extension.swift") -%>

0 comments on commit d77a2eb

Please sign in to comment.