142 lines
2.8 KiB
Swift
142 lines
2.8 KiB
Swift
import Foundation
|
|||
|
|
import Testing
|
||
|
|
|
||
|
|
@testable import WebsiteCore
|
||
|
|
|
||
|
|
@Suite("StaticFile enumeration")
|
||
|
|
struct StaticFileTests {
|
||
|
|
|
||
|
|
// MARK: Type aliases
|
||
|
|
|
||
|
|
typealias File = StaticFile
|
||
|
|
typealias FileExtension = StaticFile.Extension
|
||
|
|
|
||
|
|
// MARK: Computed tests
|
||
|
|
|
||
|
|
@Test(arguments: zip(
|
||
|
|
File.allCases,
|
||
|
|
Self.contentTypes
|
||
|
|
))
|
||
|
|
func `content type`(
|
||
|
|
for file: File,
|
||
|
|
expects contentType: String
|
||
|
|
) {
|
||
|
|
#expect(file.contentType == contentType)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test(arguments: zip(
|
||
|
|
File.allCases,
|
||
|
|
Self.fileExtensions
|
||
|
|
))
|
||
|
|
func `file extension`(
|
||
|
|
for file: File,
|
||
|
|
expects `extension`: FileExtension
|
||
|
|
) {
|
||
|
|
#expect(file.fileExtension == `extension`)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test(arguments: zip(
|
||
|
|
File.allCases,
|
||
|
|
Self.fileNames
|
||
|
|
))
|
||
|
|
func `file name`(
|
||
|
|
for file: File,
|
||
|
|
expects fileName: String
|
||
|
|
) {
|
||
|
|
#expect(file.fileName == fileName)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test(arguments: zip(
|
||
|
|
File.allCases,
|
||
|
|
Self.relativePaths
|
||
|
|
))
|
||
|
|
func `relative path`(
|
||
|
|
for file: File,
|
||
|
|
expects relativePath: String
|
||
|
|
) {
|
||
|
|
#expect(file.relativePath == relativePath)
|
||
|
|
}
|
||
|
|
|
||
|
|
// MARK: Method tests
|
||
|
|
|
||
|
|
@Test(arguments: [
|
||
|
|
"",
|
||
|
|
".",
|
||
|
|
"Resources/Static"
|
||
|
|
])
|
||
|
|
func `path relative to`(
|
||
|
|
_ basePath: String
|
||
|
|
) {
|
||
|
|
for file in File.allCases {
|
||
|
|
let pathRelativeToBasePath = file.path(relativeTo: basePath)
|
||
|
|
|
||
|
|
if basePath.isEmpty {
|
||
|
|
#expect(pathRelativeToBasePath == file.relativePath)
|
||
|
|
} else {
|
||
|
|
#expect(pathRelativeToBasePath == "\(basePath)/\(file.relativePath)")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// MARK: CaseIterable tests
|
||
|
|
|
||
|
|
@Test
|
||
|
|
func `all cases`() {
|
||
|
|
#expect(File.allCases.count == 9)
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// MARK: - Helpers
|
||
|
|
|
||
|
|
private extension StaticFileTests {
|
||
|
|
|
||
|
|
// MARK: Constants
|
||
|
|
|
||
|
|
static let contentTypes: [String] = [
|
||
|
|
"text/javascript",
|
||
|
|
"text/html",
|
||
|
|
"image/vnd.microsoft.icon",
|
||
|
|
"image/png",
|
||
|
|
"image/svg+xml",
|
||
|
|
"text/html",
|
||
|
|
"text/plain",
|
||
|
|
"application/manifest+json",
|
||
|
|
"text/css"
|
||
|
|
]
|
||
|
|
static let fileExtensions: [FileExtension] = [
|
||
|
|
.js,
|
||
|
|
.html,
|
||
|
|
.ico,
|
||
|
|
.png,
|
||
|
|
.svg,
|
||
|
|
.html,
|
||
|
|
.txt,
|
||
|
|
.webmanifest,
|
||
|
|
.css
|
||
|
|
]
|
||
|
|
static let fileNames: [String] = [
|
||
|
|
"app",
|
||
|
|
"404",
|
||
|
|
"favicon",
|
||
|
|
"icon",
|
||
|
|
"icon",
|
||
|
|
"index",
|
||
|
|
"robots",
|
||
|
|
"site",
|
||
|
|
"style"
|
||
|
|
]
|
||
|
|
static let relativePaths: [String] = [
|
||
|
|
"js/app.js",
|
||
|
|
"404.html",
|
||
|
|
"favicon.ico",
|
||
|
|
"icon.png",
|
||
|
|
"icon.svg",
|
||
|
|
"index.html",
|
||
|
|
"robots.txt",
|
||
|
|
"site.webmanifest",
|
||
|
|
"css/style.css"
|
||
|
|
]
|
||
|
|
|
||
|
|
}
|