Skip to content

Commit 8dbfc2e

Browse files
committed
migrate SemanticVersionTests
1 parent 2bb009b commit 8dbfc2e

File tree

5 files changed

+176
-150
lines changed

5 files changed

+176
-150
lines changed

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,9 @@ let package:Package = .init(
636636
.target(name: "S3Client"),
637637
]),
638638

639-
.executableTarget(name: "SemanticVersionTests",
639+
.testTarget(name: "SemanticVersionTests",
640640
dependencies: [
641641
.target(name: "SemanticVersions"),
642-
.target(name: "Testing_"),
643642
]),
644643

645644
.testTarget(name: "SymbolGraphValidationTests",

Sources/SemanticVersionTests/Main.swift

Lines changed: 0 additions & 148 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import SemanticVersions
2+
import Testing
3+
4+
@Suite
5+
enum NumericVersions
6+
{
7+
@Test
8+
static func ValidMajor()
9+
{
10+
#expect(NumericVersion.init("1") == .major(.v(1)))
11+
}
12+
@Test
13+
static func ValidMinor()
14+
{
15+
#expect(NumericVersion.init("1.2") == .minor(.v(1, 2)))
16+
}
17+
@Test
18+
static func ValidPatch()
19+
{
20+
#expect(NumericVersion.init("1.2.3") == .patch(.v(1, 2, 3)))
21+
}
22+
@Test
23+
static func InvalidEmpty()
24+
{
25+
#expect(nil == NumericVersion.init(""))
26+
}
27+
@Test
28+
static func InvalidDots()
29+
{
30+
#expect(nil == NumericVersion.init(".."))
31+
}
32+
@Test
33+
static func InvalidNonNumeric()
34+
{
35+
#expect(nil == NumericVersion.init("x.y.z"))
36+
}
37+
@Test
38+
static func InvalidFourComponents()
39+
{
40+
#expect(nil == NumericVersion.init("1.2.3.4"))
41+
}
42+
@Test
43+
static func InvalidLeadingDot()
44+
{
45+
#expect(nil == NumericVersion.init(".1.2.3"))
46+
}
47+
@Test
48+
static func InvalidTrailingDot()
49+
{
50+
#expect(nil == NumericVersion.init("1.2.3."))
51+
}
52+
@Test
53+
static func InvalidOverflow()
54+
{
55+
#expect(nil == NumericVersion.init("0.1.99999"))
56+
}
57+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import SemanticVersions
2+
import Testing
3+
4+
@Suite
5+
enum PatchVersions
6+
{
7+
@Test
8+
static func Valid()
9+
{
10+
#expect(PatchVersion.init("0.1.2") == .v(0, 1, 2))
11+
}
12+
@Test
13+
static func InvalidEmpty()
14+
{
15+
#expect(nil == PatchVersion.init(""))
16+
}
17+
@Test
18+
static func InvalidDots()
19+
{
20+
#expect(nil == PatchVersion.init(".."))
21+
}
22+
@Test
23+
static func InvalidNonNumeric()
24+
{
25+
#expect(nil == PatchVersion.init("x.y.z"))
26+
}
27+
@Test
28+
static func InvalidTwoComponents()
29+
{
30+
#expect(nil == PatchVersion.init("1.2"))
31+
}
32+
@Test
33+
static func InvalidFourComponents()
34+
{
35+
#expect(nil == PatchVersion.init("1.2.3.4"))
36+
}
37+
@Test
38+
static func InvalidLeadingDot()
39+
{
40+
#expect(nil == PatchVersion.init(".1.2.3"))
41+
}
42+
@Test
43+
static func InvalidTrailingDot()
44+
{
45+
#expect(nil == PatchVersion.init("1.2.3."))
46+
}
47+
@Test
48+
static func Overflow()
49+
{
50+
#expect(nil == PatchVersion.init("0.1.99999"))
51+
}
52+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import SemanticVersions
2+
import Testing
3+
4+
@Suite
5+
enum SemanticVersions
6+
{
7+
@Test
8+
static func Release()
9+
{
10+
#expect(SemanticVersion.init("0.1.2") == .release(.v(0, 1, 2)))
11+
}
12+
@Test
13+
static func ReleaseV()
14+
{
15+
#expect(SemanticVersion.init(refname: "v0.1.2") == .release(.v(0, 1, 2)))
16+
}
17+
18+
@Test
19+
static func Prerelease()
20+
{
21+
#expect(SemanticVersion.init(refname: "0.1.2-rc3") == .prerelease(.v(0, 1, 2), "rc3"))
22+
}
23+
@Test
24+
static func PrereleaseV()
25+
{
26+
#expect(SemanticVersion.init(refname: "v0.1.2-rc3") == .prerelease(.v(0, 1, 2), "rc3"))
27+
}
28+
@Test
29+
static func PrereleaseDashes()
30+
{
31+
#expect(SemanticVersion.init(refname: "600.0.0-prerelease-2024-04-25") ==
32+
.prerelease(.v(600, 0, 0), "prerelease-2024-04-25"))
33+
}
34+
35+
@Test
36+
static func Build()
37+
{
38+
#expect(SemanticVersion.init(refname: "0.1.2+build3") ==
39+
.release(.v(0, 1, 2), build: "build3"))
40+
}
41+
@Test
42+
static func BuildV()
43+
{
44+
#expect(SemanticVersion.init(refname: "v0.1.2+build3") ==
45+
.release(.v(0, 1, 2), build: "build3"))
46+
}
47+
@Test
48+
static func BuildDashes()
49+
{
50+
#expect(SemanticVersion.init(refname: "v0.1.2+build-3") ==
51+
.release(.v(0, 1, 2), build: "build-3"))
52+
}
53+
54+
@Test
55+
static func PrereleaseBuild()
56+
{
57+
#expect(SemanticVersion.init(refname: "0.1.2-rc3+build3") ==
58+
.prerelease(.v(0, 1, 2), "rc3", build: "build3"))
59+
}
60+
@Test
61+
static func PrereleaseBuildV()
62+
{
63+
#expect(SemanticVersion.init(refname: "v0.1.2-rc3+build3") ==
64+
.prerelease(.v(0, 1, 2), "rc3", build: "build3"))
65+
}
66+
}

0 commit comments

Comments
 (0)