Refactored the StaticFile enumeration in the Website library target into a structure.

This commit is contained in:
2026-08-24 22:37:13 +02:00
parent d8cf1abf6a
commit 74e81e1517
6 changed files with 153 additions and 155 deletions
@@ -1,82 +0,0 @@
import Infrastructure
import Testing
@testable import WebsiteLibrary
@Suite(
"StaticFile enumeration",
.tags(.enumeration)
)
struct StaticFileTests {
// MARK: Type aliases
typealias File = StaticFile
// MARK: Computed tests
@Test(arguments: zip(
File.allCases,
Self.fileExtensions
))
func `file extensions`(
for file: File,
expects extensions: [AssetExtension]
) {
#expect(file.fileExtensions == extensions)
}
@Test(arguments: zip(
File.allCases,
Self.fileNames
))
func `file name`(
for file: File,
expects fileName: String
) {
#expect(file.fileName == fileName)
}
// MARK: CaseIterable tests
@Test
func `all cases`() {
#expect(File.allCases.count == 11)
}
}
// MARK: - Helpers
private extension StaticFileTests {
// MARK: Constants
static let fileExtensions: [[AssetExtension]] = [
[.png],
[.ico],
[.svg],
[.png],
[.png],
[.css, .js],
[.css, .js],
[.txt],
[.css, .js],
[.webmanifest],
[.xml]
]
static let fileNames: [String] = [
"apple-touch-icon",
"favicon",
"icon",
"icon-192",
"icon-512",
"index",
"not-found",
"robots",
"shared",
"site",
"sitemap"
]
}
@@ -0,0 +1,57 @@
import Infrastructure
import Testing
@testable import WebsiteLibrary
@Suite(
"StaticFile type",
.tags(.type)
)
struct StaticFileTests {
// MARK: Type aliases
typealias File = StaticFile
// MARK: Computed tests
/// The path is asserted rather than the three facts behind it: it is the only form the rest of the service sees.
@Test(arguments: Self.paths)
func `relative paths`(
for file: File,
expects paths: [String]
) {
#expect(file.fileExtensions.map(file.relativePath) == paths)
}
// MARK: Constants tests
@Test
func `all files`() {
#expect(File.all.count == Self.paths.count)
}
}
// MARK: - Helpers
private extension StaticFileTests {
// MARK: Constants
/// Every file paired with the path it is served at, one per extension, in ``StaticFile/all`` order.
static let paths: [(File, [String])] = [
(.appleTouchIcon, ["apple-touch-icon.png"]),
(.favicon, ["favicon.ico"]),
(.icon, ["icon.svg"]),
(.icon192, ["icon-192.png"]),
(.icon512, ["icon-512.png"]),
(.index, ["css/index.css", "js/index.js"]),
(.notFound, ["css/not-found.css", "js/not-found.js"]),
(.robots, ["robots.txt"]),
(.shared, ["css/shared.css", "js/shared.js"]),
(.site, ["site.webmanifest"]),
(.sitemap, ["sitemap.xml"]),
]
}