import Testing @testable import Infrastructure @Suite("Asset protocol") struct AssetTests { // MARK: Properties private let image = StubAsset( fileExtensions: [.png], fileName: "icon" ) private let shared = StubAsset( fileExtensions: [.css, .js], fileName: "shared" ) // MARK: Method tests @Test func `relative path nests the file inside its extension's sub-directory`() { #expect(shared.relativePath(for: .css) == "css/shared.css") #expect(shared.relativePath(for: .js) == "js/shared.js") } @Test func `relative path keeps the file at the root without a sub-directory`() { #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)") } } } }