Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 727ae29

Browse files
authored
swift 5 #compiler check (#197)
1 parent cbe3824 commit 727ae29

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.0
1+
// swift-tools-version:4.1
22
import PackageDescription
33

44
let package = Package(

Sources/Core/CaseInsensitiveString.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ public struct CaseInsensitiveString: ExpressibleByStringLiteral, Comparable, Equ
1717
/// Internal `String` storage.
1818
private let storage: String
1919

20+
// #if compiler(>=4.2)
21+
#if swift(>=4.1.50)
22+
/// See `Hashable`.
23+
public func hash(into hasher: inout Hasher) {
24+
hasher.combine(self.storage.lowercased())
25+
}
26+
#else
2027
/// See `Hashable`.
2128
public var hashValue: Int {
2229
return self.storage.lowercased().hashValue
2330
}
31+
#endif
2432

2533
/// See `CustomStringConvertible`.
2634
public var description: String {

Sources/Core/MediaType.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,28 @@ public struct MediaType: Hashable, CustomStringConvertible, Equatable {
122122
return serialize()
123123
}
124124

125+
// #if compiler(>=4.2)
126+
#if swift(>=4.1.50)
125127
/// See `Hashable`.
126-
public let hashValue: Int
128+
public func hash(into hasher: inout Hasher) {
129+
hasher.combine(self._hashValue)
130+
}
131+
#else
132+
/// See `Hashable`.
133+
public var hashValue: Int {
134+
return self._hashValue
135+
}
136+
#endif
137+
138+
/// Hash value storage.
139+
private let _hashValue: Int
127140

128141
/// Create a new `MediaType`.
129142
public init(type: String, subType: String, parameters: [CaseInsensitiveString: String] = [:]) {
130143
self.type = type
131144
self.subType = subType
132145
self.parameters = parameters
133-
self.hashValue = type.hashValue &+ subType.hashValue
146+
self._hashValue = type.hashValue &+ subType.hashValue
134147
}
135148

136149
/// Parse a `MediaType` from a `String`.

Tests/CoreTests/ReflectableTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ class ReflectableTests: XCTestCase {
2727
}
2828

2929
let properties = try Foo.reflectProperties()
30+
31+
#if swift(>=4.1.50)
3032
XCTAssertEqual(properties.description, """
3133
[bool: Bool, obool: Optional<Bool>, int: Int, oint: Optional<Int>, sarr: Array<String>, osarr: Optional<Array<String>>, pet: Pet, opet: Optional<Pet>, dir: Direction, odir: Optional<Direction>]
3234
""")
35+
#else
36+
XCTAssertEqual(properties.description, """
37+
[bool: Bool, obool: Optional<Bool>, int: Int, oint: Optional<Int>, sarr: Array<String>, osarr: Optional<Array<String>>, pet: Pet #1, opet: Optional<Pet #1>, dir: Direction #1, odir: Optional<Direction #1>]
38+
""")
39+
#endif
3340

3441
try XCTAssertEqual(Foo.reflectProperty(forKey: \.bool)?.path, ["bool"])
3542
try XCTAssert(Foo.reflectProperty(forKey: \.bool)?.type is Bool.Type)
@@ -233,7 +240,11 @@ class ReflectableTests: XCTestCase {
233240
var age: Int
234241
}
235242

243+
#if swift(>=4.1.50)
236244
try XCTAssertEqual(User.reflectProperties(depth: 0).description, "[id: Optional<UUID>, pet: Pet, name: String, age: Int]")
245+
#else
246+
try XCTAssertEqual(User.reflectProperties(depth: 0).description, "[id: Optional<UUID>, pet: Pet #1, name: String, age: Int]")
247+
#endif
237248
try XCTAssertEqual(User.reflectProperties(depth: 1).description, "[pet.name: String, pet.age: Int]")
238249
try XCTAssertEqual(User.reflectProperties(depth: 2).description, "[]")
239250
}
@@ -308,7 +319,11 @@ class ReflectableTests: XCTestCase {
308319
var pets: [Pet]
309320
}
310321

322+
#if swift(>=4.1.50)
311323
try XCTAssertEqual(Person.reflectProperties().description, "[id: Optional<Int>, title: String, pets: Array<Pet>]")
324+
#else
325+
try XCTAssertEqual(Person.reflectProperties().description, "[id: Optional<Int>, title: String, pets: Array<Pet #1>]")
326+
#endif
312327
XCTAssertThrowsError(try Person.reflectProperty(forKey: \.pets))
313328
}
314329

0 commit comments

Comments
 (0)