Skip to content

[4.2] Fix availability statements in CodableTests.swift #17641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions test/stdlib/CodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestCodableSuper { }
#endif

// MARK: - Helper Functions
@available(OSX 10.11, iOS 9.0, *)
@available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *)
func makePersonNameComponents(namePrefix: String? = nil,
givenName: String? = nil,
middleName: String? = nil,
Expand Down Expand Up @@ -220,7 +220,7 @@ class TestCodable : TestCodableSuper {
#line : CGAffineTransform(a: 0.498, b: -0.284, c: -0.742, d: 0.3248, tx: 12, ty: 44)
]

if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
values[#line] = CGAffineTransform(rotationAngle: .pi / 2)
}

Expand All @@ -246,7 +246,7 @@ class TestCodable : TestCodableSuper {
#line : CGPoint(x: 10, y: 20)
]

if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
// Limit on magnitude in JSON. See rdar://problem/12717407
values[#line] = CGPoint(x: CGFloat.greatestFiniteMagnitude,
y: CGFloat.greatestFiniteMagnitude)
Expand Down Expand Up @@ -274,7 +274,7 @@ class TestCodable : TestCodableSuper {
#line : CGSize(width: 30, height: 40)
]

if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
// Limit on magnitude in JSON. See rdar://problem/12717407
values[#line] = CGSize(width: CGFloat.greatestFiniteMagnitude,
height: CGFloat.greatestFiniteMagnitude)
Expand Down Expand Up @@ -303,7 +303,7 @@ class TestCodable : TestCodableSuper {
#line : CGRect(x: 10, y: 20, width: 30, height: 40)
]

if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
// Limit on magnitude in JSON. See rdar://problem/12717407
values[#line] = CGRect.infinite
}
Expand All @@ -330,7 +330,7 @@ class TestCodable : TestCodableSuper {
#line : CGVector(dx: 0.0, dy: -9.81)
]

if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
// Limit on magnitude in JSON. See rdar://problem/12717407
values[#line] = CGVector(dx: CGFloat.greatestFiniteMagnitude,
dy: CGFloat.greatestFiniteMagnitude)
Expand Down Expand Up @@ -371,22 +371,22 @@ class TestCodable : TestCodableSuper {
}

// MARK: - DateInterval
@available(OSX 10.12, iOS 10.10, watchOS 3.0, tvOS 10.0, *)
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
lazy var dateIntervalValues: [Int : DateInterval] = [
#line : DateInterval(),
#line : DateInterval(start: Date.distantPast, end: Date()),
#line : DateInterval(start: Date(), end: Date.distantFuture),
#line : DateInterval(start: Date.distantPast, end: Date.distantFuture)
]

@available(OSX 10.12, iOS 10.10, watchOS 3.0, tvOS 10.0, *)
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
func test_DateInterval_JSON() {
for (testLine, interval) in dateIntervalValues {
expectRoundTripEqualityThroughJSON(for: interval, lineNumber: testLine)
}
}

@available(OSX 10.12, iOS 10.10, watchOS 3.0, tvOS 10.0, *)
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
func test_DateInterval_Plist() {
for (testLine, interval) in dateIntervalValues {
expectRoundTripEqualityThroughPlist(for: interval, lineNumber: testLine)
Expand Down Expand Up @@ -482,21 +482,21 @@ class TestCodable : TestCodableSuper {
}

// MARK: - Measurement
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
lazy var unitValues: [Int : Dimension] = [
#line : UnitAcceleration.metersPerSecondSquared,
#line : UnitMass.kilograms,
#line : UnitLength.miles
]

@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
func test_Measurement_JSON() {
for (testLine, unit) in unitValues {
expectRoundTripEqualityThroughJSON(for: Measurement(value: 42, unit: unit), lineNumber: testLine)
}
}

@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
func test_Measurement_Plist() {
for (testLine, unit) in unitValues {
expectRoundTripEqualityThroughJSON(for: Measurement(value: 42, unit: unit), lineNumber: testLine)
Expand All @@ -523,21 +523,21 @@ class TestCodable : TestCodableSuper {
}

// MARK: - PersonNameComponents
@available(OSX 10.11, iOS 9.0, *)
@available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *)
lazy var personNameComponentsValues: [Int : PersonNameComponents] = [
#line : makePersonNameComponents(givenName: "John", familyName: "Appleseed"),
#line : makePersonNameComponents(givenName: "John", familyName: "Appleseed", nickname: "Johnny"),
#line : makePersonNameComponents(namePrefix: "Dr.", givenName: "Jane", middleName: "A.", familyName: "Appleseed", nameSuffix: "Esq.", nickname: "Janie")
]

@available(OSX 10.11, iOS 9.0, *)
@available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *)
func test_PersonNameComponents_JSON() {
for (testLine, components) in personNameComponentsValues {
expectRoundTripEqualityThroughJSON(for: components, lineNumber: testLine)
}
}

@available(OSX 10.11, iOS 9.0, *)
@available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *)
func test_PersonNameComponents_Plist() {
for (testLine, components) in personNameComponentsValues {
expectRoundTripEqualityThroughPlist(for: components, lineNumber: testLine)
Expand Down Expand Up @@ -572,7 +572,7 @@ class TestCodable : TestCodableSuper {
#line : URL(string: "documentation", relativeTo: URL(string: "http://swift.org")!)!
]

if #available(OSX 10.11, iOS 9.0, *) {
if #available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *) {
values[#line] = URL(fileURLWithPath: "bin/sh", relativeTo: URL(fileURLWithPath: "/"))
}

Expand Down Expand Up @@ -770,8 +770,6 @@ var tests = [
"test_TimeZone_Plist" : TestCodable.test_TimeZone_Plist,
"test_URL_JSON" : TestCodable.test_URL_JSON,
"test_URL_Plist" : TestCodable.test_URL_Plist,
"test_URLComponents_JSON" : TestCodable.test_URLComponents_JSON,
"test_URLComponents_Plist" : TestCodable.test_URLComponents_Plist,
"test_UUID_JSON" : TestCodable.test_UUID_JSON,
"test_UUID_Plist" : TestCodable.test_UUID_Plist,
]
Expand All @@ -781,18 +779,23 @@ var tests = [
tests["test_AffineTransform_Plist"] = TestCodable.test_AffineTransform_Plist
#endif

if #available(OSX 10.11, iOS 9.0, *) {
if #available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *) {
tests["test_PersonNameComponents_JSON"] = TestCodable.test_PersonNameComponents_JSON
tests["test_PersonNameComponents_Plist"] = TestCodable.test_PersonNameComponents_Plist
}

if #available(OSX 10.12, iOS 10.10, watchOS 3.0, tvOS 10.0, *) {
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
// tests["test_DateInterval_JSON"] = TestCodable.test_DateInterval_JSON
tests["test_DateInterval_Plist"] = TestCodable.test_DateInterval_Plist
// tests["test_Measurement_JSON"] = TestCodable.test_Measurement_JSON
// tests["test_Measurement_Plist"] = TestCodable.test_Measurement_Plist
}

if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
tests["test_URLComponents_JSON"] = TestCodable.test_URLComponents_JSON
tests["test_URLComponents_Plist"] = TestCodable.test_URLComponents_Plist
}

var CodableTests = TestSuite("TestCodable")
for (name, test) in tests {
CodableTests.test(name) { test(TestCodable())() }
Expand Down