Skip to content

Commit

Permalink
Janitorial work
Browse files Browse the repository at this point in the history
- Updated README 
    - Noted test-proven SemVer implementation
    - Added examples of subtly-bad semantic versions
    - Added note about `Codable` conformance

- Updated header comments
- Added missing watchOS platform
- Added `SemVerCodableTests` to non-Xcode test files
- Added tests checking subtly-wrong SemVer strings
  • Loading branch information
KyNorthstar committed Oct 25, 2021
1 parent 1526e16 commit ab7a8fe
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let package = Package(
.macOS(.v10_10),
.iOS(.v11),
.tvOS(.v11),
.watchOS(.v4),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# Swift Semantic Versioning #
A small library that implements [SemVer 2.0.0](https://semver.org/spec/v2.0.0.html), which is copyrighted to Tom Preston-Werner CC BY 3.0. This is designed to be simple to use and to easily fit into any Swift codebase.
A small library that perfectly implements [SemVer 2.0.0](https://semver.org/spec/v2.0.0.html), which is copyrighted to Tom Preston-Werner CC BY 3.0. This is designed to be simple to use and to easily fit into any Swift codebase.

This is designed to be as easy as possible to use. You may use the extremely-verbose and explicit initializer which labels every parameter, or the one that does the same thing but excludes the labels, or the one that simply takes any valid SemVer string and gently fails to `nil` if that string is invalid. You are encouraged to use whichever one of these suits the needs at the time of use. Some examples are included in the unit tests.

Keep in mind that the pre-release and build extensions can be easily represented as string- and integer-literals. For instance, `SemVer(1,2,0, SemVer.Build(identifiers: ["123", "4"]))` has the same result as `SemVer(1,2,0, "123.4")` and `SemVer(1,2,0, [123,4])`. Again, this is done for ease-of-use. `SemVer` itself would also be expressible by a string literal, but it has too many resrictions so a failable initializer is presented instead.
Keep in mind that the pre-release and build extensions can be easily represented as string- and integer-literals. For instance, `SemVer(1,2,0, build: SemVer.Build(identifiers: ["123", "4"]))` has the same result as `SemVer(1,2,0, build: "123.4")` and `SemVer(1,2,0, build: [123,4])`. Again, this is done for ease-of-use. `SemVer` itself would also be expressible by a string literal, but it has too many resrictions so a failable initializer conforming to `LosslessStringConvertible` is presented instead, just like `Int`.

This also already conforms to `Comparable`, since comparison and precedence are a major part of the spec.
This also already conforms to `Comparable` since comparison and precedence are a major part of the spec, and to `Codable` since the encoding of semantic versions is clear and simple.


# Examples #

## Proven Strong ##

[`500` test assertions](./Tests/SemVerTests) prove that this library behaves precisely as described, conforming completely to the SemVer 2.0.0 spec.



## Examples ##

Let's say you have a release candidate of version 2.0.0 of your app. The following are all equivalent:

```swift
Expand All @@ -34,21 +42,24 @@ a `nil` object:
nil == SemVer("Obviously Bad")
nil == SemVer("1")
nil == SemVer("1.2")
nil == SemVer("-2.0")
nil == SemVer("-2.0.0")
nil == SemVer("2.0-β")
nil == SemVer("2.0-beta_1")
nil == SemVer("1.-2")
nil == SemVer("1.2.-3")
nil == SemVer("1.2.3.4")
nil == SemVer("1.2.3-😱")
```


# License #

## License ##

This is licensed under [BH-1-PS](https://github.com/BlueHuskyStudios/Licenses/blob/master/Licenses/BH-1-PS.txt).



# Requirements #
## Requirements ##

This package requires:
- Swift 5.1 or newer
Expand Down
1 change: 1 addition & 0 deletions Sources/SemVer/Semantic Version + Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SemVer
//
// Created by Ky Leggiero on 2021-10-18.
// Copyright © 2021 Ben "Ky" Leggiero BH-1-PS.
//

import Foundation
Expand Down
1 change: 1 addition & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ isTesting = true
XCTMain(SemVerTests.allTests
+ SemVerHashableTests.allTests
+ SemVerMutationTests.allTests
+ SemVerCodableTests.allTests
+ SemVerComparableTests.allTests)
10 changes: 9 additions & 1 deletion Tests/SemVerTests/SemVer+Codable Tests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SemVer+Codable Tests.swift
//
// SemVerTests
//
// Created by Ky Leggiero on 2021-10-18.
//
Expand Down Expand Up @@ -89,6 +89,14 @@ class SemVerCodableTests: SemVerTestClass {
XCTAssertEqual(SemVer(01,2,3, preRelease: ["RC","4"], build: [567])!, try encodeDecode(SemVer(01,2,3, preRelease: ["RC","4"], build: [567])!))
XCTAssertEqual(SemVer("1.2.3-RC.4+567")!, try encodeDecode(SemVer("1.2.3-RC.4+567")!))
}



static let allTests = [
("testEncode", testEncode),
("testDecode", testDecode),
("testEncodeDecode", testEncodeDecode),
]
}


Expand Down
2 changes: 1 addition & 1 deletion Tests/SemVerTests/SemVer+Hashable Tests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SemVer+Hashable Tests.swift
// SemVer
// SemVerTests
//
// Created by Ben Leggiero on 2020-04-19.
// Copyright © 2021 Ben Leggiero BH-1-PS.
Expand Down
3 changes: 3 additions & 0 deletions Tests/SemVerTests/SemVerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class SemVerTests: SemVerTestClass {
XCTAssertNil(SemVer("1.2-RC.4+567"))
XCTAssertNil(SemVer("1.2-RC+567.8"))
XCTAssertNil(SemVer("-2.0"))
XCTAssertNil(SemVer("-2.0.0"))
XCTAssertNil(SemVer("2.0-β"))
XCTAssertNil(SemVer("2.0-beta_1"))
XCTAssertNil(SemVer("1.-2"))
XCTAssertNil(SemVer("1.2.-3"))
XCTAssertNil(SemVer("1.2.3.4"))
XCTAssertNil(SemVer("1.2.3-😱"))
XCTAssertNil(SemVer("1.2.3-semántice"))

// Proof of fix of #14: https://github.com/RougeWare/Swift-SemVer/issues/14
XCTAssertNil(SemVer(1,0,0, preRelease: "01"))
Expand Down
1 change: 1 addition & 0 deletions Tests/SemVerTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public func allTests() -> [XCTestCaseEntry] {
testCase(SemVerTests.allTests),
testCase(SemVerHashableTests.allTests),
testCase(SemVerMutationTests.allTests),
testCase(SemVerCodableTests.allTests),
testCase(SemVerComparableTests.allTests),
]
}
Expand Down

0 comments on commit ab7a8fe

Please sign in to comment.