Skip to content

Commit a9d51b1

Browse files
committed
Convert ArrayVersionExtensionTests
1 parent 4fa4a3d commit a9d51b1

File tree

1 file changed

+154
-158
lines changed

1 file changed

+154
-158
lines changed

Tests/AppTests/ArrayVersionExtensionTests.swift

Lines changed: 154 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -12,167 +12,163 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
16-
1715
@testable import App
1816

19-
import SemanticVersion
2017
import SPIManifest
21-
22-
class ArrayVersionExtensionTests: AppTestCase {
23-
24-
func test_Array_canonicalDocumentationTarget() async throws {
25-
let pkg = try await savePackage(on: app.db, "1".url)
26-
let archive = DocArchive(name: "foo", title: "Foo")
27-
28-
do {
29-
// [ Default branch, nil, nil ] = Default branch
30-
let versions = [
31-
try Version(package: pkg,
32-
commit: "123",
33-
commitDate: .t0,
34-
docArchives: [archive],
35-
latest: .defaultBranch,
36-
reference: .branch("main"),
37-
spiManifest: nil),
38-
nil,
39-
nil
40-
]
41-
42-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
43-
.internal(docVersion: .reference("main"), archive: "foo"))
44-
}
45-
46-
do {
47-
// [ Default branch (with docs), nil, Release (no docs) ] = Default branch
48-
let versions = [
49-
try Version(package: pkg,
50-
commit: "123",
51-
commitDate: .t0,
52-
docArchives: [archive],
53-
latest: .defaultBranch,
54-
reference: .branch("main"),
55-
spiManifest: nil),
56-
nil,
57-
try Version(package: pkg,
58-
docArchives: nil,
59-
latest: .release,
60-
reference: .tag(SemanticVersion(1, 2, 3))),
61-
]
62-
63-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
64-
.internal(docVersion: .reference("main"), archive: "foo"))
65-
}
66-
67-
do {
68-
// [ Default branch (with docs), nil, Release (with docs) ] = Release
69-
let versions = [
70-
try Version(package: pkg,
71-
commit: "123",
72-
commitDate: .t0,
73-
docArchives: [archive],
74-
latest: .defaultBranch,
75-
reference: .branch("main"),
76-
spiManifest: nil),
77-
nil,
78-
try Version(package: pkg,
79-
docArchives: [archive],
80-
latest: .release,
81-
reference: .tag(SemanticVersion(1, 2, 3)))
82-
]
83-
84-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
85-
.internal(docVersion: .reference("1.2.3"), archive: "foo"))
86-
}
87-
88-
do {
89-
// [ Default branch (with docs), Pre-Release (with docs), nil ] = Pre-Release
90-
let versions = [
91-
try Version(package: pkg,
92-
commit: "123",
93-
commitDate: .t0,
94-
docArchives: [archive],
95-
latest: .defaultBranch,
96-
reference: .branch("main"),
97-
spiManifest: nil),
98-
try Version(package: pkg,
99-
docArchives: [archive],
100-
latest: .preRelease,
101-
reference: .tag(SemanticVersion(1, 2, 3, "b1"))),
102-
nil
103-
]
104-
105-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
106-
.internal(docVersion: .reference("1.2.3-b1"), archive: "foo"))
107-
}
108-
109-
do {
110-
// [ Default branch (with docs), Pre-Release (with docs), Release (with docs) ] = Release
111-
let versions = [
112-
try Version(package: pkg,
113-
commit: "123",
114-
commitDate: .t0,
115-
docArchives: [archive],
116-
latest: .defaultBranch,
117-
reference: .branch("main"),
118-
spiManifest: nil),
119-
try Version(package: pkg,
120-
docArchives: [archive],
121-
latest: .preRelease,
122-
reference: .tag(SemanticVersion(1, 2, 3, "b1"))),
123-
try Version(package: pkg,
124-
docArchives: [archive],
125-
latest: .release,
126-
reference: .tag(SemanticVersion(1, 2, 3)))
127-
]
128-
129-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
130-
.internal(docVersion: .reference("1.2.3"), archive: "foo"))
131-
}
132-
133-
do {
134-
// [ Default branch (no docs), nil, Release (with docs) ] = Release
135-
let versions = [
136-
try Version(package: pkg,
137-
commit: "123",
138-
commitDate: .t0,
139-
docArchives: nil,
140-
latest: .defaultBranch,
141-
reference: .branch("main"),
142-
spiManifest: nil),
143-
nil,
144-
try Version(package: pkg,
145-
docArchives: [archive],
146-
latest: .release,
147-
reference: .tag(SemanticVersion(1, 2, 3)))
148-
]
149-
150-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
151-
.internal(docVersion: .reference("1.2.3"), archive: "foo"))
152-
}
153-
154-
do {
155-
// [ Default branch (with external docs), Pre-Release (with docs), Release (with docs) ] = External docs
156-
let versions = [
157-
try Version(package: pkg,
158-
commit: "123",
159-
commitDate: .t0,
160-
docArchives: [archive],
161-
latest: .defaultBranch,
162-
reference: .branch("main"),
163-
spiManifest: .init(externalLinks: .init(documentation: "https://example.com"))),
164-
try Version(package: pkg,
165-
docArchives: [archive],
166-
latest: .preRelease,
167-
reference: .tag(SemanticVersion(1, 2, 3, "b1"))),
168-
try Version(package: pkg,
169-
docArchives: [archive],
170-
latest: .release,
171-
reference: .tag(SemanticVersion(1, 2, 3)))
172-
]
173-
174-
XCTAssertEqual(versions.canonicalDocumentationTarget(),
175-
.external(url: "https://example.com"))
18+
import SemanticVersion
19+
import Testing
20+
21+
22+
@Suite struct ArrayVersionExtensionTests {
23+
24+
@Test func Array_canonicalDocumentationTarget() async throws {
25+
try await withApp { app in
26+
let pkg = try await savePackage(on: app.db, "1".url)
27+
let archive = DocArchive(name: "foo", title: "Foo")
28+
29+
do {
30+
// [ Default branch, nil, nil ] = Default branch
31+
let versions = [
32+
try Version(package: pkg,
33+
commit: "123",
34+
commitDate: .t0,
35+
docArchives: [archive],
36+
latest: .defaultBranch,
37+
reference: .branch("main"),
38+
spiManifest: nil),
39+
nil,
40+
nil
41+
]
42+
43+
#expect(versions.canonicalDocumentationTarget() == .internal(docVersion: .reference("main"), archive: "foo"))
44+
}
45+
46+
do {
47+
// [ Default branch (with docs), nil, Release (no docs) ] = Default branch
48+
let versions = [
49+
try Version(package: pkg,
50+
commit: "123",
51+
commitDate: .t0,
52+
docArchives: [archive],
53+
latest: .defaultBranch,
54+
reference: .branch("main"),
55+
spiManifest: nil),
56+
nil,
57+
try Version(package: pkg,
58+
docArchives: nil,
59+
latest: .release,
60+
reference: .tag(SemanticVersion(1, 2, 3))),
61+
]
62+
63+
#expect(versions.canonicalDocumentationTarget() == .internal(docVersion: .reference("main"), archive: "foo"))
64+
}
65+
66+
do {
67+
// [ Default branch (with docs), nil, Release (with docs) ] = Release
68+
let versions = [
69+
try Version(package: pkg,
70+
commit: "123",
71+
commitDate: .t0,
72+
docArchives: [archive],
73+
latest: .defaultBranch,
74+
reference: .branch("main"),
75+
spiManifest: nil),
76+
nil,
77+
try Version(package: pkg,
78+
docArchives: [archive],
79+
latest: .release,
80+
reference: .tag(SemanticVersion(1, 2, 3)))
81+
]
82+
83+
#expect(versions.canonicalDocumentationTarget() == .internal(docVersion: .reference("1.2.3"), archive: "foo"))
84+
}
85+
86+
do {
87+
// [ Default branch (with docs), Pre-Release (with docs), nil ] = Pre-Release
88+
let versions = [
89+
try Version(package: pkg,
90+
commit: "123",
91+
commitDate: .t0,
92+
docArchives: [archive],
93+
latest: .defaultBranch,
94+
reference: .branch("main"),
95+
spiManifest: nil),
96+
try Version(package: pkg,
97+
docArchives: [archive],
98+
latest: .preRelease,
99+
reference: .tag(SemanticVersion(1, 2, 3, "b1"))),
100+
nil
101+
]
102+
103+
#expect(versions.canonicalDocumentationTarget() == .internal(docVersion: .reference("1.2.3-b1"), archive: "foo"))
104+
}
105+
106+
do {
107+
// [ Default branch (with docs), Pre-Release (with docs), Release (with docs) ] = Release
108+
let versions = [
109+
try Version(package: pkg,
110+
commit: "123",
111+
commitDate: .t0,
112+
docArchives: [archive],
113+
latest: .defaultBranch,
114+
reference: .branch("main"),
115+
spiManifest: nil),
116+
try Version(package: pkg,
117+
docArchives: [archive],
118+
latest: .preRelease,
119+
reference: .tag(SemanticVersion(1, 2, 3, "b1"))),
120+
try Version(package: pkg,
121+
docArchives: [archive],
122+
latest: .release,
123+
reference: .tag(SemanticVersion(1, 2, 3)))
124+
]
125+
126+
#expect(versions.canonicalDocumentationTarget() == .internal(docVersion: .reference("1.2.3"), archive: "foo"))
127+
}
128+
129+
do {
130+
// [ Default branch (no docs), nil, Release (with docs) ] = Release
131+
let versions = [
132+
try Version(package: pkg,
133+
commit: "123",
134+
commitDate: .t0,
135+
docArchives: nil,
136+
latest: .defaultBranch,
137+
reference: .branch("main"),
138+
spiManifest: nil),
139+
nil,
140+
try Version(package: pkg,
141+
docArchives: [archive],
142+
latest: .release,
143+
reference: .tag(SemanticVersion(1, 2, 3)))
144+
]
145+
146+
#expect(versions.canonicalDocumentationTarget() == .internal(docVersion: .reference("1.2.3"), archive: "foo"))
147+
}
148+
149+
do {
150+
// [ Default branch (with external docs), Pre-Release (with docs), Release (with docs) ] = External docs
151+
let versions = [
152+
try Version(package: pkg,
153+
commit: "123",
154+
commitDate: .t0,
155+
docArchives: [archive],
156+
latest: .defaultBranch,
157+
reference: .branch("main"),
158+
spiManifest: .init(externalLinks: .init(documentation: "https://example.com"))),
159+
try Version(package: pkg,
160+
docArchives: [archive],
161+
latest: .preRelease,
162+
reference: .tag(SemanticVersion(1, 2, 3, "b1"))),
163+
try Version(package: pkg,
164+
docArchives: [archive],
165+
latest: .release,
166+
reference: .tag(SemanticVersion(1, 2, 3)))
167+
]
168+
169+
#expect(versions.canonicalDocumentationTarget() == .external(url: "https://example.com"))
170+
}
176171
}
177172
}
173+
178174
}

0 commit comments

Comments
 (0)