Defined the AssetFile enumeration type in. the library target and also, conformed it to the Pathable protocol.

This commit is contained in:
2025-09-22 20:41:59 +02:00
parent f78e70e823
commit 9b908515d9
4 changed files with 118 additions and 1 deletions
@@ -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)
}
}
}
@@ -15,7 +15,7 @@ protocol Pathable {
// MARK: Properties
/// A (relative) path.
/// A (relative) path to a resource.
var path: String { get }
}
@@ -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"]
}
@@ -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.