Implemented the Resource model in the library target.

This commit is contained in:
2025-09-29 18:18:20 +02:00
parent 27d1d3b59f
commit 480cd657c9
4 changed files with 206 additions and 0 deletions
@@ -0,0 +1,147 @@
// ===----------------------------------------------------------------------===
//
// 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 HummingbirdDocC.Resource
@Suite("Resource", .tags(.model))
struct ResourceTests {
// MARK: Properties tests
#if swift(>=6.2)
@Test
func `archive path`() {
assertArchivePath(
archiveName: "SomeDocument",
expects: "/SomeDocument.doccarchive"
)
}
@Test
func `archive reference`() {
assertArchiveReference(
archiveName: "SomeDocument",
expects: "somedocument"
)
}
@Test
func `full path`() {
assertFullPath()(
archiveName: "SomeDocument",
relativePath: .uriResource,
expects: "/somedocument" + .uriResource
)
}
#else
@Test("archive path")
func archivePath() {
assertArchivePath(
archiveName: "SomeDocument",
expects: "/SomeDocument.doccarchive"
)
}
@Test("archive reference")
func archiveReference() {
assertArchiveReference(
archiveName: "SomeDocument",
expects: "somedocument"
)
}
@Test("full path")
func fullPath() {
assertFullPath()(
archiveName: "SomeDocument",
relativePath: .uriResource,
expects: "/somedocument" + .uriResource
)
}
#endif
}
// MARK: - Assertions
private extension ResourceTests {
// MARK: Functions
/// Asserts the `archivePath` computed property of a resource.
/// - Parameters:
/// - archiveName: A name of the archive the resource belongs to.
/// - archivePath: An expected path to a documentation archive related to a given archive name.
func assertArchivePath(
archiveName: String,
expects archivePath: String
) {
// GIVEN
let resource = Resource(
archiveName: archiveName,
relativePath: .empty
)
// WHEN
let result = resource.archivePath
// THEN
#expect(result == archivePath)
}
/// Asserts the `archiveReference` computed property of a resource.
/// - Parameters:
/// - archiveName: A name of the archive the resource belongs to.
/// - archiveReference: An expected reference related to a given archive name.
func assertArchiveReference(
archiveName: String,
expects archiveReference: String
) {
// GIVEN
let resource = Resource(
archiveName: archiveName,
relativePath: .empty
)
// WHEN
let result = resource.archiveReference
// THEN
#expect(result == archiveReference)
}
/// Asserts the `fullPath` computed property of a resource.
/// - Parameters:
/// - archiveName: A name of the archive the resource belongs to.
/// - relativePath: A relative URI path to a resource.
/// - fullPath: An expected relative URI path to a resource in its documentation archive.
func assertFullPath(
archiveName: String,
relativePath: String,
expects fullPath: String
) {
// GIVEN
let resource = Resource(
archiveName: archiveName,
relativePath: relativePath
)
// WHEN
let result = resource.fullPath
// THEN
#expect(result == fullPath)
}
}
@@ -22,6 +22,8 @@ extension Tag {
@Tag static var `extension`: Self
/// Tag that indicate a test case for a middleware type.
@Tag static var middleware: Self
/// Tag that indicate a test case for a model type.
@Tag static var model: Self
/// Tag that indicate a test case for a use case type.
@Tag static var useCase: Self