Template support for input parameters #4

Merged
javier merged 81 commits from feature/arguments-templating into main 2025-02-17 22:11:06 +00:00
2 changed files with 45 additions and 8 deletions
Showing only changes of commit 2852f4b1bf - Show all commits

View File

@ -24,7 +24,7 @@ struct FileServiceTests {
#expect(folder.isFileURL == true)
}
// MARK: Functions
// MARK: Functions tests
@Test(arguments: [URL.someNewFolder, .someNewFile])
func createFolder(with url: URL) async throws {

View File

@ -1,13 +1,14 @@
import ColibriLibrary
import Foundation
struct FileServiceMock {
final class FileServiceMock {
// MARK: Properties
private let action: Action?
private let folder: URL
private var actions: [Action] = []
private weak var spy: FileServiceSpy?
// MARK: Initialisers
@ -17,7 +18,21 @@ struct FileServiceMock {
action: Action? = nil,
spy: FileServiceSpy? = nil
) {
self.action = action
self.actions = if let action {
[action]
} else {
[]
}
self.folder = currentFolder
self.spy = spy
}
init(
currentFolder: URL,
actions: [Action],
spy: FileServiceSpy? = nil
) {
self.actions = actions
self.folder = currentFolder
self.spy = spy
}
@ -37,7 +52,9 @@ extension FileServiceMock: FileServicing {
// MARK: Functions
func createFolder(at url: URL) async throws(FileServiceError) {
switch action {
guard let nextAction else { return }
switch nextAction {
case .error(let error):
throw error
case let .createFolder(url):
@ -48,7 +65,9 @@ extension FileServiceMock: FileServicing {
}
func delete(at url: URL) async throws(FileServiceError) {
switch action {
guard let nextAction else { return }
switch nextAction {
case .error(let error):
throw error
case let .delete(url):
@ -59,7 +78,9 @@ extension FileServiceMock: FileServicing {
}
func exists(at url: URL) async throws(FileServiceError) -> Bool {
switch action {
guard let nextAction else { return false }
switch nextAction {
case .error(let error):
throw error
case let .exists(url, exists):
@ -72,7 +93,23 @@ extension FileServiceMock: FileServicing {
}
// MARK: - Enumerations
// MARK: - Helpers
private extension FileServiceMock {
// MARK: Computed
var nextAction: Action? {
guard !actions.isEmpty else {
return nil
}
return actions.removeFirst()
}
}
// MARK: - Actions
extension FileServiceMock {
enum Action {