From 790433f1a78128ab972fa4c35267f3f9c15c8727 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Tue, 30 Sep 2025 15:30:28 +0200 Subject: [PATCH] Removed the unnecessary "fullPath" computed property from the Resource model in the library target. --- .../Internal/Extensions/String+Formats.swift | 2 - .../Internal/Extensions/String+Helpers.swift | 2 +- .../Internal/Models/Resource.swift | 15 ++---- .../Tests/Internal/Models/ResourceTests.swift | 47 ++----------------- 4 files changed, 9 insertions(+), 57 deletions(-) diff --git a/Sources/HummingbirdDocC/Internal/Extensions/String+Formats.swift b/Sources/HummingbirdDocC/Internal/Extensions/String+Formats.swift index 8c7dd24..d425b2b 100644 --- a/Sources/HummingbirdDocC/Internal/Extensions/String+Formats.swift +++ b/Sources/HummingbirdDocC/Internal/Extensions/String+Formats.swift @@ -31,8 +31,6 @@ extension String { static let forwardSlash = "%@/" /// A format pattern used to generate relative paths for index files. static let index = "%@/%@/index.html" - /// A format pattern used to generate relative paths for resources. - static let resource = "/%@/%@" /// A format pattern used to generate relative paths that starts with the `/` string. static let root = "/%@" } diff --git a/Sources/HummingbirdDocC/Internal/Extensions/String+Helpers.swift b/Sources/HummingbirdDocC/Internal/Extensions/String+Helpers.swift index acd84cf..8dfc996 100644 --- a/Sources/HummingbirdDocC/Internal/Extensions/String+Helpers.swift +++ b/Sources/HummingbirdDocC/Internal/Extensions/String+Helpers.swift @@ -37,7 +37,7 @@ extension String { return nil } - return matches.output.1 + return matches.output.1 ?? .empty } } diff --git a/Sources/HummingbirdDocC/Internal/Models/Resource.swift b/Sources/HummingbirdDocC/Internal/Models/Resource.swift index ee765e5..db07960 100644 --- a/Sources/HummingbirdDocC/Internal/Models/Resource.swift +++ b/Sources/HummingbirdDocC/Internal/Models/Resource.swift @@ -11,7 +11,7 @@ // ===----------------------------------------------------------------------=== /// A model that encapsulates the information related to a resource in a given `DocC` documentation archive. -struct Resource { +struct Resource: Equatable { // MARK: Properties @@ -38,18 +38,13 @@ struct Resource { // MARK: Computed /// A relative URI path to a documentation archive the resource belongs to. - lazy var archivePath: String = { + var archivePath: String { .init(format: .Format.Path.archive, archiveName) - }() + } /// A reference name for the documentation archive the resource belongs to. - lazy var archiveReference: String = { + var archiveReference: String { archiveName.lowercased() - }() - - /// A relative URI path to the resource in its documentation archive. - lazy var fullPath: String = { - .init(format: .Format.Path.archive, archiveName, relativePath) - }() + } } diff --git a/Tests/HummingbirdDocC/Tests/Internal/Models/ResourceTests.swift b/Tests/HummingbirdDocC/Tests/Internal/Models/ResourceTests.swift index 1a96374..a0da9e1 100644 --- a/Tests/HummingbirdDocC/Tests/Internal/Models/ResourceTests.swift +++ b/Tests/HummingbirdDocC/Tests/Internal/Models/ResourceTests.swift @@ -12,7 +12,7 @@ import Testing -@testable import HummingbirdDocC.Resource +@testable import struct HummingbirdDocC.Resource @Suite("Resource", .tags(.model)) struct ResourceTests { @@ -35,15 +35,6 @@ struct ResourceTests { expects: "somedocument" ) } - - @Test - func `full path`() { - assertFullPath()( - archiveName: "SomeDocument", - relativePath: .uriResource, - expects: "/somedocument" + .uriResource - ) - } #else @Test("archive path") func archivePath() { @@ -60,15 +51,6 @@ struct ResourceTests { expects: "somedocument" ) } - - @Test("full path") - func fullPath() { - assertFullPath()( - archiveName: "SomeDocument", - relativePath: .uriResource, - expects: "/somedocument" + .uriResource - ) - } #endif } @@ -88,7 +70,7 @@ private extension ResourceTests { expects archivePath: String ) { // GIVEN - let resource = Resource( + var resource = Resource( archiveName: archiveName, relativePath: .empty ) @@ -109,7 +91,7 @@ private extension ResourceTests { expects archiveReference: String ) { // GIVEN - let resource = Resource( + var resource = Resource( archiveName: archiveName, relativePath: .empty ) @@ -120,28 +102,5 @@ private extension ResourceTests { // 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) - } }