Initial commit.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import Testing
|
||||
|
||||
@testable import Infrastructure
|
||||
|
||||
@Suite(
|
||||
"Asset protocol",
|
||||
.tags(.`protocol`)
|
||||
)
|
||||
struct AssetTests {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let image = StubAsset(
|
||||
fileExtensions: [.png],
|
||||
fileName: "icon"
|
||||
)
|
||||
private let portrait = StubAsset(
|
||||
folder: "img/organizer",
|
||||
fileExtensions: [.jpg],
|
||||
fileName: "portrait"
|
||||
)
|
||||
private let shared = StubAsset(
|
||||
fileExtensions: [.css, .js],
|
||||
fileName: "shared"
|
||||
)
|
||||
|
||||
// MARK: Method tests
|
||||
|
||||
@Test
|
||||
func `relative path nests the file inside its extension's folder`() {
|
||||
#expect(shared.relativePath(for: .css) == "css/shared.css")
|
||||
#expect(shared.relativePath(for: .js) == "js/shared.js")
|
||||
}
|
||||
|
||||
@Test
|
||||
func `relative path prefers the asset's own folder over the extension's`() {
|
||||
#expect(portrait.relativePath(for: .jpg) == "img/organizer/portrait.jpg")
|
||||
}
|
||||
|
||||
@Test
|
||||
func `relative path keeps the file at the root without a folder`() {
|
||||
#expect(image.relativePath(for: .png) == "icon.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
func `url path prefixes the relative path with a slash`() {
|
||||
#expect(shared.urlPath(for: .css) == "/css/shared.css")
|
||||
#expect(image.urlPath(for: .png) == "/icon.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
func `url path appends a version token as a query parameter`() {
|
||||
#expect(shared.urlPath(
|
||||
for: .css,
|
||||
version: "0123456789abcdef"
|
||||
) == "/css/shared.css?v=0123456789abcdef")
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, ""] as [String?])
|
||||
func `url path without a version`(
|
||||
version: String?
|
||||
) {
|
||||
#expect(shared.urlPath(
|
||||
for: .css,
|
||||
version: version
|
||||
) == "/css/shared.css")
|
||||
}
|
||||
|
||||
@Test(arguments: [
|
||||
"",
|
||||
".",
|
||||
"Resources/Static"
|
||||
])
|
||||
func `path relative to`(
|
||||
_ basePath: String
|
||||
) {
|
||||
for fileExtension in shared.fileExtensions {
|
||||
let pathRelativeToBasePath = shared.path(
|
||||
relativeTo: basePath,
|
||||
for: fileExtension
|
||||
)
|
||||
let relativePath = shared.relativePath(for: fileExtension)
|
||||
|
||||
if basePath.isEmpty {
|
||||
#expect(pathRelativeToBasePath == relativePath)
|
||||
} else {
|
||||
#expect(pathRelativeToBasePath == "\(basePath)/\(relativePath)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user