diff --git a/.travis.yml b/.travis.yml index 69afcfba..1f9d626c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,10 @@ matrix: dist: trusty sudo: required env: SWIFT_SNAPSHOT=4.0.3 -# Tests fail on Swift 4.2 on Linux. -# - os: linux -# dist: trusty -# sudo: required -# env: DOCKER_IMAGE=ubuntu:16.04 SWIFT_SNAPSHOT=4.2.1 + - os: linux + dist: trusty + sudo: required + env: DOCKER_IMAGE=ubuntu:16.04 SWIFT_SNAPSHOT=4.2.1 # - os: linux # dist: trusty # sudo: required diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift new file mode 100644 index 00000000..7bd26320 --- /dev/null +++ b/Package@swift-4.2.swift @@ -0,0 +1,43 @@ +// swift-tools-version:4.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. +/** + * Copyright IBM Corporation 2016, 2017 + * + * 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 PackageDescription + +let package = Package( + name: "SwiftyJSON", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "SwiftyJSON", + targets: ["SwiftyJSON"] + ) + ], + dependencies: [], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "SwiftyJSON", + dependencies: [] + ), + .testTarget( + name: "SwiftyJSONTests", + dependencies: ["SwiftyJSON"] + ) + ] +) diff --git a/Sources/SwiftyJSON/SwiftyJSON.swift b/Sources/SwiftyJSON/SwiftyJSON.swift index 9362bc84..c7bd7e66 100755 --- a/Sources/SwiftyJSON/SwiftyJSON.swift +++ b/Sources/SwiftyJSON/SwiftyJSON.swift @@ -237,7 +237,13 @@ public struct JSON { var type: Type var value: Any - if let bool = newValue as? Bool { + if let number = newValue as? Int { + type = .number + value = NSNumber(value: number) + } else if let number = newValue as? Double { + type = .number + value = NSNumber(value: number) + } else if let bool = newValue as? Bool { type = .bool value = bool } else if let number = newValue as? NSNumber { @@ -248,13 +254,7 @@ public struct JSON { type = .number value = number } - } else if let number = newValue as? Double { - type = .number - value = NSNumber(value: number) - } else if let number = newValue as? Int { - type = .number - value = NSNumber(value: number) - } else if let string = newValue as? String { + } else if let string = newValue as? String { type = .string value = string } else if let string = newValue as? NSString { diff --git a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift index d2dba525..fef0134d 100644 --- a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift +++ b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift @@ -70,7 +70,7 @@ class LiteralConvertibleTests: XCTestCase { XCTAssert(jsonNil_1 == nil) let jsonNil_2:JSON = JSON(NSNull.self) XCTAssert(jsonNil_2 != nil) - let jsonNil_3:JSON = JSON([1:2]) + let jsonNil_3:JSON = JSON(["1":2]) XCTAssert(jsonNil_3 != nil) } diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 55c88548..ab35a441 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -55,7 +55,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 9876543210.123456789) // Number of fraction digits differs on OSX and Linux, // issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 - #if os(Linux) + #if (os(Linux) && !swift(>=4.2)) XCTAssertEqual(json.stringValue, "9876543210.12346") #else XCTAssertEqual(json.stringValue, "9876543210.123457") @@ -128,7 +128,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 9876543210.123456789) // Number of fraction digits differs on OSX and Linux, // issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 - #if os(Linux) + #if (os(Linux) && !swift(>=4.2)) XCTAssertEqual(json.stringValue, "9876543210.12346") #else XCTAssertEqual(json.stringValue, "9876543210.123457") diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index 593015f5..f76135f9 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -43,7 +43,7 @@ class PrintableTests: XCTestCase { let json:JSON = 1234567890.876623 // Number of fraction digits differs on OSX and Linux, // issue https://github.com/IBM-Swift/SwiftRuntime/issues/183 - #if os(Linux) + #if (os(Linux) && !swift(>=4.2)) XCTAssertEqual(json.description, "1234567890.87662") XCTAssertEqual(json.debugDescription, "1234567890.87662") #else