Skip to content

Commit 4133d76

Browse files
authored
Make the dump-package command output defaultLocalization (#9170)
1 parent 8889a96 commit 4133d76

File tree

8 files changed

+161
-6
lines changed

8 files changed

+161
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// swift-tools-version: 6.0
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "PlayingCard",
6+
products: [
7+
.library(name: "PlayingCard", targets: ["PlayingCard"]),
8+
],
9+
targets: [
10+
.target(name: "PlayingCard", path: "src"),
11+
]
12+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public struct PlayingCard: Equatable {
2+
let rank: Rank
3+
let suit: Suit
4+
5+
public init(rank: Rank, suit: Suit) {
6+
self.rank = rank
7+
self.suit = suit
8+
}
9+
}
10+
11+
// MARK: - Comparable
12+
13+
extension PlayingCard: Comparable {}
14+
15+
public func <(lhs: PlayingCard, rhs: PlayingCard) -> Bool {
16+
return lhs.suit < rhs.suit || (lhs.suit == rhs.suit && lhs.rank < rhs.rank)
17+
}
18+
19+
// MARK: - CustomStringConvertible
20+
21+
extension PlayingCard : CustomStringConvertible {
22+
public var description: String {
23+
return "\(suit)\(rank)"
24+
}
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
public enum Rank : Int {
2+
case Ace = 1
3+
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
4+
case Jack, Queen, King
5+
}
6+
7+
// MARK: - Comparable
8+
9+
extension Rank : Comparable {}
10+
11+
public func <(lhs: Rank, rhs: Rank) -> Bool {
12+
switch (lhs, rhs) {
13+
case (_, _) where lhs == rhs:
14+
return false
15+
case (.Ace, _):
16+
return false
17+
default:
18+
return lhs.rawValue < rhs.rawValue
19+
}
20+
}
21+
22+
// MARK: - CustomStringConvertible
23+
24+
extension Rank : CustomStringConvertible {
25+
public var description: String {
26+
switch self {
27+
case .Ace: return "A"
28+
case .Jack: return "J"
29+
case .Queen: return "Q"
30+
case .King: return "K"
31+
default:
32+
return "\(rawValue)"
33+
}
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public enum Suit: String {
2+
case Spades, Hearts, Diamonds, Clubs
3+
}
4+
5+
// MARK: - Comparable
6+
7+
extension Suit: Comparable {}
8+
9+
public func <(lhs: Suit, rhs: Suit) -> Bool {
10+
switch (lhs, rhs) {
11+
case (_, _) where lhs == rhs:
12+
return false
13+
case (.Spades, _),
14+
(.Hearts, .Diamonds), (.Hearts, .Clubs),
15+
(.Diamonds, .Clubs):
16+
return false
17+
default:
18+
return true
19+
}
20+
}
21+
22+
// MARK: - CustomStringConvertible
23+
24+
extension Suit : CustomStringConvertible {
25+
public var description: String {
26+
switch self {
27+
case .Spades: return "♠︎"
28+
case .Hearts: return ""
29+
case .Diamonds: return ""
30+
case .Clubs: return "♣︎"
31+
}
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// swift-tools-version: 6.0
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "Dealer",
6+
defaultLocalization: "en",
7+
platforms: [
8+
.macOS(.v10_13),
9+
.iOS(.v12),
10+
.tvOS(.v12),
11+
.watchOS(.v5)
12+
],
13+
dependencies: [
14+
.package(path: "../PlayingCard"),
15+
],
16+
targets: [
17+
.target(
18+
name: "Dealer",
19+
dependencies: ["PlayingCard"],
20+
path: "./"
21+
),
22+
]
23+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import PlayingCard
12+
13+
let hand: [PlayingCard] = [
14+
.init(rank: .Ace, suit: .Hearts),
15+
.init(rank: .King, suit: .Spades),
16+
]
17+
18+
for card in hand {
19+
print(card)
20+
}

Sources/PackageModel/Manifest/Manifest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ extension Manifest: Encodable {
655655
}
656656

657657
try container.encode(self.toolsVersion, forKey: .toolsVersion)
658+
try container.encode(self.defaultLocalization, forKey: .defaultLocalization)
658659
try container.encode(self.pkgConfig, forKey: .pkgConfig)
659660
try container.encode(self.providers, forKey: .providers)
660661
try container.encode(self.cLanguageStandard, forKey: .cLanguageStandard)

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ struct PackageCommandTests {
986986
func dumpPackage(
987987
data: BuildData,
988988
) async throws {
989-
try await fixture(name: "DependencyResolution/External/Complex") { fixturePath in
989+
try await fixture(name: "Miscellaneous/DumpPackage") { fixturePath in
990990
let packageRoot = fixturePath.appending("app")
991991
let (dumpOutput, _) = try await execute(
992992
["dump-package"],
@@ -1000,29 +1000,34 @@ struct PackageCommandTests {
10001000
return
10011001
}
10021002
guard case .string(let name)? = contents["name"] else {
1003-
Issue.record("unexpected result")
1003+
Issue.record("unexpected name")
1004+
return
1005+
}
1006+
guard case .string(let defaultLocalization)? = contents["defaultLocalization"] else {
1007+
Issue.record("unexpected defaultLocalization")
10041008
return
10051009
}
10061010
guard case .array(let platforms)? = contents["platforms"] else {
1007-
Issue.record("unexpected result")
1011+
Issue.record("unexpected platforms")
10081012
return
10091013
}
10101014
#expect(name == "Dealer")
1015+
#expect(defaultLocalization == "en")
10111016
#expect(
10121017
platforms == [
10131018
.dictionary([
10141019
"platformName": .string("macos"),
1015-
"version": .string("10.12"),
1020+
"version": .string("10.13"),
10161021
"options": .array([]),
10171022
]),
10181023
.dictionary([
10191024
"platformName": .string("ios"),
1020-
"version": .string("10.0"),
1025+
"version": .string("12.0"),
10211026
"options": .array([]),
10221027
]),
10231028
.dictionary([
10241029
"platformName": .string("tvos"),
1025-
"version": .string("11.0"),
1030+
"version": .string("12.0"),
10261031
"options": .array([]),
10271032
]),
10281033
.dictionary([
@@ -1032,6 +1037,7 @@ struct PackageCommandTests {
10321037
]),
10331038
]
10341039
)
1040+
// FIXME: We should also test dependencies and targets here.
10351041
}
10361042
}
10371043

0 commit comments

Comments
 (0)