Skip to content
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

Fix linux swift4 2 #43

Merged
merged 4 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions Package@swift-4.2.swift
Original file line number Diff line number Diff line change
@@ -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"]
)
]
)
16 changes: 8 additions & 8 deletions Sources/SwiftyJSON/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyJSONTests/LiteralConvertibleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftyJSONTests/NumberTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftyJSONTests/PrintableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down