Skip to content

Commit d4ce78d

Browse files
committed
Move Dictionary extension, add test
1 parent 3b4c479 commit d4ce78d

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2022 Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
18+
extension Dictionary where Key == PackageId, Value == URL {
19+
subscript(caseInsensitive packageId: PackageId) -> URL? {
20+
first(where: { $0.key.lowercased() == packageId.lowercased() })?.value
21+
}
22+
}

Sources/ReleaseNotesCore/ReleaseNotes.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ReleaseNotes: AsyncParsableCommand {
5353

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

107107
}
108-
109-
110-
private extension Dictionary where Key == PackageId, Value == URL {
111-
subscript(caseIgnoring packageId: PackageId) -> URL? {
112-
first(where: { $0.key.lowercased() == packageId.lowercased() })?.value
113-
}
114-
}

Tests/ReleaseNotesTests/PackageResolvedTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@ final class ReleaseNotesCoreTests: XCTestCase {
3232
XCTAssertEqual(map?.count, 5)
3333
}
3434

35+
func test_Dictionary_subscript_caseInsensitive() throws {
36+
let d = [
37+
PackageId("foo"): URL(string: "1")!,
38+
PackageId("bar"): URL(string: "2")!,
39+
]
40+
XCTAssertEqual(d[caseInsensitive: "foo"], URL(string: "1")!)
41+
XCTAssertEqual(d[caseInsensitive: "Foo"], URL(string: "1")!)
42+
}
43+
3544
}

0 commit comments

Comments
 (0)