Skip to content

Commit

Permalink
Merge pull request #11 from SwiftPackageIndex/support-Package.resolve…
Browse files Browse the repository at this point in the history
…d-v2

Move extension to test-only
  • Loading branch information
finestructure authored Oct 10, 2022
2 parents 3d1764e + d4ce78d commit 6710dc4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
22 changes: 22 additions & 0 deletions Sources/ReleaseNotesCore/Dictionary+ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2022 Dave Verwer, Sven A. Schmidt, and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation


extension Dictionary where Key == PackageId, Value == URL {
subscript(caseInsensitive packageId: PackageId) -> URL? {
first(where: { $0.key.lowercased() == packageId.lowercased() })?.value
}
}
21 changes: 0 additions & 21 deletions Sources/ReleaseNotesCore/PackageResolved.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,6 @@ enum PackageResolved {
}


extension PackageResolved {
var v1: V1? {
switch self {
case let .v1(value):
return value
case .v2:
return nil
}
}

var v2: V2? {
switch self {
case .v1:
return nil
case let .v2(value):
return value
}
}
}


extension PackageResolved {
func getPackageMap() -> [PackageId: URL] {
switch self {
Expand Down
9 changes: 1 addition & 8 deletions Sources/ReleaseNotesCore/ReleaseNotes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ReleaseNotes: AsyncParsableCommand {

print("\nRelease notes URLs (updating from):")
for update in updates {
let releasesURL = packageMap[caseIgnoring: update.packageId]
let releasesURL = packageMap[caseInsensitive: update.packageId]
.map { $0.absoluteString.droppingGitExtension + "/releases" }
?? "\(update.packageId)"
print(releasesURL, "(\(update.oldRevision?.description ?? "new package"))")
Expand Down Expand Up @@ -105,10 +105,3 @@ struct ReleaseNotes: AsyncParsableCommand {
}

}


private extension Dictionary where Key == PackageId, Value == URL {
subscript(caseIgnoring packageId: PackageId) -> URL? {
first(where: { $0.key.lowercased() == packageId.lowercased() })?.value
}
}
9 changes: 9 additions & 0 deletions Tests/ReleaseNotesTests/PackageResolvedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ final class ReleaseNotesCoreTests: XCTestCase {
XCTAssertEqual(map?.count, 5)
}

func test_Dictionary_subscript_caseInsensitive() throws {
let d = [
PackageId("foo"): URL(string: "1")!,
PackageId("bar"): URL(string: "2")!,
]
XCTAssertEqual(d[caseInsensitive: "foo"], URL(string: "1")!)
XCTAssertEqual(d[caseInsensitive: "Foo"], URL(string: "1")!)
}

}
23 changes: 23 additions & 0 deletions Tests/ReleaseNotesTests/ReleaseNotesCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,26 @@ final class PackageResolvedTests: XCTestCase {
}

}


private extension PackageResolved {
var v1: V1? {
switch self {
case let .v1(value):
return value
case .v2:
return nil
}
}

var v2: V2? {
switch self {
case .v1:
return nil
case let .v2(value):
return value
}
}
}


0 comments on commit 6710dc4

Please sign in to comment.