Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic Version 2.1.0 Update #47

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions Sources/Version/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
A struct representing a “semver” version, that is: a Semantic Version.
- SeeAlso: https://semver.org
*/

public struct Version {
/// The major version.
public let major: Int
Expand Down Expand Up @@ -48,6 +49,18 @@ public struct Version {
print("notice: negative components were abs’d")
}
}

/**
Creates a version object.
- Note: Integers are made absolute since negative integers are not allowed, yet it is conventional Swift to take `Int` over `UInt` where possible.
- Remark: This initializer variant provided when it would be more readable than the nameless variant.
*/
public init(major: Int, minor: Int, patch: Int, prereleaseIdentifiers: [String] = [], buildMetadataIdentifiers: [String] = []) {
self.init(major, minor, patch, pre: prereleaseIdentifiers, build: buildMetadataIdentifiers)
}

/// Represents `0.0.0`
public static let null = Version(0,0,0)
}

extension Version: LosslessStringConvertible {
Expand Down Expand Up @@ -180,6 +193,10 @@ public extension Version {
}
}

#if swift(>=5.5)
extension Version: Sendable {}
#endif

extension Version: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(major)
Expand All @@ -192,13 +209,13 @@ extension Version: Hashable {
extension Version: Equatable {
/// Compares the provided versions *without* comparing any build-metadata
public static func == (lhs: Version, rhs: Version) -> Bool {
lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch && lhs.prereleaseIdentifiers == rhs.prereleaseIdentifiers
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch && lhs.prereleaseIdentifiers == rhs.prereleaseIdentifiers
}
}

extension Version: Comparable {
func isEqualWithoutPrerelease(_ other: Version) -> Bool {
major == other.major && minor == other.minor && patch == other.patch
return major == other.major && minor == other.minor && patch == other.patch
}

/**
Expand Down Expand Up @@ -232,10 +249,10 @@ extension Version: Comparable {
let typedRhsIdentifier: Any = Int(rhsPrereleaseIdentifier) ?? rhsPrereleaseIdentifier

switch (typedLhsIdentifier, typedRhsIdentifier) {
case let (int1 as Int, int2 as Int): return int1 < int2
case let (string1 as String, string2 as String): return string1 < string2
case (is Int, is String): return true // Int prereleases < String prereleases
case (is String, is Int): return false
case let (int1 as Int, int2 as Int): return int1 < int2
case let (string1 as String, string2 as String): return string1 < string2
case (is Int, is String): return true // Int prereleases < String prereleases
case (is String, is Int): return false
default:
fatalError("impossi-op")
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Version/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
https://github.com/mxcl/Version/releases/tag/2.0.1
https://github.com/mxcl/Version/releases/tag/2.1.0
Version+Comparable.swift merged into Version.swift.