diff --git a/Sources/DocCMiddleware/Internal/Enumerations/AssetFile.swift b/Sources/DocCMiddleware/Internal/Enumerations/AssetFile.swift new file mode 100644 index 0000000..89de2c7 --- /dev/null +++ b/Sources/DocCMiddleware/Internal/Enumerations/AssetFile.swift @@ -0,0 +1,38 @@ +// ===----------------------------------------------------------------------=== +// +// This source file is part of the Hummingbird DocC Middleware open source project +// +// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors +// Licensed under the EUPL 1.2 or later. +// +// See LICENSE for license information +// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors +// +// ===----------------------------------------------------------------------=== + +/// An enumeration that represents the essential static files that could be generated by the `DocC` building process. +enum AssetFile: String, CaseIterable { + /// A file defining all the documentation available, which will be used to redirect to the root of the documentation's root article. + case documentation = "documentation.json" + /// A file containing the icon in `.ico` format within the documentation generated by the `DocC` building process. + case faviconICO = "favicon.ico" + /// A file containing the icon in `.svg` format within the documentation generated by the `DocC` building process. + case faviconSVG = "favicon.svg" + /// A file containing the theme settings within the documentation generated by the `DocC` building process. + case themeSettings = "theme-settings.json" +} + +// MARK: - Pathable + +extension AssetFile: Pathable { + + // MARK: Computed + + var path: String { + switch self { + case .documentation: .init(format: .Format.Path.data, rawValue) + default: .init(format: .Format.Path.root, rawValue) + } + } + +} diff --git a/Sources/DocCMiddleware/Internal/Protocols/Pathable.swift b/Sources/DocCMiddleware/Internal/Protocols/Pathable.swift index 5cb5014..2d0f7a4 100644 --- a/Sources/DocCMiddleware/Internal/Protocols/Pathable.swift +++ b/Sources/DocCMiddleware/Internal/Protocols/Pathable.swift @@ -15,7 +15,7 @@ protocol Pathable { // MARK: Properties - /// A (relative) path. + /// A (relative) path to a resource. var path: String { get } } diff --git a/Tests/DocCMiddleware/Tests/Internal/Enumerations/AssetFileTests.swift b/Tests/DocCMiddleware/Tests/Internal/Enumerations/AssetFileTests.swift new file mode 100644 index 0000000..6ad465f --- /dev/null +++ b/Tests/DocCMiddleware/Tests/Internal/Enumerations/AssetFileTests.swift @@ -0,0 +1,77 @@ +// ===----------------------------------------------------------------------=== +// +// This source file is part of the Hummingbird DocC Middleware open source project +// +// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors +// Licensed under the EUPL 1.2 or later. +// +// See LICENSE for license information +// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors +// +// ===----------------------------------------------------------------------=== + +import Testing + +@testable import enum DocCMiddleware.AssetFile + +@Suite("Asset File", .tags(.enumeration)) +struct AssetFileTests { + + // MARK: Properties tests + +#if swift(>=6.2) + @Test(arguments: zip( + AssetFile.allCases, + Output.assetFilePaths + )) + func `path`( + `case`: AssetFile, + expects result: String + ) { + assertPath(`case`, expects: result) + } +#else + @Test("path", arguments: zip( + AssetFile.allCases, + Output.assetFilePaths + )) + func path( + `case`: AssetFile, + expects result: String + ) { + assertPath(`case`, expects: result) + } +#endif + +} + +// MARK: - Assertions + +private extension AssetFileTests { + + // MARK: Functions + + /// Asserts the path property based on a given ``AssetFile`` enumeration case and an expected result. + /// - Parameters: + /// - case: A representation of the ``AssetFile`` enumeration + /// - result: An expected result coming out of the property. + func assertPath( + _ case: AssetFile, + expects result: String + ) { + // GIVEN + // WHEN + let output = `case`.path + + // THEN + #expect(output == result) + } + +} + +// MARK: - Constants + +extension Output { + /// A list of expected outputs for the paths of the ``AssetFile`` enumeration cases. + static let assetFilePaths: [String] = ["/data/documentation.json", "/favicon.ico", "/favicon.svg", "/theme-settings.json"] +} diff --git a/Tests/DocCMiddleware/Types/Extensions/Tag+Constants.swift b/Tests/DocCMiddleware/Types/Extensions/Tag+Constants.swift index 7c6b32f..34ee316 100644 --- a/Tests/DocCMiddleware/Types/Extensions/Tag+Constants.swift +++ b/Tests/DocCMiddleware/Types/Extensions/Tag+Constants.swift @@ -16,6 +16,8 @@ extension Tag { // MARK: Constants + /// Tag that indicate a test case for an enumeration type. + @Tag static var enumeration: Self /// Tag that indicate a test case for a type initialization. @Tag static var initializer: Self /// Tag that indicate a test case for a use case type.