From 720ad687fbc4a4205cb6fa5a470bd153b97ea606 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sat, 18 Jan 2025 11:38:01 +0100 Subject: [PATCH] Implemented the "path" property for the Folder enumeration in the library target. --- .../Internal/Enumerations/Folder.swift | 33 ++++++++++++++---- .../Public/Tasks/CreateFoldersTask.swift | 2 +- .../Internal/Enumerations/FolderTests.swift | 34 +++++++++++++++++++ .../Public/Tasks/CreateFoldersTaskTests.swift | 2 +- 4 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 Test/Sources/Cases/Internal/Enumerations/FolderTests.swift diff --git a/Library/Sources/Internal/Enumerations/Folder.swift b/Library/Sources/Internal/Enumerations/Folder.swift index ce66129..fc9c448 100644 --- a/Library/Sources/Internal/Enumerations/Folder.swift +++ b/Library/Sources/Internal/Enumerations/Folder.swift @@ -1,10 +1,29 @@ -enum Folder: String { - case app = "App/Sources" - case libraryPublic = "Library/Sources/Public" - case libraryInternal = "Library/Sources/Internal" - case testCasesPublic = "Test/Sources/Cases/Public" - case testCasesInternal = "Test/Sources/Cases/Internal" - case testHelpers = "Test/Sources/Helpers" +enum Folder { + case app + case libraryPublic + case libraryInternal + case testCasesPublic + case testCasesInternal + case testHelpers +} + +// MARK: - Properties + +extension Folder { + + // MARK: Computed + + var path: String { + switch self { + case .app: "App/Sources" + case .libraryPublic: "Library/Sources/Public" + case .libraryInternal: "Library/Sources/Internal" + case .testCasesPublic: "Test/Sources/Cases/Public" + case .testCasesInternal: "Test/Sources/Cases/Internal" + case .testHelpers: "Test/Sources/Helpers" + } + } + } // MARK: - CaseIterable diff --git a/Library/Sources/Public/Tasks/CreateFoldersTask.swift b/Library/Sources/Public/Tasks/CreateFoldersTask.swift index 3895fe6..2a39327 100644 --- a/Library/Sources/Public/Tasks/CreateFoldersTask.swift +++ b/Library/Sources/Public/Tasks/CreateFoldersTask.swift @@ -15,7 +15,7 @@ public struct CreateFoldersTask { // MARK: Functions public func callAsFunction(at rootFolder: URL) async throws { - let folders = Folder.allCases.map { rootFolder.appendingPath($0.rawValue) } + let folders = Folder.allCases.map { rootFolder.appendingPath($0.path) } for folder in folders { try await fileService.createFolder(at: folder) diff --git a/Test/Sources/Cases/Internal/Enumerations/FolderTests.swift b/Test/Sources/Cases/Internal/Enumerations/FolderTests.swift new file mode 100644 index 0000000..31196f5 --- /dev/null +++ b/Test/Sources/Cases/Internal/Enumerations/FolderTests.swift @@ -0,0 +1,34 @@ +import Testing + +@testable import ColibriLibrary + +struct FolderTests { + + // MARK: Properties tests + + @Test(arguments: zip(Folder.allCases, Expectation.paths)) + func paths(for folder: Folder, expects path: String) async throws { + // GIVEN + // WHEN + let result = folder.path + + // THEN + #expect(result == path) + } + +} + +// MARK: - Expectations + +private extension FolderTests { + enum Expectation { + static let paths: [String] = [ + "App/Sources", + "Library/Sources/Public", + "Library/Sources/Internal", + "Test/Sources/Cases/Public", + "Test/Sources/Cases/Internal", + "Test/Sources/Helpers" + ] + } +} diff --git a/Test/Sources/Cases/Public/Tasks/CreateFoldersTaskTests.swift b/Test/Sources/Cases/Public/Tasks/CreateFoldersTaskTests.swift index ddbfa29..af361a4 100644 --- a/Test/Sources/Cases/Public/Tasks/CreateFoldersTaskTests.swift +++ b/Test/Sources/Cases/Public/Tasks/CreateFoldersTaskTests.swift @@ -14,7 +14,7 @@ struct CreateFoldersTaskTests { @Test(arguments: [URL.someCurrentFolder, .someDotFolder, .someTildeFolder]) func createFolders(with rootFolder: URL) async throws { // GIVEN - let folders = Folder.allCases.map { rootFolder.appendingPath($0.rawValue) } + let folders = Folder.allCases.map { rootFolder.appendingPath($0.path) } let actions = folders.map { FileServiceMock.Action.createFolder($0) } let createFolders = task(actions: actions)