Merge pull request #1062 from ddunn2/urlSessionServer
diff --git a/CoreFoundation/NumberDate.subproj/CFNumber.c b/CoreFoundation/NumberDate.subproj/CFNumber.c
index 868e5e1..935780e 100644
--- a/CoreFoundation/NumberDate.subproj/CFNumber.c
+++ b/CoreFoundation/NumberDate.subproj/CFNumber.c
@@ -1107,6 +1107,13 @@
__CFBitfieldSetValue(((struct __CFNumber *)result)->_base._cfinfo[CF_INFO_BITS], 4, 0, (uint8_t)__CFNumberTypeTable[type].canonicalType);
}
+void _CFNumberInitInt128(CFNumberRef result, int64_t value) {
+ CFSInt128Struct int128value;
+ int128value.high = 0;
+ int128value.low = value;
+ _CFNumberInit(result, kCFNumberSInt128Type, &int128value);
+}
+
void _CFNumberInitBool(CFNumberRef result, Boolean value) {
_CFNumberInit(result, kCFNumberCharType, &value);
}
@@ -1116,7 +1123,11 @@
}
void _CFNumberInitUInt8(CFNumberRef result, uint8_t value) {
- _CFNumberInit(result, kCFNumberCharType, &value);
+ if (value > INT8_MAX) {
+ _CFNumberInitInt16(result, value);
+ } else {
+ _CFNumberInit(result, kCFNumberCharType, &value);
+ }
}
void _CFNumberInitInt16(CFNumberRef result, int16_t value) {
@@ -1124,7 +1135,11 @@
}
void _CFNumberInitUInt16(CFNumberRef result, uint16_t value) {
- _CFNumberInit(result, kCFNumberShortType, &value);
+ if (value > INT16_MAX) {
+ _CFNumberInitInt32(result, value);
+ } else {
+ _CFNumberInit(result, kCFNumberShortType, &value);
+ }
}
void _CFNumberInitInt32(CFNumberRef result, int32_t value) {
@@ -1132,7 +1147,11 @@
}
void _CFNumberInitUInt32(CFNumberRef result, uint32_t value) {
- _CFNumberInit(result, kCFNumberIntType, &value);
+ if (value > INT32_MAX) {
+ _CFNumberInitInt64(result, value);
+ } else {
+ _CFNumberInit(result, kCFNumberIntType, &value);
+ }
}
void _CFNumberInitInt(CFNumberRef result, long value) {
@@ -1140,7 +1159,22 @@
}
void _CFNumberInitUInt(CFNumberRef result, unsigned long value) {
- _CFNumberInit(result, kCFNumberLongType, &value);
+ if (value > LONG_MAX) {
+ switch (sizeof(unsigned long)) {
+ case 4:
+ _CFNumberInitInt64(result, value);
+ break;
+
+ case 8:
+ _CFNumberInitInt128(result, value);
+ break;
+
+ default:
+ CFAssert1(false, __kCFLogAssertion, "Unexpected unsigned long type size: %d", sizeof(unsigned long));
+ }
+ } else {
+ _CFNumberInit(result, kCFNumberLongType, &value);
+ }
}
void _CFNumberInitInt64(CFNumberRef result, int64_t value) {
@@ -1148,7 +1182,11 @@
}
void _CFNumberInitUInt64(CFNumberRef result, uint64_t value) {
- _CFNumberInit(result, kCFNumberLongLongType, &value);
+ if (value > INT64_MAX) {
+ _CFNumberInitInt128(result, value);
+ } else {
+ _CFNumberInit(result, kCFNumberLongLongType, &value);
+ }
}
void _CFNumberInitFloat(CFNumberRef result, float value) {
diff --git a/Foundation/IndexPath.swift b/Foundation/IndexPath.swift
index 1bcf3ca..b85aaf6 100644
--- a/Foundation/IndexPath.swift
+++ b/Foundation/IndexPath.swift
@@ -2,16 +2,29 @@
//
// This source file is part of the Swift.org open source project
//
-// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
+// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
-// See http://swift.org/LICENSE.txt for license information
-// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
-// Implementation note: NSIndexPath is an efficient array of integers for Objective-C.
-// For Swift, we bridge to this wrapper of Array<Int>. This gives us great Swift performance and interop with Objective-C.
+#if DEPLOYMENT_RUNTIME_SWIFT
+
+func _NSIndexPathCreateFromIndexes(_ idx1: Int, _ idx2: Int) -> NSObject {
+ var indexes = (idx1, idx2)
+ return withUnsafeBytes(of: &indexes) { (ptr) -> NSIndexPath in
+ return NSIndexPath.init(indexes: ptr.baseAddress!.assumingMemoryBound(to: Int.self), length: 2)
+ }
+}
+
+#else
+
+@_exported import Foundation // Clang module
+import _SwiftFoundationOverlayShims
+
+#endif
/**
`IndexPath` represents the path to a specific node in a tree of nested array collections.
@@ -24,7 +37,513 @@
public typealias Index = Array<Int>.Index
public typealias Indices = DefaultRandomAccessIndices<IndexPath>
- fileprivate var _indexes : Array<Int>
+ fileprivate enum Storage : ExpressibleByArrayLiteral {
+ typealias Element = Int
+ case empty
+ case single(Int)
+ case pair(Int, Int)
+ case array([Int])
+
+ init(arrayLiteral elements: Int...) {
+ self.init(elements)
+ }
+
+ init(_ elements: [Int]) {
+ switch elements.count {
+ case 0:
+ self = .empty
+ break
+ case 1:
+ self = .single(elements[0])
+ break
+ case 2:
+ self = .pair(elements[0], elements[1])
+ break
+ default:
+ self = .array(elements)
+ break
+ }
+ }
+
+ func dropLast() -> Storage {
+ switch self {
+ case .empty:
+ return .empty
+ case .single(_):
+ return .empty
+ case .pair(let first, _):
+ return .single(first)
+ case .array(let indexes):
+ switch indexes.count {
+ case 3:
+ return .pair(indexes[0], indexes[1])
+ default:
+ return .array(Array<Int>(indexes.dropLast()))
+ }
+ }
+ }
+
+ mutating func append(_ other: Int) {
+ switch self {
+ case .empty:
+ self = .single(other)
+ break
+ case .single(let first):
+ self = .pair(first, other)
+ break
+ case .pair(let first, let second):
+ self = .array([first, second, other])
+ break
+ case .array(let indexes):
+ self = .array(indexes + [other])
+ break
+ }
+ }
+
+ mutating func append(contentsOf other: Storage) {
+ switch self {
+ case .empty:
+ switch other {
+ case .empty:
+ // DO NOTHING
+ break
+ case .single(let rhsIndex):
+ self = .single(rhsIndex)
+ break
+ case .pair(let rhsFirst, let rhsSecond):
+ self = .pair(rhsFirst, rhsSecond)
+ break
+ case .array(let rhsIndexes):
+ self = .array(rhsIndexes)
+ break
+ }
+ break
+ case .single(let lhsIndex):
+ switch other {
+ case .empty:
+ // DO NOTHING
+ break
+ case .single(let rhsIndex):
+ self = .pair(lhsIndex, rhsIndex)
+ break
+ case .pair(let rhsFirst, let rhsSecond):
+ self = .array([lhsIndex, rhsFirst, rhsSecond])
+ break
+ case .array(let rhsIndexes):
+ self = .array([lhsIndex] + rhsIndexes)
+ break
+ }
+ break
+ case .pair(let lhsFirst, let lhsSecond):
+ switch other {
+ case .empty:
+ // DO NOTHING
+ break
+ case .single(let rhsIndex):
+ self = .array([lhsFirst, lhsSecond, rhsIndex])
+ break
+ case .pair(let rhsFirst, let rhsSecond):
+ self = .array([lhsFirst, lhsSecond, rhsFirst, rhsSecond])
+ break
+ case .array(let rhsIndexes):
+ self = .array([lhsFirst, lhsSecond] + rhsIndexes)
+ break
+ }
+ break
+ case .array(let lhsIndexes):
+ switch other {
+ case .empty:
+ // DO NOTHING
+ break
+ case .single(let rhsIndex):
+ self = .array(lhsIndexes + [rhsIndex])
+ break
+ case .pair(let rhsFirst, let rhsSecond):
+ self = .array(lhsIndexes + [rhsFirst, rhsSecond])
+ break
+ case .array(let rhsIndexes):
+ self = .array(lhsIndexes + rhsIndexes)
+ break
+ }
+ break
+ }
+ }
+
+ mutating func append(contentsOf other: [Int]) {
+ switch self {
+ case .empty:
+ switch other.count {
+ case 0:
+ // DO NOTHING
+ break
+ case 1:
+ self = .single(other[0])
+ break
+ case 2:
+ self = .pair(other[0], other[1])
+ break
+ default:
+ self = .array(other)
+ break
+ }
+ break
+ case .single(let first):
+ switch other.count {
+ case 0:
+ // DO NOTHING
+ break
+ case 1:
+ self = .pair(first, other[0])
+ break
+ default:
+ self = .array([first] + other)
+ break
+ }
+ break
+ case .pair(let first, let second):
+ switch other.count {
+ case 0:
+ // DO NOTHING
+ break
+ default:
+ self = .array([first, second] + other)
+ break
+ }
+ break
+ case .array(let indexes):
+ self = .array(indexes + other)
+ break
+ }
+ }
+
+ subscript(_ index: Int) -> Int {
+ get {
+ switch self {
+ case .empty:
+ fatalError("index \(index) out of bounds of count 0")
+ break
+ case .single(let first):
+ precondition(index == 0, "index \(index) out of bounds of count 1")
+ return first
+ case .pair(let first, let second):
+ precondition(index >= 0 && index < 2, "index \(index) out of bounds of count 2")
+ return index == 0 ? first : second
+ case .array(let indexes):
+ return indexes[index]
+ }
+ }
+ set {
+ switch self {
+ case .empty:
+ fatalError("index \(index) out of bounds of count 0")
+ break
+ case .single(_):
+ precondition(index == 0, "index \(index) out of bounds of count 1")
+ self = .single(newValue)
+ break
+ case .pair(let first, let second):
+ precondition(index >= 0 && index < 2, "index \(index) out of bounds of count 2")
+ if index == 0 {
+ self = .pair(newValue, second)
+ } else {
+ self = .pair(first, newValue)
+ }
+ break
+ case .array(let indexes_):
+ var indexes = indexes_
+ indexes[index] = newValue
+ self = .array(indexes)
+ break
+ }
+ }
+ }
+
+ subscript(range: Range<Index>) -> Storage {
+ get {
+ switch self {
+ case .empty:
+ switch (range.lowerBound, range.upperBound) {
+ case (0, 0):
+ return .empty
+ default:
+ fatalError("range \(range) is out of bounds of count 0")
+ }
+ case .single(let index):
+ switch (range.lowerBound, range.upperBound) {
+ case (0, 0): fallthrough
+ case (1, 1):
+ return .empty
+ case (0, 1):
+ return .single(index)
+ default:
+ fatalError("range \(range) is out of bounds of count 1")
+ }
+ return self
+ case .pair(let first, let second):
+
+ switch (range.lowerBound, range.upperBound) {
+ case (0, 0):
+ fallthrough
+ case (1, 1):
+ fallthrough
+ case (2, 2):
+ return .empty
+ case (0, 1):
+ return .single(first)
+ case (1, 2):
+ return .single(second)
+ case (0, 2):
+ return self
+ default:
+ fatalError("range \(range) is out of bounds of count 2")
+ }
+ case .array(let indexes):
+ let slice = indexes[range]
+ switch slice.count {
+ case 0:
+ return .empty
+ case 1:
+ return .single(slice[0])
+ case 2:
+ return .pair(slice[0], slice[1])
+ default:
+ return .array(Array<Int>(slice))
+ }
+ }
+ }
+ set {
+ switch self {
+ case .empty:
+ precondition(range.lowerBound == 0 && range.upperBound == 0, "range \(range) is out of bounds of count 0")
+ self = newValue
+ break
+ case .single(let index):
+ switch (range.lowerBound, range.upperBound, newValue) {
+ case (0, 0, .empty):
+ fallthrough
+ case (1, 1, .empty):
+ break
+ case (0, 0, .single(let other)):
+ self = .pair(other, index)
+ break
+ case (0, 0, .pair(let first, let second)):
+ self = .array([first, second, index])
+ break
+ case (0, 0, .array(let other)):
+ self = .array(other + [index])
+ break
+ case (0, 1, .empty):
+ fallthrough
+ case (0, 1, .single):
+ fallthrough
+ case (0, 1, .pair):
+ fallthrough
+ case (0, 1, .array):
+ self = newValue
+ case (1, 1, .single(let other)):
+ self = .pair(index, other)
+ break
+ case (1, 1, .pair(let first, let second)):
+ self = .array([index, first, second])
+ break
+ case (1, 1, .array(let other)):
+ self = .array([index] + other)
+ break
+ default:
+ fatalError("range \(range) is out of bounds of count 1")
+ }
+ case .pair(let first, let second):
+ switch (range.lowerBound, range.upperBound) {
+ case (0, 0):
+ switch newValue {
+ case .empty:
+ break
+ case .single(let other):
+ self = .array([other, first, second])
+ break
+ case .pair(let otherFirst, let otherSecond):
+ self = .array([otherFirst, otherSecond, first, second])
+ break
+ case .array(let other):
+ self = .array(other + [first, second])
+ break
+ }
+ break
+ case (0, 1):
+ switch newValue {
+ case .empty:
+ self = .single(second)
+ break
+ case .single(let other):
+ self = .pair(other, second)
+ break
+ case .pair(let otherFirst, let otherSecond):
+ self = .array([otherFirst, otherSecond, second])
+ break
+ case .array(let other):
+ self = .array(other + [second])
+ break
+ }
+ break
+ case (0, 2):
+ self = newValue
+ break
+ case (1, 2):
+ switch newValue {
+ case .empty:
+ self = .single(first)
+ break
+ case .single(let other):
+ self = .pair(first, other)
+ break
+ case .pair(let otherFirst, let otherSecond):
+ self = .array([first, otherFirst, otherSecond])
+ break
+ case .array(let other):
+ self = .array([first] + other)
+ }
+ break
+ case (2, 2):
+ switch newValue {
+ case .empty:
+ break
+ case .single(let other):
+ self = .array([first, second, other])
+ break
+ case .pair(let otherFirst, let otherSecond):
+ self = .array([first, second, otherFirst, otherSecond])
+ break
+ case .array(let other):
+ self = .array([first, second] + other)
+ }
+ break
+ default:
+ fatalError("range \(range) is out of bounds of count 2")
+ }
+ case .array(let indexes):
+ var newIndexes = indexes
+ newIndexes.removeSubrange(range)
+ switch newValue {
+ case .empty:
+ break
+ case .single(let index):
+ newIndexes.insert(index, at: range.lowerBound)
+ break
+ case .pair(let first, let second):
+ newIndexes.insert(first, at: range.lowerBound)
+ newIndexes.insert(second, at: range.lowerBound + 1)
+ break
+ case .array(let other):
+ newIndexes.insert(contentsOf: other, at: range.lowerBound)
+ break
+ }
+ self = Storage(newIndexes)
+ break
+ }
+ }
+ }
+
+ var count: Int {
+ switch self {
+ case .empty:
+ return 0
+ case .single:
+ return 1
+ case .pair:
+ return 2
+ case .array(let indexes):
+ return indexes.count
+ }
+ }
+
+ var startIndex: Int {
+ return 0
+ }
+
+ var endIndex: Int {
+ return count
+ }
+
+ var allValues: [Int] {
+ switch self {
+ case .empty: return []
+ case .single(let index): return [index]
+ case .pair(let first, let second): return [first, second]
+ case .array(let indexes): return indexes
+ }
+ }
+
+ func index(before i: Int) -> Int {
+ return i - 1
+ }
+
+ func index(after i: Int) -> Int {
+ return i + 1
+ }
+
+ var description: String {
+ switch self {
+ case .empty:
+ return "[]"
+ case .single(let index):
+ return "[\(index)]"
+ case .pair(let first, let second):
+ return "[\(first), \(second)]"
+ case .array(let indexes):
+ return indexes.description
+ }
+ }
+
+ func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<Int>) throws -> R) rethrows -> R {
+ switch self {
+ case .empty:
+ return try body(UnsafeBufferPointer<Int>(start: nil, count: 0))
+ case .single(let index_):
+ var index = index_
+ return try withUnsafePointer(to: &index) { (start) throws -> R in
+ return try body(UnsafeBufferPointer<Int>(start: start, count: 1))
+ }
+ case .pair(let first, let second):
+ var pair = (first, second)
+ return try withUnsafeBytes(of: &pair) { (rawBuffer: UnsafeRawBufferPointer) throws -> R in
+ return try body(UnsafeBufferPointer<Int>(start: rawBuffer.baseAddress?.assumingMemoryBound(to: Int.self), count: 2))
+ }
+ case .array(let indexes):
+ return try indexes.withUnsafeBufferPointer(body)
+ }
+ }
+
+ var debugDescription: String { return description }
+
+ static func +(_ lhs: Storage, _ rhs: Storage) -> Storage {
+ var res = lhs
+ res.append(contentsOf: rhs)
+ return res
+ }
+
+ static func +(_ lhs: Storage, _ rhs: [Int]) -> Storage {
+ var res = lhs
+ res.append(contentsOf: rhs)
+ return res
+ }
+
+ static func ==(_ lhs: Storage, _ rhs: Storage) -> Bool {
+ switch (lhs, rhs) {
+ case (.empty, .empty):
+ return true
+ case (.single(let lhsIndex), .single(let rhsIndex)):
+ return lhsIndex == rhsIndex
+ case (.pair(let lhsFirst, let lhsSecond), .pair(let rhsFirst, let rhsSecond)):
+ return lhsFirst == rhsFirst && lhsSecond == rhsSecond
+ case (.array(let lhsIndexes), .array(let rhsIndexes)):
+ return lhsIndexes == rhsIndexes
+ default:
+ return false
+ }
+ }
+ }
+
+ fileprivate var _indexes : Storage
/// Initialize an empty index path.
public init() {
@@ -34,17 +553,21 @@
/// Initialize with a sequence of integers.
public init<ElementSequence : Sequence>(indexes: ElementSequence)
where ElementSequence.Iterator.Element == Element {
- _indexes = Array(indexes)
+ _indexes = Storage(indexes.map { $0 })
}
/// Initialize with an array literal.
public init(arrayLiteral indexes: Element...) {
- _indexes = indexes
+ _indexes = Storage(indexes)
}
/// Initialize with an array of elements.
- public init(indexes: [Element]) {
- _indexes = indexes
+ public init(indexes: Array<Element>) {
+ _indexes = Storage(indexes)
+ }
+
+ fileprivate init(storage: Storage) {
+ _indexes = storage
}
/// Initialize with a single element.
@@ -54,7 +577,7 @@
/// Return a new `IndexPath` containing all but the last element.
public func dropLast() -> IndexPath {
- return IndexPath(indexes: _indexes.dropLast())
+ return IndexPath(storage: _indexes.dropLast())
}
/// Append an `IndexPath` to `self`.
@@ -68,7 +591,7 @@
}
/// Append an array of elements to `self`.
- public mutating func append(_ other: [Element]) {
+ public mutating func append(_ other: Array<Element>) {
_indexes.append(contentsOf: other)
}
@@ -76,17 +599,17 @@
public func appending(_ other: Element) -> IndexPath {
var result = _indexes
result.append(other)
- return IndexPath(indexes: result)
+ return IndexPath(storage: result)
}
/// Return a new `IndexPath` containing the elements in self and the elements in `other`.
public func appending(_ other: IndexPath) -> IndexPath {
- return IndexPath(indexes: _indexes + other._indexes)
+ return IndexPath(storage: _indexes + other._indexes)
}
/// Return a new `IndexPath` containing the elements in self and the elements in `other`.
- public func appending(_ other: [Element]) -> IndexPath {
- return IndexPath(indexes: _indexes + other)
+ public func appending(_ other: Array<Element>) -> IndexPath {
+ return IndexPath(storage: _indexes + other)
}
public subscript(index: Index) -> Element {
@@ -100,10 +623,10 @@
public subscript(range: Range<Index>) -> IndexPath {
get {
- return IndexPath(indexes: _indexes[range])
+ return IndexPath(storage: _indexes[range])
}
set {
- _indexes.replaceSubrange(range, with: newValue._indexes)
+ _indexes[range] = newValue._indexes
}
}
@@ -132,17 +655,44 @@
}
/// Sorting an array of `IndexPath` using this comparison results in an array representing nodes in depth-first traversal order.
- public func compare(_ other: IndexPath) -> ComparisonResult {
- // This is temporary
- let me = self.makeReference()
- let other = other.makeReference()
- return me.compare(IndexPath._unconditionallyBridgeFromObjectiveC(other))
+ public func compare(_ other: IndexPath) -> ComparisonResult {
+ let thisLength = count
+ let otherLength = other.count
+ let length = Swift.min(thisLength, otherLength)
+ for idx in 0..<length {
+ let otherValue = other[idx]
+ let value = self[idx]
+ if value < otherValue {
+ return .orderedAscending
+ } else if value > otherValue {
+ return .orderedDescending
+ }
+ }
+ if thisLength > otherLength {
+ return .orderedDescending
+ } else if thisLength < otherLength {
+ return .orderedAscending
+ }
+ return .orderedSame
}
public var hashValue: Int {
- // This is temporary
- let me = self.makeReference()
- return me.hash
+ func hashIndexes(first: Int, last: Int, count: Int) -> Int {
+ let totalBits = MemoryLayout<Int>.size * 8
+ let lengthBits = 8
+ let firstIndexBits = (totalBits - lengthBits) / 2
+ return count &+ (first << lengthBits) &+ (last << (lengthBits + firstIndexBits))
+ }
+
+ switch _indexes {
+ case .empty: return 0
+ case .single(let index): return index.hashValue
+ case .pair(let first, let second):
+ return hashIndexes(first: first, last: second, count: 2)
+ default:
+ let cnt = _indexes.count
+ return hashIndexes(first: _indexes[0], last: _indexes[cnt - 1], count: cnt)
+ }
}
// MARK: - Bridging Helpers
@@ -151,49 +701,59 @@
let count = nsIndexPath.length
if count == 0 {
_indexes = []
+ } else if count == 1 {
+ _indexes = .single(nsIndexPath.index(atPosition: 0))
+ } else if count == 2 {
+ _indexes = .pair(nsIndexPath.index(atPosition: 0), nsIndexPath.index(atPosition: 1))
} else {
- var ptr = malloc(count * MemoryLayout<Element>.size)
- defer { free(ptr) }
-
- let elementPtr = ptr!.bindMemory(to: Element.self, capacity: count)
- nsIndexPath.getIndexes(elementPtr, range: NSMakeRange(0, count))
-
- let buffer = UnsafeBufferPointer(start: elementPtr, count: count)
- _indexes = Array(buffer)
+ var indexes = Array<Int>(repeating: 0, count: count)
+ indexes.withUnsafeMutableBufferPointer { (buffer: inout UnsafeMutableBufferPointer<Int>) -> Void in
+ nsIndexPath.getIndexes(buffer.baseAddress!, range: NSRange(location: 0, length: count))
+ }
+ _indexes = .array(indexes)
}
}
fileprivate func makeReference() -> ReferenceType {
- return _indexes.withUnsafeBufferPointer {
- return ReferenceType(indexes: $0.baseAddress, length: $0.count)
+ switch _indexes {
+ case .empty:
+ return ReferenceType()
+ case .single(let index):
+ return ReferenceType(index: index)
+ case .pair(let first, let second):
+ return _NSIndexPathCreateFromIndexes(first, second) as! ReferenceType
+ default:
+ return _indexes.withUnsafeBufferPointer {
+ return ReferenceType(indexes: $0.baseAddress, length: $0.count)
+ }
}
}
public static func ==(lhs: IndexPath, rhs: IndexPath) -> Bool {
return lhs._indexes == rhs._indexes
}
-
+
public static func +(lhs: IndexPath, rhs: IndexPath) -> IndexPath {
return lhs.appending(rhs)
}
-
+
public static func +=(lhs: inout IndexPath, rhs: IndexPath) {
lhs.append(rhs)
}
-
+
public static func <(lhs: IndexPath, rhs: IndexPath) -> Bool {
return lhs.compare(rhs) == ComparisonResult.orderedAscending
}
-
+
public static func <=(lhs: IndexPath, rhs: IndexPath) -> Bool {
let order = lhs.compare(rhs)
return order == ComparisonResult.orderedAscending || order == ComparisonResult.orderedSame
}
-
+
public static func >(lhs: IndexPath, rhs: IndexPath) -> Bool {
return lhs.compare(rhs) == ComparisonResult.orderedDescending
}
-
+
public static func >=(lhs: IndexPath, rhs: IndexPath) -> Bool {
let order = lhs.compare(rhs)
return order == ComparisonResult.orderedDescending || order == ComparisonResult.orderedSame
@@ -204,17 +764,23 @@
public var description: String {
return _indexes.description
}
-
+
public var debugDescription: String {
return _indexes.debugDescription
}
public var customMirror: Mirror {
- return _indexes.customMirror
+ return Mirror(self, unlabeledChildren: self, displayStyle: .collection)
}
}
-extension IndexPath : _ObjectTypeBridgeable {
+#if DEPLOYMENT_RUNTIME_SWIFT
+internal typealias IndexPathBridgeType = _ObjectTypeBridgeable
+#else
+internal typealias IndexPathBridgeType = _ObjectiveCBridgeable
+#endif
+
+extension IndexPath : IndexPathBridgeType {
public static func _getObjectiveCType() -> Any.Type {
return NSIndexPath.self
}
@@ -234,7 +800,8 @@
}
public static func _unconditionallyBridgeFromObjectiveC(_ source: NSIndexPath?) -> IndexPath {
- return IndexPath(nsIndexPath: source!)
+ guard let src = source else { return IndexPath() }
+ return IndexPath(nsIndexPath: src)
}
}
@@ -242,6 +809,46 @@
// Must be @nonobjc to avoid infinite recursion during bridging.
@nonobjc
public func _toCustomAnyHashable() -> AnyHashable? {
- return AnyHashable(IndexPath._unconditionallyBridgeFromObjectiveC(self))
+ return AnyHashable(IndexPath(nsIndexPath: self))
}
}
+
+extension IndexPath : Codable {
+ private enum CodingKeys : Int, CodingKey {
+ case indexes
+ }
+
+ public init(from decoder: Decoder) throws {
+ let container = try decoder.container(keyedBy: CodingKeys.self)
+ var indexesContainer = try container.nestedUnkeyedContainer(forKey: .indexes)
+
+ var indexes = [Int]()
+ if let count = indexesContainer.count {
+ indexes.reserveCapacity(count)
+ }
+
+ while !indexesContainer.isAtEnd {
+ let index = try indexesContainer.decode(Int.self)
+ indexes.append(index)
+ }
+
+ self.init(indexes: indexes)
+ }
+
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.container(keyedBy: CodingKeys.self)
+ var indexesContainer = container.nestedUnkeyedContainer(forKey: .indexes)
+ switch self._indexes {
+ case .empty:
+ break
+ case .single(let index):
+ try indexesContainer.encode(index)
+ case .pair(let first, let second):
+ try indexesContainer.encode(first)
+ try indexesContainer.encode(second)
+ case .array(let indexes):
+ try indexesContainer.encode(contentsOf: indexes)
+ }
+ }
+}
+
diff --git a/Foundation/NSArray.swift b/Foundation/NSArray.swift
index 6f52df9..9c37357 100644
--- a/Foundation/NSArray.swift
+++ b/Foundation/NSArray.swift
@@ -446,9 +446,6 @@
self.enumerateObjects(at: IndexSet(integersIn: 0..<count), options: opts, using: block)
}
open func enumerateObjects(at s: IndexSet, options opts: NSEnumerationOptions = [], using block: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
- guard !opts.contains(.concurrent) else {
- NSUnimplemented()
- }
s._bridgeToObjectiveC().enumerate(options: opts) { (idx, stop) in
block(self.object(at: idx), idx, stop)
}
diff --git a/Foundation/NSConcreteValue.swift b/Foundation/NSConcreteValue.swift
index 6b01414..eccb14e 100644
--- a/Foundation/NSConcreteValue.swift
+++ b/Foundation/NSConcreteValue.swift
@@ -39,7 +39,7 @@
scanner.scanLocation = 1
- guard scanner.scanInteger(&count) && count > 0 else {
+ guard scanner.scanInt(&count) && count > 0 else {
print("NSConcreteValue.TypeInfo: array count is missing or zero")
return nil
}
diff --git a/Foundation/NSDictionary.swift b/Foundation/NSDictionary.swift
index 16ec60e..f331104 100644
--- a/Foundation/NSDictionary.swift
+++ b/Foundation/NSDictionary.swift
@@ -9,7 +9,7 @@
import CoreFoundation
-
+import Dispatch
open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCoding {
private let _cfinfo = _CFInfo(typeID: CFDictionaryGetTypeID())
@@ -454,19 +454,37 @@
enumerateKeysAndObjects(options: [], using: block)
}
- open func enumerateKeysAndObjects(options opts: NSEnumerationOptions = [], using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Swift.Void) {
+ open func enumerateKeysAndObjects(options opts: NSEnumerationOptions = [], using block: (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void) {
let count = self.count
var keys = [Any]()
var objects = [Any]()
+ var sharedStop = ObjCBool(false)
+ let lock = NSLock()
+
getObjects(&objects, andKeys: &keys, count: count)
- var stop = ObjCBool(false)
- for idx in 0..<count {
- withUnsafeMutablePointer(to: &stop, { stop in
- block(keys[idx], objects[idx], stop)
- })
-
- if stop {
- break
+ let iteration: (Int) -> Void = withoutActuallyEscaping(block) { (closure: @escaping (Any, Any, UnsafeMutablePointer<ObjCBool>) -> Void) -> (Int) -> Void in
+ return { (idx) in
+ lock.lock()
+ var stop = sharedStop
+ lock.unlock()
+ if stop { return }
+
+ closure(keys[idx], objects[idx], &stop)
+
+ if stop {
+ lock.lock()
+ sharedStop = stop
+ lock.unlock()
+ return
+ }
+ }
+ }
+
+ if opts.contains(.concurrent) {
+ DispatchQueue.concurrentPerform(iterations: count, execute: iteration)
+ } else {
+ for idx in 0..<count {
+ iteration(idx)
}
}
}
diff --git a/Foundation/NSGeometry.swift b/Foundation/NSGeometry.swift
index 9ac69d2..454014a 100644
--- a/Foundation/NSGeometry.swift
+++ b/Foundation/NSGeometry.swift
@@ -71,7 +71,7 @@
return self.x.hashValue &+ self.y.hashValue
}
- var description: String? {
+ var description: String {
return NSStringFromPoint(self)
}
}
@@ -134,7 +134,7 @@
return self.width.hashValue &+ self.height.hashValue
}
- var description: String? {
+ var description: String {
return NSStringFromSize(self)
}
}
@@ -216,7 +216,7 @@
return self.origin.hash &+ self.size.hash
}
- var description: String? {
+ var description: String {
return NSStringFromRect(self)
}
}
@@ -316,8 +316,8 @@
return self.top.hashValue &+ self.left.hashValue &+ self.bottom.hashValue &+ self.right.hashValue
}
- var description: String? {
- return nil
+ var description: String {
+ return ""
}
}
diff --git a/Foundation/NSIndexSet.swift b/Foundation/NSIndexSet.swift
index 6c5490d..66f2bf5 100644
--- a/Foundation/NSIndexSet.swift
+++ b/Foundation/NSIndexSet.swift
@@ -7,6 +7,7 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
+import Dispatch
/* Class for managing set of indexes. The set of valid indexes are 0 .. NSNotFound - 1; trying to use indexes outside this range is an error. NSIndexSet uses NSNotFound as a return value in cases where the queried index doesn't exist in the set; for instance, when you ask firstIndex and there are no indexes; or when you ask for indexGreaterThanIndex: on the last index, and so on.
@@ -388,36 +389,60 @@
let reverse = opts.contains(.reverse)
let passRanges = paramType == NSRange.self
let findIndex = returnType == Bool.self
- var stop = false
+ var sharedStop = false
+ let lock = NSLock()
let ranges = _ranges[startRangeIndex...endRangeIndex]
- let rangeSequence = (reverse ? AnySequence(ranges.reversed()) : AnySequence(ranges))
- outer: for curRange in rangeSequence {
- let intersection = NSIntersectionRange(curRange, range)
- if passRanges {
- if intersection.length > 0 {
- let _ = block(intersection as! P, &stop)
- }
- if stop {
- break outer
- }
- } else if intersection.length > 0 {
- let maxIndex = NSMaxRange(intersection) - 1
- let indexes = reverse ? stride(from: maxIndex, through: intersection.location, by: -1) : stride(from: intersection.location, through: maxIndex, by: 1)
- for idx in indexes {
- if findIndex {
- let found : Bool = block(idx as! P, &stop) as! Bool
- if found {
- result = idx
- stop = true
- }
- } else {
- let _ = block(idx as! P, &stop)
+ let rangeSequence = (reverse ? AnyCollection(ranges.reversed()) : AnyCollection(ranges))
+ let iteration = withoutActuallyEscaping(block) { (closure: @escaping (P, UnsafeMutablePointer<ObjCBool>) -> R) -> (Int) -> Void in
+ return { (rangeIdx) in
+ lock.lock()
+ var stop = sharedStop
+ lock.unlock()
+ if stop { return }
+
+ let idx = rangeSequence.index(rangeSequence.startIndex, offsetBy: IntMax(rangeIdx))
+ let curRange = rangeSequence[idx]
+ let intersection = NSIntersectionRange(curRange, range)
+ if passRanges {
+ if intersection.length > 0 {
+ let _ = closure(intersection as! P, &stop)
}
if stop {
- break outer
+ lock.lock()
+ sharedStop = stop
+ lock.unlock()
+ return
+ }
+ } else if intersection.length > 0 {
+ let maxIndex = NSMaxRange(intersection) - 1
+ let indexes = reverse ? stride(from: maxIndex, through: intersection.location, by: -1) : stride(from: intersection.location, through: maxIndex, by: 1)
+ for idx in indexes {
+ if findIndex {
+ let found : Bool = closure(idx as! P, &stop) as! Bool
+ if found {
+ result = idx
+ stop = true
+ }
+ } else {
+ let _ = closure(idx as! P, &stop)
+ }
+ if stop {
+ lock.lock()
+ sharedStop = stop
+ lock.unlock()
+ return
+ }
}
}
- } // else, continue
+ }
+ }
+
+ if opts.contains(.concurrent) {
+ DispatchQueue.concurrentPerform(iterations: Int(rangeSequence.count), execute: iteration)
+ } else {
+ for idx in 0..<Int(rangeSequence.count) {
+ iteration(idx)
+ }
}
return result
diff --git a/Foundation/NSKeyedArchiver.swift b/Foundation/NSKeyedArchiver.swift
index 40fc5a5..3790990 100644
--- a/Foundation/NSKeyedArchiver.swift
+++ b/Foundation/NSKeyedArchiver.swift
@@ -755,7 +755,7 @@
scanner.scanLocation = 1 // advance past ObJCType
var count : Int = 0
- guard scanner.scanInteger(&count) && count > 0 else {
+ guard scanner.scanInt(&count) && count > 0 else {
fatalError("NSKeyedArchiver.encodeValueOfObjCType: array count is missing or zero")
}
diff --git a/Foundation/NSKeyedUnarchiver.swift b/Foundation/NSKeyedUnarchiver.swift
index c8feeb5..47fc2f8 100644
--- a/Foundation/NSKeyedUnarchiver.swift
+++ b/Foundation/NSKeyedUnarchiver.swift
@@ -813,7 +813,7 @@
scanner.scanLocation = 1
var count : Int = 0
- guard scanner.scanInteger(&count) && count > 0 else {
+ guard scanner.scanInt(&count) && count > 0 else {
fatalError("NSKeyedUnarchiver.decodeValueOfObjCType: array count is missing or zero")
}
diff --git a/Foundation/NSNumber.swift b/Foundation/NSNumber.swift
index 8900a64..5cc73a6 100644
--- a/Foundation/NSNumber.swift
+++ b/Foundation/NSNumber.swift
@@ -461,9 +461,12 @@
}
open var boolValue: Bool {
- return int64Value != 0
+ // Darwin Foundation NSNumber appears to have a bug and return false for NSNumber(value: Int64.min).boolValue,
+ // even though the documentation says:
+ // "A 0 value always means false, and any nonzero value is interpreted as true."
+ return (int64Value != 0) && (int64Value != Int64.min)
}
-
+
open var intValue: Int {
var val: Int = 0
withUnsafeMutablePointer(to: &val) { (value: UnsafeMutablePointer<Int>) -> Void in
diff --git a/Foundation/NSRange.swift b/Foundation/NSRange.swift
index 5889644..699ebb1 100644
--- a/Foundation/NSRange.swift
+++ b/Foundation/NSRange.swift
@@ -7,11 +7,15 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
+#if DEPLOYMENT_RUNTIME_SWIFT
+
import CoreFoundation
public struct _NSRange {
public var location: Int
public var length: Int
+
+
public init() {
location = 0
length = 0
@@ -21,100 +25,10 @@
self.location = location
self.length = length
}
+}
- internal init(_ range: CFRange) {
- location = range.location == kCFNotFound ? NSNotFound : range.location
- length = range.length
- }
-}
-
-extension CFRange {
- internal init(_ range: NSRange) {
- location = range.location == NSNotFound ? kCFNotFound : range.location
- length = range.length
- }
-}
-
public typealias NSRange = _NSRange
-
-extension NSRange {
- public init(_ x: Range<Int>) {
- location = x.lowerBound
- length = x.count
- }
- public func toRange() -> Range<Int>? {
- if location == NSNotFound { return nil }
- return location..<(location+length)
- }
-
- internal func toCountableRange() -> CountableRange<Int>? {
- if location == NSNotFound { return nil }
- return location..<(location+length)
- }
-}
-
-extension NSRange: NSSpecialValueCoding {
- init(bytes: UnsafeRawPointer) {
- self.location = bytes.load(as: Int.self)
- self.length = bytes.load(fromByteOffset: MemoryLayout<Int>.stride, as: Int.self)
- }
-
- init?(coder aDecoder: NSCoder) {
- guard aDecoder.allowsKeyedCoding else {
- preconditionFailure("Unkeyed coding is unsupported.")
- }
- if let location = aDecoder.decodeObject(of: NSNumber.self, forKey: "NS.rangeval.location") {
- self.location = location.intValue
- } else {
- self.location = 0
- }
- if let length = aDecoder.decodeObject(of: NSNumber.self, forKey: "NS.rangeval.length") {
- self.length = length.intValue
- } else {
- self.length = 0
- }
- }
-
- func encodeWithCoder(_ aCoder: NSCoder) {
- guard aCoder.allowsKeyedCoding else {
- preconditionFailure("Unkeyed coding is unsupported.")
- }
- aCoder.encode(NSNumber(value: self.location), forKey: "NS.rangeval.location")
- aCoder.encode(NSNumber(value: self.length), forKey: "NS.rangeval.length")
- }
-
- static func objCType() -> String {
-#if arch(i386) || arch(arm)
- return "{_NSRange=II}"
-#elseif arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
- return "{_NSRange=QQ}"
-#else
- NSUnimplemented()
-#endif
- }
-
- func getValue(_ value: UnsafeMutableRawPointer) {
- value.initializeMemory(as: NSRange.self, to: self)
- }
-
- func isEqual(_ aValue: Any) -> Bool {
- if let other = aValue as? NSRange {
- return other.location == self.location && other.length == self.length
- } else {
- return false
- }
- }
-
- var hash: Int {
- return self.location &+ self.length
- }
-
- var description: String? {
- return NSStringFromRange(self)
- }
-}
-
public typealias NSRangePointer = UnsafeMutablePointer<NSRange>
public func NSMakeRange(_ loc: Int, _ len: Int) -> NSRange {
@@ -185,7 +99,7 @@
// fail early if there are no decimal digits
return emptyRange
}
- guard let location = scanner.scanInteger() else {
+ guard let location = scanner.scanInt() else {
return emptyRange
}
let partialRange = NSMakeRange(location, 0)
@@ -198,12 +112,308 @@
// return early if there are no integer characters after the first int in the string
return partialRange
}
- guard let length = scanner.scanInteger() else {
+ guard let length = scanner.scanInt() else {
return partialRange
}
return NSMakeRange(location, length)
}
+
+#else
+@_exported import Foundation // Clang module
+#endif
+extension NSRange : Hashable {
+ public var hashValue: Int {
+ #if arch(i386) || arch(arm)
+ return Int(bitPattern: (UInt(bitPattern: location) | (UInt(bitPattern: length) << 16)))
+ #elseif arch(x86_64) || arch(arm64)
+ return Int(bitPattern: (UInt(bitPattern: location) | (UInt(bitPattern: length) << 32)))
+ #endif
+ }
+
+ public static func==(_ lhs: NSRange, _ rhs: NSRange) -> Bool {
+ return lhs.location == rhs.location && lhs.length == rhs.length
+ }
+}
+
+extension NSRange : CustomStringConvertible, CustomDebugStringConvertible {
+ public var description: String { return "{\(location), \(length)}" }
+ public var debugDescription: String {
+ guard location != NSNotFound else {
+ return "{NSNotFound, \(length)}"
+ }
+ return "{\(location), \(length)}"
+ }
+}
+
+extension NSRange {
+ public init?(_ string: String) {
+ var savedLocation = 0
+ if string.isEmpty {
+ // fail early if the string is empty
+ return nil
+ }
+ let scanner = Scanner(string: string)
+ let digitSet = CharacterSet.decimalDigits
+ let _ = scanner.scanUpToCharacters(from: digitSet, into: nil)
+ if scanner.isAtEnd {
+ // fail early if there are no decimal digits
+ return nil
+ }
+ var location = 0
+ savedLocation = scanner.scanLocation
+ guard scanner.scanInt(&location) else {
+ return nil
+ }
+ if scanner.isAtEnd {
+ // return early if there are no more characters after the first int in the string
+ return nil
+ }
+ if scanner.scanString(".", into: nil) {
+ scanner.scanLocation = savedLocation
+ var double = 0.0
+ guard scanner.scanDouble(&double) else {
+ return nil
+ }
+ guard let integral = Int(exactly: double) else {
+ return nil
+ }
+ location = integral
+ }
+
+ let _ = scanner.scanUpToCharacters(from: digitSet, into: nil)
+ if scanner.isAtEnd {
+ // return early if there are no integer characters after the first int in the string
+ return nil
+ }
+ var length = 0
+ savedLocation = scanner.scanLocation
+ guard scanner.scanInt(&length) else {
+ return nil
+ }
+
+ if !scanner.isAtEnd {
+ if scanner.scanString(".", into: nil) {
+ scanner.scanLocation = savedLocation
+ var double = 0.0
+ guard scanner.scanDouble(&double) else {
+ return nil
+ }
+ guard let integral = Int(exactly: double) else {
+ return nil
+ }
+ length = integral
+ }
+ }
+
+
+ self.location = location
+ self.length = length
+ }
+}
+
+extension NSRange {
+ public var lowerBound: Int { return location }
+
+ public var upperBound: Int { return location + length }
+
+ public func contains(_ index: Int) -> Bool { return (!(index < location) && (index - location) < length) }
+
+ public mutating func formUnion(_ other: NSRange) {
+ self = union(other)
+ }
+
+ public func union(_ other: NSRange) -> NSRange {
+ let max1 = location + length
+ let max2 = other.location + other.length
+ let maxend = (max1 < max2) ? max2 : max1
+ let minloc = location < other.location ? location : other.location
+ return NSRange(location: minloc, length: maxend - minloc)
+ }
+
+ public func intersection(_ other: NSRange) -> NSRange? {
+ let max1 = location + length
+ let max2 = other.location + other.length
+ let minend = (max1 < max2) ? max1 : max2
+ if other.location <= location && location < max2 {
+ return NSRange(location: location, length: minend - location)
+ } else if location <= other.location && other.location < max1 {
+ return NSRange(location: other.location, length: minend - other.location);
+ }
+ return nil
+ }
+}
+
+
+//===----------------------------------------------------------------------===//
+// Ranges
+//===----------------------------------------------------------------------===//
+
+extension NSRange {
+ public init<R: RangeExpression>(_ region: R)
+ where R.Bound: FixedWidthInteger, R.Bound.Stride : SignedInteger {
+ let r = region.relative(to: 0..<R.Bound.max)
+ location = numericCast(r.lowerBound)
+ length = numericCast(r.count)
+ }
+
+ public init<R: RangeExpression, S: StringProtocol>(_ region: R, in target: S)
+ where R.Bound == S.Index, S.Index == String.Index {
+ let r = region.relative(to: target)
+ self = NSRange(
+ location: r.lowerBound._utf16Index - target.startIndex._utf16Index,
+ length: r.upperBound._utf16Index - r.lowerBound._utf16Index
+ )
+ }
+
+ @available(swift, deprecated: 4, renamed: "Range.init(_:)")
+ public func toRange() -> Range<Int>? {
+ if location == NSNotFound { return nil }
+ return location..<(location+length)
+ }
+}
+
+extension Range where Bound: BinaryInteger {
+ public init?(_ range: NSRange) {
+ guard range.location != NSNotFound else { return nil }
+ self.init(uncheckedBounds: (numericCast(range.lowerBound), numericCast(range.upperBound)))
+ }
+}
+
+// This additional overload will mean Range.init(_:) defaults to Range<Int> when
+// no additional type context is provided:
+extension Range where Bound == Int {
+ public init?(_ range: NSRange) {
+ guard range.location != NSNotFound else { return nil }
+ self.init(uncheckedBounds: (range.lowerBound, range.upperBound))
+ }
+}
+
+extension Range where Bound == String.Index {
+ public init?(_ range: NSRange, in string: String) {
+ let u = string.utf16
+ guard range.location != NSNotFound,
+ let start = u.index(u.startIndex, offsetBy: range.location, limitedBy: u.endIndex),
+ let end = u.index(u.startIndex, offsetBy: range.location + range.length, limitedBy: u.endIndex),
+ let lowerBound = String.Index(start, within: string),
+ let upperBound = String.Index(end, within: string)
+ else { return nil }
+
+ self = lowerBound..<upperBound
+ }
+}
+
+extension NSRange : CustomReflectable {
+ public var customMirror: Mirror {
+ return Mirror(self, children: ["location": location, "length": length])
+ }
+}
+
+extension NSRange : CustomPlaygroundQuickLookable {
+ public var customPlaygroundQuickLook: PlaygroundQuickLook {
+ return .range(Int64(location), Int64(length))
+ }
+}
+
+extension NSRange : Codable {
+ public init(from decoder: Decoder) throws {
+ var container = try decoder.unkeyedContainer()
+ let location = try container.decode(Int.self)
+ let length = try container.decode(Int.self)
+ self.init(location: location, length: length)
+ }
+
+ public func encode(to encoder: Encoder) throws {
+ var container = encoder.unkeyedContainer()
+ try container.encode(self.location)
+ try container.encode(self.length)
+ }
+}
+
+#if DEPLOYMENT_RUNTIME_SWIFT
+
+
+extension NSRange {
+ internal init(_ range: CFRange) {
+ location = range.location == kCFNotFound ? NSNotFound : range.location
+ length = range.length
+ }
+}
+
+extension CFRange {
+ internal init(_ range: NSRange) {
+ location = range.location == NSNotFound ? kCFNotFound : range.location
+ length = range.length
+ }
+}
+
+extension NSRange {
+ public init(_ x: Range<Int>) {
+ location = x.lowerBound
+ length = x.count
+ }
+
+ internal func toCountableRange() -> CountableRange<Int>? {
+ if location == NSNotFound { return nil }
+ return location..<(location+length)
+ }
+}
+
+extension NSRange: NSSpecialValueCoding {
+ init(bytes: UnsafeRawPointer) {
+ self.location = bytes.load(as: Int.self)
+ self.length = bytes.load(fromByteOffset: MemoryLayout<Int>.stride, as: Int.self)
+ }
+
+ init?(coder aDecoder: NSCoder) {
+ guard aDecoder.allowsKeyedCoding else {
+ preconditionFailure("Unkeyed coding is unsupported.")
+ }
+ if let location = aDecoder.decodeObject(of: NSNumber.self, forKey: "NS.rangeval.location") {
+ self.location = location.intValue
+ } else {
+ self.location = 0
+ }
+ if let length = aDecoder.decodeObject(of: NSNumber.self, forKey: "NS.rangeval.length") {
+ self.length = length.intValue
+ } else {
+ self.length = 0
+ }
+ }
+
+ func encodeWithCoder(_ aCoder: NSCoder) {
+ guard aCoder.allowsKeyedCoding else {
+ preconditionFailure("Unkeyed coding is unsupported.")
+ }
+ aCoder.encode(NSNumber(value: self.location), forKey: "NS.rangeval.location")
+ aCoder.encode(NSNumber(value: self.length), forKey: "NS.rangeval.length")
+ }
+
+ static func objCType() -> String {
+#if arch(i386) || arch(arm)
+ return "{_NSRange=II}"
+#elseif arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
+ return "{_NSRange=QQ}"
+#else
+ NSUnimplemented()
+#endif
+ }
+
+ func getValue(_ value: UnsafeMutableRawPointer) {
+ value.initializeMemory(as: NSRange.self, to: self)
+ }
+
+ func isEqual(_ aValue: Any) -> Bool {
+ if let other = aValue as? NSRange {
+ return other.location == self.location && other.length == self.length
+ } else {
+ return false
+ }
+ }
+
+ var hash: Int { return hashValue }
+}
+
extension NSValue {
public convenience init(range: NSRange) {
self.init()
@@ -215,3 +425,5 @@
return specialValue._value as! NSRange
}
}
+#endif
+
diff --git a/Foundation/NSScanner.swift b/Foundation/NSScanner.swift
index 93b91ea..40da664 100644
--- a/Foundation/NSScanner.swift
+++ b/Foundation/NSScanner.swift
@@ -391,19 +391,19 @@
extension Scanner {
// On overflow, the below methods will return success and clamp
- public func scanInt(_ result: UnsafeMutablePointer<Int32>) -> Bool {
+ public func scanInt32(_ result: UnsafeMutablePointer<Int32>) -> Bool {
return _scanString.scan(_skipSet, locationToScanFrom: &_scanLocation) { (value: Int32) -> Void in
result.pointee = value
}
}
- public func scanInteger(_ result: UnsafeMutablePointer<Int>) -> Bool {
+ public func scanInt(_ result: UnsafeMutablePointer<Int>) -> Bool {
return _scanString.scan(_skipSet, locationToScanFrom: &_scanLocation) { (value: Int) -> Void in
result.pointee = value
}
}
- public func scanLongLong(_ result: UnsafeMutablePointer<Int64>) -> Bool {
+ public func scanInt64(_ result: UnsafeMutablePointer<Int64>) -> Bool {
return _scanString.scan(_skipSet, locationToScanFrom: &_scanLocation) { (value: Int64) -> Void in
result.pointee = value
}
@@ -427,13 +427,13 @@
}
}
- public func scanHexInt(_ result: UnsafeMutablePointer<UInt32>) -> Bool {
+ public func scanHexInt32(_ result: UnsafeMutablePointer<UInt32>) -> Bool {
return _scanString.scanHex(_skipSet, locationToScanFrom: &_scanLocation) { (value: UInt32) -> Void in
result.pointee = value
}
}
- public func scanHexLongLong(_ result: UnsafeMutablePointer<UInt64>) -> Bool {
+ public func scanHexInt64(_ result: UnsafeMutablePointer<UInt64>) -> Bool {
return _scanString.scanHex(_skipSet, locationToScanFrom: &_scanLocation) { (value: UInt64) -> Void in
result.pointee = value
}
@@ -469,9 +469,20 @@
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
extension Scanner {
- public func scanInt() -> Int32? {
+ public func scanInt32() -> Int32? {
var value: Int32 = 0
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int32>) -> Int32? in
+ if scanInt32(ptr) {
+ return ptr.pointee
+ } else {
+ return nil
+ }
+ }
+ }
+
+ public func scanInt() -> Int? {
+ var value: Int = 0
+ return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int>) -> Int? in
if scanInt(ptr) {
return ptr.pointee
} else {
@@ -480,21 +491,10 @@
}
}
- public func scanInteger() -> Int? {
- var value: Int = 0
- return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int>) -> Int? in
- if scanInteger(ptr) {
- return ptr.pointee
- } else {
- return nil
- }
- }
- }
-
- public func scanLongLong() -> Int64? {
+ public func scanInt64() -> Int64? {
var value: Int64 = 0
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int64>) -> Int64? in
- if scanLongLong(ptr) {
+ if scanInt64(ptr) {
return ptr.pointee
} else {
return nil
@@ -535,10 +535,10 @@
}
}
- public func scanHexInt() -> UInt32? {
+ public func scanHexInt32() -> UInt32? {
var value: UInt32 = 0
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<UInt32>) -> UInt32? in
- if scanHexInt(ptr) {
+ if scanHexInt32(ptr) {
return ptr.pointee
} else {
return nil
@@ -546,10 +546,10 @@
}
}
- public func scanHexLongLong() -> UInt64? {
+ public func scanHexInt64() -> UInt64? {
var value: UInt64 = 0
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<UInt64>) -> UInt64? in
- if scanHexLongLong(ptr) {
+ if scanHexInt64(ptr) {
return ptr.pointee
} else {
return nil
@@ -579,9 +579,17 @@
}
}
+ public func scanString(_ string:String, into ptr: UnsafeMutablePointer<String?>?) -> Bool {
+ if let str = scanString(string) {
+ ptr?.pointee = str
+ return true
+ }
+ return false
+ }
+
// These methods avoid calling the private API for _invertedSkipSet and manually re-construct them so that it is only usage of public API usage
// Future implementations on Darwin of these methods will likely be more optimized to take advantage of the cached values.
- public func scanString(string searchString: String) -> String? {
+ public func scanString(_ searchString: String) -> String? {
let str = self.string._bridgeToObjectiveC()
var stringLoc = scanLocation
let stringLen = str.length
@@ -644,6 +652,14 @@
return nil
}
+ public func scanUpToCharacters(from set: CharacterSet, into ptr: UnsafeMutablePointer<String?>?) -> Bool {
+ if let result = scanUpToCharactersFromSet(set) {
+ ptr?.pointee = result
+ return true
+ }
+ return false
+ }
+
public func scanUpToCharactersFromSet(_ set: CharacterSet) -> String? {
let str = self.string._bridgeToObjectiveC()
var stringLoc = scanLocation
diff --git a/Foundation/NSSpecialValue.swift b/Foundation/NSSpecialValue.swift
index 42bc6d9..6809db0 100644
--- a/Foundation/NSSpecialValue.swift
+++ b/Foundation/NSSpecialValue.swift
@@ -25,7 +25,7 @@
// So in order to implement equality and hash we have the hack below.
func isEqual(_ value: Any) -> Bool
var hash: Int { get }
- var description: String? { get }
+ var description: String { get }
}
internal class NSSpecialValue : NSValue {
@@ -126,11 +126,11 @@
}
override var description : String {
- if let description = _value.description {
- return description
- } else {
+ let desc = _value.description
+ if desc.isEmpty {
return super.description
}
+ return desc
}
override func isEqual(_ value: Any?) -> Bool {
diff --git a/Foundation/NSString.swift b/Foundation/NSString.swift
index a444c24..97212d5 100644
--- a/Foundation/NSString.swift
+++ b/Foundation/NSString.swift
@@ -639,18 +639,18 @@
}
public var intValue: Int32 {
- return Scanner(string: _swiftObject).scanInt() ?? 0
+ return Scanner(string: _swiftObject).scanInt32() ?? 0
}
public var integerValue: Int {
let scanner = Scanner(string: _swiftObject)
var value: Int = 0
- let _ = scanner.scanInteger(&value)
+ let _ = scanner.scanInt(&value)
return value
}
public var longLongValue: Int64 {
- return Scanner(string: _swiftObject).scanLongLong() ?? 0
+ return Scanner(string: _swiftObject).scanInt64() ?? 0
}
public var boolValue: Bool {
@@ -658,8 +658,8 @@
// skip initial whitespace if present
let _ = scanner.scanCharactersFromSet(.whitespaces)
// scan a single optional '+' or '-' character, followed by zeroes
- if scanner.scanString(string: "+") == nil {
- let _ = scanner.scanString(string: "-")
+ if scanner.scanString("+") == nil {
+ let _ = scanner.scanString("-")
}
// scan any following zeroes
let _ = scanner.scanCharactersFromSet(CharacterSet(charactersIn: "0"))
diff --git a/Foundation/NSURLProtocol.swift b/Foundation/NSURLProtocol.swift
index bc985cf..74bf665 100644
--- a/Foundation/NSURLProtocol.swift
+++ b/Foundation/NSURLProtocol.swift
@@ -145,98 +145,7 @@
func urlProtocol(_ protocol: URLProtocol, didCancel challenge: URLAuthenticationChallenge)
}
-internal class _ProtocolClient : NSObject, URLProtocolClient {
-
- func urlProtocol(_ protocol: URLProtocol, didReceive response: URLResponse, cacheStoragePolicy policy: URLCache.StoragePolicy) {
- `protocol`.task?.response = response
- }
-
- func urlProtocolDidFinishLoading(_ protocol: URLProtocol) {
- guard let task = `protocol`.task else { fatalError() }
- guard let session = task.session as? URLSession else { fatalError() }
- switch session.behaviour(for: task) {
- case .taskDelegate(let delegate):
- session.delegateQueue.addOperation {
- delegate.urlSession(session, task: task, didCompleteWithError: nil)
- task.state = .completed
- session.taskRegistry.remove(task)
- }
- case .noDelegate:
- task.state = .completed
- session.taskRegistry.remove(task)
- case .dataCompletionHandler:
- let data = Data()
- guard let client = `protocol`.client else { fatalError() }
- client.urlProtocol(`protocol`, didLoad: data)
- return
- case .downloadCompletionHandler(let completion):
- session.delegateQueue.addOperation {
- completion(task.currentRequest?.url, task.response, nil)
- task.state = .completed
- session.taskRegistry.remove(task)
- }
- }
- }
-
- func urlProtocol(_ protocol: URLProtocol, didCancel challenge: URLAuthenticationChallenge) {
- NSUnimplemented()
- }
-
- func urlProtocol(_ protocol: URLProtocol, didReceive challenge: URLAuthenticationChallenge) {
- NSUnimplemented()
- }
-
- func urlProtocol(_ protocol: URLProtocol, didLoad data: Data) {
- guard let task = `protocol`.task else { fatalError() }
- guard let session = task.session as? URLSession else { fatalError() }
- switch session.behaviour(for: task) {
- case .dataCompletionHandler(let completion):
- guard let s = task.session as? URLSession else { fatalError() }
- s.delegateQueue.addOperation {
- completion(data, task.response, nil)
- task.state = .completed
- s.taskRegistry.remove(task)
- }
- default: return
- }
- }
-
- func urlProtocol(_ protocol: URLProtocol, didFailWithError error: Error) {
- guard let task = `protocol`.task else { fatalError() }
- guard let session = task.session as? URLSession else { fatalError() }
- switch session.behaviour(for: task) {
- case .taskDelegate(let delegate):
- session.delegateQueue.addOperation {
- delegate.urlSession(session, task: task, didCompleteWithError: error as Error)
- task.state = .completed
- session.taskRegistry.remove(task)
- }
- case .noDelegate:
- task.state = .completed
- session.taskRegistry.remove(task)
- case .dataCompletionHandler(let completion):
- session.delegateQueue.addOperation {
- completion(nil, nil, error)
- task.state = .completed
- session.taskRegistry.remove(task)
- }
- case .downloadCompletionHandler(let completion):
- session.delegateQueue.addOperation {
- completion(nil, nil, error)
- task.state = .completed
- session.taskRegistry.remove(task)
- }
- }
- }
-
- func urlProtocol(_ protocol: URLProtocol, cachedResponseIsValid cachedResponse: CachedURLResponse) {
- NSUnimplemented()
- }
-
- func urlProtocol(_ protocol: URLProtocol, wasRedirectedTo request: URLRequest, redirectResponse: URLResponse) {
- NSUnimplemented()
- }
-}
+internal class _ProtocolClient : NSObject { }
/*!
@class NSURLProtocol
diff --git a/Foundation/NSURLSession/NSURLSession.swift b/Foundation/NSURLSession/NSURLSession.swift
index 9db5780..c9aa90d 100644
--- a/Foundation/NSURLSession/NSURLSession.swift
+++ b/Foundation/NSURLSession/NSURLSession.swift
@@ -191,7 +191,7 @@
internal let taskRegistry = URLSession._TaskRegistry()
fileprivate let identifier: Int32
fileprivate var invalidated = false
- fileprivate static let registerProtocols = {
+ fileprivate static let registerProtocols: () = {
// TODO: We register all the native protocols here.
let _ = URLProtocol.registerClass(_HTTPURLProtocol.self)
}()
diff --git a/Foundation/NSURLSession/NSURLSessionTask.swift b/Foundation/NSURLSession/NSURLSessionTask.swift
index 3d90128..f843780 100644
--- a/Foundation/NSURLSession/NSURLSessionTask.swift
+++ b/Foundation/NSURLSession/NSURLSessionTask.swift
@@ -522,3 +522,96 @@
/* Key in the userInfo dictionary of an NSError received during a failed download. */
public let URLSessionDownloadTaskResumeData: String = "NSURLSessionDownloadTaskResumeData"
+
+extension _ProtocolClient : URLProtocolClient {
+
+ func urlProtocol(_ protocol: URLProtocol, didReceive response: URLResponse, cacheStoragePolicy policy: URLCache.StoragePolicy) {
+ `protocol`.task?.response = response
+ }
+
+ func urlProtocolDidFinishLoading(_ protocol: URLProtocol) {
+ guard let task = `protocol`.task else { fatalError() }
+ guard let session = task.session as? URLSession else { fatalError() }
+ switch session.behaviour(for: task) {
+ case .taskDelegate(let delegate):
+ session.delegateQueue.addOperation {
+ delegate.urlSession(session, task: task, didCompleteWithError: nil)
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ }
+ case .noDelegate:
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ case .dataCompletionHandler(let completion):
+ let data = Data()
+ guard let client = `protocol`.client else { fatalError() }
+ client.urlProtocol(`protocol`, didLoad: data)
+ return
+ case .downloadCompletionHandler(let completion):
+ session.delegateQueue.addOperation {
+ completion(task.currentRequest?.url, task.response, nil)
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ }
+ }
+ }
+
+ func urlProtocol(_ protocol: URLProtocol, didCancel challenge: URLAuthenticationChallenge) {
+ NSUnimplemented()
+ }
+
+ func urlProtocol(_ protocol: URLProtocol, didReceive challenge: URLAuthenticationChallenge) {
+ NSUnimplemented()
+ }
+
+ func urlProtocol(_ protocol: URLProtocol, didLoad data: Data) {
+ guard let task = `protocol`.task else { fatalError() }
+ guard let session = task.session as? URLSession else { fatalError() }
+ switch session.behaviour(for: task) {
+ case .dataCompletionHandler(let completion):
+ guard let s = task.session as? URLSession else { fatalError() }
+ s.delegateQueue.addOperation {
+ completion(data, task.response, nil)
+ task.state = .completed
+ s.taskRegistry.remove(task)
+ }
+ default: return
+ }
+ }
+
+ func urlProtocol(_ protocol: URLProtocol, didFailWithError error: Error) {
+ guard let task = `protocol`.task else { fatalError() }
+ guard let session = task.session as? URLSession else { fatalError() }
+ switch session.behaviour(for: task) {
+ case .taskDelegate(let delegate):
+ session.delegateQueue.addOperation {
+ delegate.urlSession(session, task: task, didCompleteWithError: error as Error)
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ }
+ case .noDelegate:
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ case .dataCompletionHandler(let completion):
+ session.delegateQueue.addOperation {
+ completion(nil, nil, error)
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ }
+ case .downloadCompletionHandler(let completion):
+ session.delegateQueue.addOperation {
+ completion(nil, nil, error)
+ task.state = .completed
+ session.taskRegistry.remove(task)
+ }
+ }
+ }
+
+ func urlProtocol(_ protocol: URLProtocol, cachedResponseIsValid cachedResponse: CachedURLResponse) {
+ NSUnimplemented()
+ }
+
+ func urlProtocol(_ protocol: URLProtocol, wasRedirectedTo request: URLRequest, redirectResponse: URLResponse) {
+ NSUnimplemented()
+ }
+}
diff --git a/TestFoundation/TestNSAffineTransform.swift b/TestFoundation/TestNSAffineTransform.swift
index cdbffe2..70bac08 100644
--- a/TestFoundation/TestNSAffineTransform.swift
+++ b/TestFoundation/TestNSAffineTransform.swift
@@ -45,18 +45,18 @@
func checkPointTransformation(_ transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = #file, line: UInt = #line) {
let newPoint = transform.transform(point)
- XCTAssertEqualWithAccuracy(Double(newPoint.x), Double(expectedPoint.x), accuracy: accuracyThreshold,
- "x (expected: \(expectedPoint.x), was: \(newPoint.x)): \(message)", file: file, line: line)
- XCTAssertEqualWithAccuracy(Double(newPoint.y), Double(expectedPoint.y), accuracy: accuracyThreshold,
- "y (expected: \(expectedPoint.y), was: \(newPoint.y)): \(message)", file: file, line: line)
+ XCTAssertEqual(Double(newPoint.x), Double(expectedPoint.x), accuracy: accuracyThreshold,
+ "x (expected: \(expectedPoint.x), was: \(newPoint.x)): \(message)", file: file, line: line)
+ XCTAssertEqual(Double(newPoint.y), Double(expectedPoint.y), accuracy: accuracyThreshold,
+ "y (expected: \(expectedPoint.y), was: \(newPoint.y)): \(message)", file: file, line: line)
}
func checkSizeTransformation(_ transform: NSAffineTransform, size: NSSize, expectedSize: NSSize, _ message: String = "", file: StaticString = #file, line: UInt = #line) {
let newSize = transform.transform(size)
- XCTAssertEqualWithAccuracy(Double(newSize.width), Double(expectedSize.width), accuracy: accuracyThreshold,
- "width (expected: \(expectedSize.width), was: \(newSize.width)): \(message)", file: file, line: line)
- XCTAssertEqualWithAccuracy(Double(newSize.height), Double(expectedSize.height), accuracy: accuracyThreshold,
- "height (expected: \(expectedSize.height), was: \(newSize.height)): \(message)", file: file, line: line)
+ XCTAssertEqual(Double(newSize.width), Double(expectedSize.width), accuracy: accuracyThreshold,
+ "width (expected: \(expectedSize.width), was: \(newSize.width)): \(message)", file: file, line: line)
+ XCTAssertEqual(Double(newSize.height), Double(expectedSize.height), accuracy: accuracyThreshold,
+ "height (expected: \(expectedSize.height), was: \(newSize.height)): \(message)", file: file, line: line)
}
func checkRectTransformation(_ transform: NSAffineTransform, rect: NSRect, expectedRect: NSRect, _ message: String = "", file: StaticString = #file, line: UInt = #line) {
@@ -74,13 +74,13 @@
// The diagonal entries (1,1) and (2,2) of the identity matrix are ones. The other entries are zeros.
// TODO: These should use DBL_MAX but it's not available as part of Glibc on Linux
- XCTAssertEqualWithAccuracy(Double(transformStruct.m11), Double(1), accuracy: accuracyThreshold)
- XCTAssertEqualWithAccuracy(Double(transformStruct.m22), Double(1), accuracy: accuracyThreshold)
+ XCTAssertEqual(Double(transformStruct.m11), Double(1), accuracy: accuracyThreshold)
+ XCTAssertEqual(Double(transformStruct.m22), Double(1), accuracy: accuracyThreshold)
- XCTAssertEqualWithAccuracy(Double(transformStruct.m12), Double(0), accuracy: accuracyThreshold)
- XCTAssertEqualWithAccuracy(Double(transformStruct.m21), Double(0), accuracy: accuracyThreshold)
- XCTAssertEqualWithAccuracy(Double(transformStruct.tX), Double(0), accuracy: accuracyThreshold)
- XCTAssertEqualWithAccuracy(Double(transformStruct.tY), Double(0), accuracy: accuracyThreshold)
+ XCTAssertEqual(Double(transformStruct.m12), Double(0), accuracy: accuracyThreshold)
+ XCTAssertEqual(Double(transformStruct.m21), Double(0), accuracy: accuracyThreshold)
+ XCTAssertEqual(Double(transformStruct.tX), Double(0), accuracy: accuracyThreshold)
+ XCTAssertEqual(Double(transformStruct.tY), Double(0), accuracy: accuracyThreshold)
}
func test_IdentityTransformation() {
diff --git a/TestFoundation/TestNSIndexPath.swift b/TestFoundation/TestNSIndexPath.swift
index 320d9e6..018875d 100644
--- a/TestFoundation/TestNSIndexPath.swift
+++ b/TestFoundation/TestNSIndexPath.swift
@@ -21,37 +21,755 @@
static var allTests: [(String, (TestNSIndexPath) -> () throws -> Void)] {
return [
- ("test_BasicConstruction", test_BasicConstruction)
+ ("testEmpty", testEmpty),
+ ("testSingleIndex", testSingleIndex),
+ ("testTwoIndexes", testTwoIndexes),
+ ("testManyIndexes", testManyIndexes),
+ ("testCreateFromSequence", testCreateFromSequence),
+ ("testCreateFromLiteral", testCreateFromLiteral),
+ ("testDropLast", testDropLast),
+ ("testDropLastFromEmpty", testDropLastFromEmpty),
+ ("testDropLastFromSingle", testDropLastFromSingle),
+ ("testDropLastFromPair", testDropLastFromPair),
+ ("testDropLastFromTriple", testDropLastFromTriple),
+ ("testStartEndIndex", testStartEndIndex),
+ ("testIterator", testIterator),
+ ("testIndexing", testIndexing),
+ ("testCompare", testCompare),
+ ("testHashing", testHashing),
+ ("testEquality", testEquality),
+ ("testSubscripting", testSubscripting),
+ ("testAppending", testAppending),
+ ("testAppendEmpty", testAppendEmpty),
+ ("testAppendEmptyIndexPath", testAppendEmptyIndexPath),
+ ("testAppendManyIndexPath", testAppendManyIndexPath),
+ ("testAppendEmptyIndexPathToSingle", testAppendEmptyIndexPathToSingle),
+ ("testAppendSingleIndexPath", testAppendSingleIndexPath),
+ ("testAppendSingleIndexPathToSingle", testAppendSingleIndexPathToSingle),
+ ("testAppendPairIndexPath", testAppendPairIndexPath),
+ ("testAppendManyIndexPathToEmpty", testAppendManyIndexPathToEmpty),
+ ("testAppendByOperator", testAppendByOperator),
+ ("testAppendArray", testAppendArray),
+ ("testRanges", testRanges),
+ ("testRangeFromEmpty", testRangeFromEmpty),
+ ("testRangeFromSingle", testRangeFromSingle),
+ ("testRangeFromPair", testRangeFromPair),
+ ("testRangeFromMany", testRangeFromMany),
+ ("testRangeReplacementSingle", testRangeReplacementSingle),
+ ("testRangeReplacementPair", testRangeReplacementPair),
+ ("testMoreRanges", testMoreRanges),
+ ("testIteration", testIteration),
+ ("testDescription", testDescription),
+ ("testBridgeToObjC", testBridgeToObjC),
+ ("testForceBridgeFromObjC", testForceBridgeFromObjC),
+ ("testConditionalBridgeFromObjC", testConditionalBridgeFromObjC),
+ ("testUnconditionalBridgeFromObjC", testUnconditionalBridgeFromObjC),
+ ("testObjcBridgeType", testObjcBridgeType),
+ ("test_AnyHashableContainingIndexPath", test_AnyHashableContainingIndexPath),
+ ("test_AnyHashableCreatedFromNSIndexPath", test_AnyHashableCreatedFromNSIndexPath),
+ ("test_unconditionallyBridgeFromObjectiveC", test_unconditionallyBridgeFromObjectiveC),
+ ("test_slice_1ary", test_slice_1ary),
]
}
- func test_BasicConstruction() {
- // Test `init()`
- do {
- let path = IndexPath()
- XCTAssertEqual(path.count, 0)
+ func testEmpty() {
+ let ip = IndexPath()
+ XCTAssertEqual(ip.count, 0)
+ }
+
+ func testSingleIndex() {
+ let ip = IndexPath(index: 1)
+ XCTAssertEqual(ip.count, 1)
+ XCTAssertEqual(ip[0], 1)
+
+ let highValueIp = IndexPath(index: .max)
+ XCTAssertEqual(highValueIp.count, 1)
+ XCTAssertEqual(highValueIp[0], .max)
+
+ let lowValueIp = IndexPath(index: .min)
+ XCTAssertEqual(lowValueIp.count, 1)
+ XCTAssertEqual(lowValueIp[0], .min)
+ }
+
+ func testTwoIndexes() {
+ let ip = IndexPath(indexes: [0, 1])
+ XCTAssertEqual(ip.count, 2)
+ XCTAssertEqual(ip[0], 0)
+ XCTAssertEqual(ip[1], 1)
+ }
+
+ func testManyIndexes() {
+ let ip = IndexPath(indexes: [0, 1, 2, 3, 4])
+ XCTAssertEqual(ip.count, 5)
+ XCTAssertEqual(ip[0], 0)
+ XCTAssertEqual(ip[1], 1)
+ XCTAssertEqual(ip[2], 2)
+ XCTAssertEqual(ip[3], 3)
+ XCTAssertEqual(ip[4], 4)
+ }
+
+ func testCreateFromSequence() {
+ let seq = repeatElement(5, count: 3)
+ let ip = IndexPath(indexes: seq)
+ XCTAssertEqual(ip.count, 3)
+ XCTAssertEqual(ip[0], 5)
+ XCTAssertEqual(ip[1], 5)
+ XCTAssertEqual(ip[2], 5)
+ }
+
+ func testCreateFromLiteral() {
+ let ip: IndexPath = [1, 2, 3, 4]
+ XCTAssertEqual(ip.count, 4)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+ XCTAssertEqual(ip[2], 3)
+ XCTAssertEqual(ip[3], 4)
+ }
+
+ func testDropLast() {
+ let ip: IndexPath = [1, 2, 3, 4]
+ let ip2 = ip.dropLast()
+ XCTAssertEqual(ip2.count, 3)
+ XCTAssertEqual(ip2[0], 1)
+ XCTAssertEqual(ip2[1], 2)
+ XCTAssertEqual(ip2[2], 3)
+ }
+
+ func testDropLastFromEmpty() {
+ let ip: IndexPath = []
+ let ip2 = ip.dropLast()
+ XCTAssertEqual(ip2.count, 0)
+ }
+
+ func testDropLastFromSingle() {
+ let ip: IndexPath = [1]
+ let ip2 = ip.dropLast()
+ XCTAssertEqual(ip2.count, 0)
+ }
+
+ func testDropLastFromPair() {
+ let ip: IndexPath = [1, 2]
+ let ip2 = ip.dropLast()
+ XCTAssertEqual(ip2.count, 1)
+ XCTAssertEqual(ip2[0], 1)
+ }
+
+ func testDropLastFromTriple() {
+ let ip: IndexPath = [1, 2, 3]
+ let ip2 = ip.dropLast()
+ XCTAssertEqual(ip2.count, 2)
+ XCTAssertEqual(ip2[0], 1)
+ XCTAssertEqual(ip2[1], 2)
+ }
+
+ func testStartEndIndex() {
+ let ip: IndexPath = [1, 2, 3, 4]
+ XCTAssertEqual(ip.startIndex, 0)
+ XCTAssertEqual(ip.endIndex, ip.count)
+ }
+
+ func testIterator() {
+ let ip: IndexPath = [1, 2, 3, 4]
+ var iter = ip.makeIterator()
+ var sum = 0
+ while let index = iter.next() {
+ sum += index
+ }
+ XCTAssertEqual(sum, 1 + 2 + 3 + 4)
+ }
+
+ func testIndexing() {
+ let ip: IndexPath = [1, 2, 3, 4]
+ XCTAssertEqual(ip.index(before: 1), 0)
+ XCTAssertEqual(ip.index(before: 0), -1) // beyond range!
+ XCTAssertEqual(ip.index(after: 1), 2)
+ XCTAssertEqual(ip.index(after: 4), 5) // beyond range!
+ }
+
+ func testCompare() {
+ let ip1: IndexPath = [1, 2]
+ let ip2: IndexPath = [3, 4]
+ let ip3: IndexPath = [5, 1]
+ let ip4: IndexPath = [1, 1, 1]
+ let ip5: IndexPath = [1, 1, 9]
+
+ XCTAssertEqual(ip1.compare(ip1), ComparisonResult.orderedSame)
+ XCTAssertEqual(ip1 < ip1, false)
+ XCTAssertEqual(ip1 <= ip1, true)
+ XCTAssertEqual(ip1 == ip1, true)
+ XCTAssertEqual(ip1 >= ip1, true)
+ XCTAssertEqual(ip1 > ip1, false)
+
+ XCTAssertEqual(ip1.compare(ip2), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip1 < ip2, true)
+ XCTAssertEqual(ip1 <= ip2, true)
+ XCTAssertEqual(ip1 == ip2, false)
+ XCTAssertEqual(ip1 >= ip2, false)
+ XCTAssertEqual(ip1 > ip2, false)
+
+ XCTAssertEqual(ip1.compare(ip3), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip1 < ip3, true)
+ XCTAssertEqual(ip1 <= ip3, true)
+ XCTAssertEqual(ip1 == ip3, false)
+ XCTAssertEqual(ip1 >= ip3, false)
+ XCTAssertEqual(ip1 > ip3, false)
+
+ XCTAssertEqual(ip1.compare(ip4), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip1 < ip4, false)
+ XCTAssertEqual(ip1 <= ip4, false)
+ XCTAssertEqual(ip1 == ip4, false)
+ XCTAssertEqual(ip1 >= ip4, true)
+ XCTAssertEqual(ip1 > ip4, true)
+
+ XCTAssertEqual(ip1.compare(ip5), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip1 < ip5, false)
+ XCTAssertEqual(ip1 <= ip5, false)
+ XCTAssertEqual(ip1 == ip5, false)
+ XCTAssertEqual(ip1 >= ip5, true)
+ XCTAssertEqual(ip1 > ip5, true)
+
+ XCTAssertEqual(ip2.compare(ip1), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip2 < ip1, false)
+ XCTAssertEqual(ip2 <= ip1, false)
+ XCTAssertEqual(ip2 == ip1, false)
+ XCTAssertEqual(ip2 >= ip1, true)
+ XCTAssertEqual(ip2 > ip1, true)
+
+ XCTAssertEqual(ip2.compare(ip2), ComparisonResult.orderedSame)
+ XCTAssertEqual(ip2 < ip2, false)
+ XCTAssertEqual(ip2 <= ip2, true)
+ XCTAssertEqual(ip2 == ip2, true)
+ XCTAssertEqual(ip2 >= ip2, true)
+ XCTAssertEqual(ip2 > ip2, false)
+
+ XCTAssertEqual(ip2.compare(ip3), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip2 < ip3, true)
+ XCTAssertEqual(ip2 <= ip3, true)
+ XCTAssertEqual(ip2 == ip3, false)
+ XCTAssertEqual(ip2 >= ip3, false)
+ XCTAssertEqual(ip2 > ip3, false)
+
+ XCTAssertEqual(ip2.compare(ip4), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip2.compare(ip5), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip3.compare(ip1), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip3.compare(ip2), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip3.compare(ip3), ComparisonResult.orderedSame)
+ XCTAssertEqual(ip3.compare(ip4), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip3.compare(ip5), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip4.compare(ip1), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip4.compare(ip2), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip4.compare(ip3), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip4.compare(ip4), ComparisonResult.orderedSame)
+ XCTAssertEqual(ip4.compare(ip5), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip5.compare(ip1), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip5.compare(ip2), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip5.compare(ip3), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip5.compare(ip4), ComparisonResult.orderedDescending)
+ XCTAssertEqual(ip5.compare(ip5), ComparisonResult.orderedSame)
+
+ let ip6: IndexPath = [1, 1]
+ XCTAssertEqual(ip6.compare(ip5), ComparisonResult.orderedAscending)
+ XCTAssertEqual(ip5.compare(ip6), ComparisonResult.orderedDescending)
+ }
+
+ func testHashing() {
+ let ip1: IndexPath = [5, 1]
+ let ip2: IndexPath = [1, 1, 1]
+
+ XCTAssertNotEqual(ip1.hashValue, ip2.hashValue)
+
+ IndexPath(indexes: [Int.max >> 8, 2, Int.max >> 36]).hashValue // this should not cause an overflow crash
+ }
+
+ func testEquality() {
+ let ip1: IndexPath = [1, 1]
+ let ip2: IndexPath = [1, 1]
+ let ip3: IndexPath = [1, 1, 1]
+ let ip4: IndexPath = []
+ let ip5: IndexPath = [1]
+
+ XCTAssertTrue(ip1 == ip2)
+ XCTAssertFalse(ip1 == ip3)
+ XCTAssertFalse(ip1 == ip4)
+ XCTAssertFalse(ip4 == ip1)
+ XCTAssertFalse(ip5 == ip1)
+ XCTAssertFalse(ip5 == ip4)
+ XCTAssertTrue(ip4 == ip4)
+ XCTAssertTrue(ip5 == ip5)
+ }
+
+ func testSubscripting() {
+ var ip1: IndexPath = [1]
+ var ip2: IndexPath = [1, 2]
+ var ip3: IndexPath = [1, 2, 3]
+
+ XCTAssertEqual(ip1[0], 1)
+
+ XCTAssertEqual(ip2[0], 1)
+ XCTAssertEqual(ip2[1], 2)
+
+ XCTAssertEqual(ip3[0], 1)
+ XCTAssertEqual(ip3[1], 2)
+ XCTAssertEqual(ip3[2], 3)
+
+ ip1[0] = 2
+ XCTAssertEqual(ip1[0], 2)
+
+ ip2[0] = 2
+ ip2[1] = 3
+ XCTAssertEqual(ip2[0], 2)
+ XCTAssertEqual(ip2[1], 3)
+
+ ip3[0] = 2
+ ip3[1] = 3
+ ip3[2] = 4
+ XCTAssertEqual(ip3[0], 2)
+ XCTAssertEqual(ip3[1], 3)
+ XCTAssertEqual(ip3[2], 4)
+
+ let ip4 = ip3[0..<2]
+ XCTAssertEqual(ip4.count, 2)
+ XCTAssertEqual(ip4[0], 2)
+ XCTAssertEqual(ip4[1], 3)
+ }
+
+ func testAppending() {
+ var ip : IndexPath = [1, 2, 3, 4]
+ let ip2 = IndexPath(indexes: [5, 6, 7])
+
+ ip.append(ip2)
+
+ XCTAssertEqual(ip.count, 7)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[6], 7)
+
+ let ip3 = ip.appending(IndexPath(indexes: [8, 9]))
+ XCTAssertEqual(ip3.count, 9)
+ XCTAssertEqual(ip3[7], 8)
+ XCTAssertEqual(ip3[8], 9)
+
+ let ip4 = ip3.appending([10, 11])
+ XCTAssertEqual(ip4.count, 11)
+ XCTAssertEqual(ip4[9], 10)
+ XCTAssertEqual(ip4[10], 11)
+
+ let ip5 = ip.appending(8)
+ XCTAssertEqual(ip5.count, 8)
+ XCTAssertEqual(ip5[7], 8)
+ }
+
+ func testAppendEmpty() {
+ var ip: IndexPath = []
+ ip.append(1)
+
+ XCTAssertEqual(ip.count, 1)
+ XCTAssertEqual(ip[0], 1)
+
+ ip.append(2)
+ XCTAssertEqual(ip.count, 2)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+
+ ip.append(3)
+ XCTAssertEqual(ip.count, 3)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+ XCTAssertEqual(ip[2], 3)
+
+ ip.append(4)
+ XCTAssertEqual(ip.count, 4)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+ XCTAssertEqual(ip[2], 3)
+ XCTAssertEqual(ip[3], 4)
+ }
+
+ func testAppendEmptyIndexPath() {
+ var ip: IndexPath = []
+ ip.append(IndexPath(indexes: []))
+
+ XCTAssertEqual(ip.count, 0)
+ }
+
+ func testAppendManyIndexPath() {
+ var ip: IndexPath = []
+ ip.append(IndexPath(indexes: [1, 2, 3]))
+
+ XCTAssertEqual(ip.count, 3)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+ XCTAssertEqual(ip[2], 3)
+ }
+
+ func testAppendEmptyIndexPathToSingle() {
+ var ip: IndexPath = [1]
+ ip.append(IndexPath(indexes: []))
+
+ XCTAssertEqual(ip.count, 1)
+ XCTAssertEqual(ip[0], 1)
+ }
+
+ func testAppendSingleIndexPath() {
+ var ip: IndexPath = []
+ ip.append(IndexPath(indexes: [1]))
+
+ XCTAssertEqual(ip.count, 1)
+ XCTAssertEqual(ip[0], 1)
+ }
+
+ func testAppendSingleIndexPathToSingle() {
+ var ip: IndexPath = [1]
+ ip.append(IndexPath(indexes: [1]))
+
+ XCTAssertEqual(ip.count, 2)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 1)
+ }
+
+ func testAppendPairIndexPath() {
+ var ip: IndexPath = []
+ ip.append(IndexPath(indexes: [1, 2]))
+
+ XCTAssertEqual(ip.count, 2)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+ }
+
+ func testAppendManyIndexPathToEmpty() {
+ var ip: IndexPath = []
+ ip.append(IndexPath(indexes: [1, 2, 3]))
+
+ XCTAssertEqual(ip.count, 3)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[1], 2)
+ XCTAssertEqual(ip[2], 3)
+ }
+
+ func testAppendByOperator() {
+ let ip1: IndexPath = []
+ let ip2: IndexPath = []
+
+ let ip3 = ip1 + ip2
+ XCTAssertEqual(ip3.count, 0)
+
+ let ip4: IndexPath = [1]
+ let ip5: IndexPath = [2]
+
+ let ip6 = ip4 + ip5
+ XCTAssertEqual(ip6.count, 2)
+ XCTAssertEqual(ip6[0], 1)
+ XCTAssertEqual(ip6[1], 2)
+
+ var ip7: IndexPath = []
+ ip7 += ip6
+ XCTAssertEqual(ip7.count, 2)
+ XCTAssertEqual(ip7[0], 1)
+ XCTAssertEqual(ip7[1], 2)
+ }
+
+ func testAppendArray() {
+ var ip: IndexPath = [1, 2, 3, 4]
+ let indexes = [5, 6, 7]
+
+ ip.append(indexes)
+
+ XCTAssertEqual(ip.count, 7)
+ XCTAssertEqual(ip[0], 1)
+ XCTAssertEqual(ip[6], 7)
+ }
+
+ func testRanges() {
+ let ip1 = IndexPath(indexes: [1, 2, 3])
+ let ip2 = IndexPath(indexes: [6, 7, 8])
+
+ // Replace the whole range
+ var mutateMe = ip1
+ mutateMe[0..<3] = ip2
+ XCTAssertEqual(mutateMe, ip2)
+
+ // Insert at the beginning
+ mutateMe = ip1
+ mutateMe[0..<0] = ip2
+ XCTAssertEqual(mutateMe, IndexPath(indexes: [6, 7, 8, 1, 2, 3]))
+
+ // Insert at the end
+ mutateMe = ip1
+ mutateMe[3..<3] = ip2
+ XCTAssertEqual(mutateMe, IndexPath(indexes: [1, 2, 3, 6, 7, 8]))
+
+ // Insert in middle
+ mutateMe = ip1
+ mutateMe[2..<2] = ip2
+ XCTAssertEqual(mutateMe, IndexPath(indexes: [1, 2, 6, 7, 8, 3]))
+ }
+
+ func testRangeFromEmpty() {
+ let ip1 = IndexPath()
+ let ip2 = ip1[0..<0]
+ XCTAssertEqual(ip2.count, 0)
+ }
+
+ func testRangeFromSingle() {
+ let ip1 = IndexPath(indexes: [1])
+ let ip2 = ip1[0..<0]
+ XCTAssertEqual(ip2.count, 0)
+ let ip3 = ip1[0..<1]
+ XCTAssertEqual(ip3.count, 1)
+ XCTAssertEqual(ip3[0], 1)
+ }
+
+ func testRangeFromPair() {
+ let ip1 = IndexPath(indexes: [1, 2])
+ let ip2 = ip1[0..<0]
+ XCTAssertEqual(ip2.count, 0)
+ let ip3 = ip1[0..<1]
+ XCTAssertEqual(ip3.count, 1)
+ XCTAssertEqual(ip3[0], 1)
+ let ip4 = ip1[1..<1]
+ XCTAssertEqual(ip4.count, 0)
+ let ip5 = ip1[0..<2]
+ XCTAssertEqual(ip5.count, 2)
+ XCTAssertEqual(ip5[0], 1)
+ XCTAssertEqual(ip5[1], 2)
+ let ip6 = ip1[1..<2]
+ XCTAssertEqual(ip6.count, 1)
+ XCTAssertEqual(ip6[0], 2)
+ let ip7 = ip1[2..<2]
+ XCTAssertEqual(ip7.count, 0)
+ }
+
+ func testRangeFromMany() {
+ let ip1 = IndexPath(indexes: [1, 2, 3])
+ let ip2 = ip1[0..<0]
+ XCTAssertEqual(ip2.count, 0)
+ let ip3 = ip1[0..<1]
+ XCTAssertEqual(ip3.count, 1)
+ let ip4 = ip1[0..<2]
+ XCTAssertEqual(ip4.count, 2)
+ let ip5 = ip1[0..<3]
+ XCTAssertEqual(ip5.count, 3)
+ }
+
+ func testRangeReplacementSingle() {
+ var ip1 = IndexPath(indexes: [1])
+ ip1[0..<1] = IndexPath(indexes: [2])
+ XCTAssertEqual(ip1[0], 2)
+
+ ip1[0..<1] = IndexPath(indexes: [])
+ XCTAssertEqual(ip1.count, 0)
+ }
+
+ func testRangeReplacementPair() {
+ var ip1 = IndexPath(indexes: [1, 2])
+ ip1[0..<1] = IndexPath(indexes: [2, 3])
+ XCTAssertEqual(ip1.count, 3)
+ XCTAssertEqual(ip1[0], 2)
+ XCTAssertEqual(ip1[1], 3)
+ XCTAssertEqual(ip1[2], 2)
+
+ ip1[0..<1] = IndexPath(indexes: [])
+ XCTAssertEqual(ip1.count, 2)
+ }
+
+ func testMoreRanges() {
+ var ip = IndexPath(indexes: [1, 2, 3])
+ let ip2 = IndexPath(indexes: [5, 6, 7, 8, 9, 10])
+
+ ip[1..<2] = ip2
+ XCTAssertEqual(ip, IndexPath(indexes: [1, 5, 6, 7, 8, 9, 10, 3]))
+ }
+
+ func testIteration() {
+ let ip = IndexPath(indexes: [1, 2, 3])
+
+ var count = 0
+ for _ in ip {
+ count += 1
}
- // Test `init(index:)`
- do {
- let path = IndexPath(index: 8)
- XCTAssertEqual(path.count, 1)
-
- let index0 = path[0]
- XCTAssertEqual(index0, 8)
+ XCTAssertEqual(3, count)
+ }
+
+ func testDescription() {
+ let ip1: IndexPath = []
+ let ip2: IndexPath = [1]
+ let ip3: IndexPath = [1, 2]
+ let ip4: IndexPath = [1, 2, 3]
+
+ XCTAssertEqual(ip1.description, "[]")
+ XCTAssertEqual(ip2.description, "[1]")
+ XCTAssertEqual(ip3.description, "[1, 2]")
+ XCTAssertEqual(ip4.description, "[1, 2, 3]")
+
+ XCTAssertEqual(ip1.debugDescription, ip1.description)
+ XCTAssertEqual(ip2.debugDescription, ip2.description)
+ XCTAssertEqual(ip3.debugDescription, ip3.description)
+ XCTAssertEqual(ip4.debugDescription, ip4.description)
+ }
+
+ func testBridgeToObjC() {
+ let ip1: IndexPath = []
+ let ip2: IndexPath = [1]
+ let ip3: IndexPath = [1, 2]
+ let ip4: IndexPath = [1, 2, 3]
+
+ let nsip1 = ip1._bridgeToObjectiveC()
+ let nsip2 = ip2._bridgeToObjectiveC()
+ let nsip3 = ip3._bridgeToObjectiveC()
+ let nsip4 = ip4._bridgeToObjectiveC()
+
+ XCTAssertEqual(nsip1.length, 0)
+ XCTAssertEqual(nsip2.length, 1)
+ XCTAssertEqual(nsip3.length, 2)
+ XCTAssertEqual(nsip4.length, 3)
+ }
+
+ func testForceBridgeFromObjC() {
+ let nsip1 = NSIndexPath()
+ let nsip2 = NSIndexPath(index: 1)
+ let nsip3 = [1, 2].withUnsafeBufferPointer { (buffer: UnsafeBufferPointer<Int>) -> NSIndexPath in
+ return NSIndexPath(indexes: buffer.baseAddress, length: buffer.count)
+ }
+ let nsip4 = [1, 2, 3].withUnsafeBufferPointer { (buffer: UnsafeBufferPointer<Int>) -> NSIndexPath in
+ return NSIndexPath(indexes: buffer.baseAddress, length: buffer.count)
}
- // Test `init(indexes:)`
- do {
- let path = IndexPath(indexes: [1, 2])
- XCTAssertEqual(path.count, 2)
-
- let index0 = path[0]
- XCTAssertEqual(index0, 1)
-
- let index1 = path[1]
- XCTAssertEqual(index1, 2)
+ var ip1: IndexPath? = IndexPath()
+ IndexPath._forceBridgeFromObjectiveC(nsip1, result: &ip1)
+ XCTAssertNotNil(ip1)
+ XCTAssertEqual(ip1!.count, 0)
+
+ var ip2: IndexPath? = IndexPath()
+ IndexPath._forceBridgeFromObjectiveC(nsip2, result: &ip2)
+ XCTAssertNotNil(ip2)
+ XCTAssertEqual(ip2!.count, 1)
+ XCTAssertEqual(ip2![0], 1)
+
+ var ip3: IndexPath? = IndexPath()
+ IndexPath._forceBridgeFromObjectiveC(nsip3, result: &ip3)
+ XCTAssertNotNil(ip3)
+ XCTAssertEqual(ip3!.count, 2)
+ XCTAssertEqual(ip3![0], 1)
+ XCTAssertEqual(ip3![1], 2)
+
+ var ip4: IndexPath? = IndexPath()
+ IndexPath._forceBridgeFromObjectiveC(nsip4, result: &ip4)
+ XCTAssertNotNil(ip4)
+ XCTAssertEqual(ip4!.count, 3)
+ XCTAssertEqual(ip4![0], 1)
+ XCTAssertEqual(ip4![1], 2)
+ XCTAssertEqual(ip4![2], 3)
+ }
+
+ func testConditionalBridgeFromObjC() {
+ let nsip1 = NSIndexPath()
+ let nsip2 = NSIndexPath(index: 1)
+ let nsip3 = [1, 2].withUnsafeBufferPointer { (buffer: UnsafeBufferPointer<Int>) -> NSIndexPath in
+ return NSIndexPath(indexes: buffer.baseAddress, length: buffer.count)
}
+ let nsip4 = [1, 2, 3].withUnsafeBufferPointer { (buffer: UnsafeBufferPointer<Int>) -> NSIndexPath in
+ return NSIndexPath(indexes: buffer.baseAddress, length: buffer.count)
+ }
+
+ var ip1: IndexPath? = IndexPath()
+ XCTAssertTrue(IndexPath._conditionallyBridgeFromObjectiveC(nsip1, result: &ip1))
+ XCTAssertNotNil(ip1)
+ XCTAssertEqual(ip1!.count, 0)
+
+ var ip2: IndexPath? = IndexPath()
+ XCTAssertTrue(IndexPath._conditionallyBridgeFromObjectiveC(nsip2, result: &ip2))
+ XCTAssertNotNil(ip2)
+ XCTAssertEqual(ip2!.count, 1)
+ XCTAssertEqual(ip2![0], 1)
+
+ var ip3: IndexPath? = IndexPath()
+ XCTAssertTrue(IndexPath._conditionallyBridgeFromObjectiveC(nsip3, result: &ip3))
+ XCTAssertNotNil(ip3)
+ XCTAssertEqual(ip3!.count, 2)
+ XCTAssertEqual(ip3![0], 1)
+ XCTAssertEqual(ip3![1], 2)
+
+ var ip4: IndexPath? = IndexPath()
+ XCTAssertTrue(IndexPath._conditionallyBridgeFromObjectiveC(nsip4, result: &ip4))
+ XCTAssertNotNil(ip4)
+ XCTAssertEqual(ip4!.count, 3)
+ XCTAssertEqual(ip4![0], 1)
+ XCTAssertEqual(ip4![1], 2)
+ XCTAssertEqual(ip4![2], 3)
+ }
+
+ func testUnconditionalBridgeFromObjC() {
+ let nsip1 = NSIndexPath()
+ let nsip2 = NSIndexPath(index: 1)
+ let nsip3 = [1, 2].withUnsafeBufferPointer { (buffer: UnsafeBufferPointer<Int>) -> NSIndexPath in
+ return NSIndexPath(indexes: buffer.baseAddress, length: buffer.count)
+ }
+ let nsip4 = [1, 2, 3].withUnsafeBufferPointer { (buffer: UnsafeBufferPointer<Int>) -> NSIndexPath in
+ return NSIndexPath(indexes: buffer.baseAddress, length: buffer.count)
+ }
+
+ let ip1: IndexPath = IndexPath._unconditionallyBridgeFromObjectiveC(nsip1)
+ XCTAssertEqual(ip1.count, 0)
+
+ var ip2: IndexPath = IndexPath._unconditionallyBridgeFromObjectiveC(nsip2)
+ XCTAssertEqual(ip2.count, 1)
+ XCTAssertEqual(ip2[0], 1)
+
+ var ip3: IndexPath = IndexPath._unconditionallyBridgeFromObjectiveC(nsip3)
+ XCTAssertEqual(ip3.count, 2)
+ XCTAssertEqual(ip3[0], 1)
+ XCTAssertEqual(ip3[1], 2)
+
+ var ip4: IndexPath = IndexPath._unconditionallyBridgeFromObjectiveC(nsip4)
+ XCTAssertEqual(ip4.count, 3)
+ XCTAssertEqual(ip4[0], 1)
+ XCTAssertEqual(ip4[1], 2)
+ XCTAssertEqual(ip4[2], 3)
+ }
+
+ func testObjcBridgeType() {
+ XCTAssertTrue(IndexPath._getObjectiveCType() == NSIndexPath.self)
+ }
+
+ func test_AnyHashableContainingIndexPath() {
+ let values: [IndexPath] = [
+ IndexPath(indexes: [1, 2]),
+ IndexPath(indexes: [1, 2, 3]),
+ IndexPath(indexes: [1, 2, 3]),
+ ]
+ let anyHashables = values.map(AnyHashable.init)
+ XCTAssert(IndexPath.self == type(of: anyHashables[0].base))
+ XCTAssert(IndexPath.self == type(of: anyHashables[1].base))
+ XCTAssert(IndexPath.self == type(of: anyHashables[2].base))
+ XCTAssertNotEqual(anyHashables[0], anyHashables[1])
+ XCTAssertEqual(anyHashables[1], anyHashables[2])
+ }
+
+ func test_AnyHashableCreatedFromNSIndexPath() {
+ let values: [NSIndexPath] = [
+ NSIndexPath(index: 1),
+ NSIndexPath(index: 2),
+ NSIndexPath(index: 2),
+ ]
+ let anyHashables = values.map(AnyHashable.init)
+ XCTAssert(IndexPath.self == type(of: anyHashables[0].base))
+ XCTAssert(IndexPath.self == type(of: anyHashables[1].base))
+ XCTAssert(IndexPath.self == type(of: anyHashables[2].base))
+ XCTAssertNotEqual(anyHashables[0], anyHashables[1])
+ XCTAssertEqual(anyHashables[1], anyHashables[2])
+ }
+
+ func test_unconditionallyBridgeFromObjectiveC() {
+ XCTAssertEqual(IndexPath(), IndexPath._unconditionallyBridgeFromObjectiveC(nil))
+ }
+
+ func test_slice_1ary() {
+ let indexPath: IndexPath = [0]
+ let res = indexPath.dropFirst()
+ XCTAssertEqual(0, res.count)
+
+ let slice = indexPath[1..<1]
+ XCTAssertEqual(0, slice.count)
}
}
diff --git a/TestFoundation/TestNSNumber.swift b/TestFoundation/TestNSNumber.swift
index a1ad875..62e16c9 100644
--- a/TestFoundation/TestNSNumber.swift
+++ b/TestFoundation/TestNSNumber.swift
@@ -24,6 +24,13 @@
("test_numberWithChar", test_numberWithChar ),
("test_numberWithUnsignedChar", test_numberWithUnsignedChar ),
("test_numberWithShort", test_numberWithShort ),
+ ("test_numberWithUnsignedShort", test_numberWithUnsignedShort ),
+ ("test_numberWithLong", test_numberWithLong ),
+ ("test_numberWithUnsignedLong", test_numberWithUnsignedLong ),
+ ("test_numberWithLongLong", test_numberWithLongLong ),
+ ("test_numberWithUnsignedLongLong", test_numberWithUnsignedLongLong ),
+ ("test_numberWithInt", test_numberWithInt ),
+ ("test_numberWithUInt", test_numberWithUInt ),
("test_numberWithFloat", test_numberWithFloat ),
("test_numberWithDouble", test_numberWithDouble ),
("test_compareNumberWithBool", test_compareNumberWithBool ),
@@ -154,15 +161,6 @@
}
func test_numberWithUnsignedChar() {
- XCTAssertEqual(NSNumber(value: UInt8(0)).boolValue, false)
- XCTAssertEqual(NSNumber(value: UInt8(0)).int8Value, Int8(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).uint8Value, UInt8(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).int16Value, Int16(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).uint16Value, UInt16(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).int32Value, Int32(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).uint32Value, UInt32(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).int64Value, Int64(0))
- XCTAssertEqual(NSNumber(value: UInt8(0)).uint64Value, UInt64(0))
XCTAssertEqual(NSNumber(value: UInt8(42)).boolValue, true)
XCTAssertEqual(NSNumber(value: UInt8(42)).int8Value, Int8(42))
XCTAssertEqual(NSNumber(value: UInt8(42)).uint8Value, UInt8(42))
@@ -172,27 +170,56 @@
XCTAssertEqual(NSNumber(value: UInt8(42)).uint32Value, UInt32(42))
XCTAssertEqual(NSNumber(value: UInt8(42)).int64Value, Int64(42))
XCTAssertEqual(NSNumber(value: UInt8(42)).uint64Value, UInt64(42))
- XCTAssertEqual(NSNumber(value: UInt8.max).boolValue, true)
- XCTAssertEqual(NSNumber(value: UInt8.max).uint8Value, UInt8.max)
-// XCTAssertEqual(NSNumber(value: UInt8.max).int16Value, Int16(UInt8.max))
-// XCTAssertEqual(NSNumber(value: UInt8.max).uint16Value, UInt16(UInt8.max))
-// XCTAssertEqual(NSNumber(value: UInt8.max).int32Value, Int32(UInt8.max))
-// XCTAssertEqual(NSNumber(value: UInt8.max).uint32Value, UInt32(UInt8.max))
-// XCTAssertEqual(NSNumber(value: UInt8.max).int64Value, Int64(UInt8.max))
-// XCTAssertEqual(NSNumber(value: UInt8.max).uint64Value, UInt64(UInt8.max))
+ XCTAssertEqual(NSNumber(value: UInt8(42)).floatValue, Float(42))
+ XCTAssertEqual(NSNumber(value: UInt8(42)).doubleValue, Double(42))
+
XCTAssertEqual(NSNumber(value: UInt8.min).boolValue, false)
XCTAssertEqual(NSNumber(value: UInt8.min).int8Value, Int8(UInt8.min))
XCTAssertEqual(NSNumber(value: UInt8.min).int16Value, Int16(UInt8.min))
XCTAssertEqual(NSNumber(value: UInt8.min).int32Value, Int32(UInt8.min))
XCTAssertEqual(NSNumber(value: UInt8.min).int64Value, Int64(UInt8.min))
- XCTAssertEqual(NSNumber(value: UInt8(0)).floatValue, Float(0))
- XCTAssertEqual(NSNumber(value: UInt8(42)).floatValue, Float(42))
-// XCTAssertEqual(NSNumber(value: UInt8.max).floatValue, Float(UInt8.max))
XCTAssertEqual(NSNumber(value: UInt8.min).floatValue, Float(UInt8.min))
- XCTAssertEqual(NSNumber(value: UInt8(0)).doubleValue, Double(0))
- XCTAssertEqual(NSNumber(value: UInt8(42)).doubleValue, Double(42))
-// XCTAssertEqual(NSNumber(value: UInt8.max).doubleValue, Double(UInt8.max))
XCTAssertEqual(NSNumber(value: UInt8.min).doubleValue, Double(UInt8.min))
+
+ //--------
+
+ XCTAssertEqual(NSNumber(value: UInt8(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: UInt8(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt8(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt8(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt8(0)).floatValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt8(0)).doubleValue, 0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: UInt8.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: UInt8.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt8.max).int16Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt8.max).int32Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt8.max).int64Value, 255)
+
+ XCTAssertEqual(NSNumber(value: UInt8.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt8.max).uint16Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt8.max).uint32Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt8.max).uint64Value, 255)
+
+ XCTAssertEqual(NSNumber(value: UInt8.max).intValue, 255)
+ XCTAssertEqual(NSNumber(value: UInt8.max).uintValue, 255)
+
+ XCTAssertEqual(NSNumber(value: UInt8.max).floatValue, Float(UInt8.max))
+ XCTAssertEqual(NSNumber(value: UInt8.max).doubleValue, Double(UInt8.max))
}
func test_numberWithShort() {
@@ -227,8 +254,520 @@
XCTAssertEqual(NSNumber(value: Int16(0)).doubleValue, Double(0))
XCTAssertEqual(NSNumber(value: Int16(-37)).doubleValue, Double(-37))
XCTAssertEqual(NSNumber(value: Int16(42)).doubleValue, Double(42))
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int16(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: Int16(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int16(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int16(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: Int16(0)).floatValue, 0)
+ XCTAssertEqual(NSNumber(value: Int16(0)).doubleValue, 0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int16.min).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int16.min).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16.min).int16Value, -32768)
+ XCTAssertEqual(NSNumber(value: Int16.min).int32Value, -32768)
+ XCTAssertEqual(NSNumber(value: Int16.min).int64Value, -32768)
+
+ XCTAssertEqual(NSNumber(value: Int16.min).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int16.min).uint16Value, 32768)
+ XCTAssertEqual(NSNumber(value: Int16.min).uint32Value, 4294934528)
+ XCTAssertEqual(NSNumber(value: Int16.min).uint64Value, 18446744073709518848)
+
+ XCTAssertEqual(NSNumber(value: Int16.min).intValue, -32768)
+ let uintSize = MemoryLayout<UInt>.size
+ switch uintSize {
+ case 4: XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 4294934528)
+ case 8: XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 18446744073709518848)
+ default: XCTFail("Unexpected UInt size: \(uintSize)")
+ }
+
+ XCTAssertEqual(NSNumber(value: Int16.min).floatValue, Float(Int16.min))
+ XCTAssertEqual(NSNumber(value: Int16.min).doubleValue, Double(Int16.min))
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int16.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int16.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: Int16.max).int16Value, 32767)
+ XCTAssertEqual(NSNumber(value: Int16.max).int32Value, 32767)
+ XCTAssertEqual(NSNumber(value: Int16.max).int64Value, 32767)
+
+ XCTAssertEqual(NSNumber(value: Int16.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: Int16.max).uint16Value, 32767)
+ XCTAssertEqual(NSNumber(value: Int16.max).uint32Value, 32767)
+ XCTAssertEqual(NSNumber(value: Int16.max).uint64Value, 32767)
+
+ XCTAssertEqual(NSNumber(value: Int16.max).intValue, 32767)
+ XCTAssertEqual(NSNumber(value: Int16.max).uintValue, 32767)
+
+ XCTAssertEqual(NSNumber(value: Int16.max).floatValue, Float(Int16.max))
+ XCTAssertEqual(NSNumber(value: Int16.max).doubleValue, Double(Int16.max))
}
-
+
+ func test_numberWithUnsignedShort() {
+ XCTAssertEqual(NSNumber(value: UInt16(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: UInt16(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt16(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt16(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt16(0)).floatValue, 0.0)
+ XCTAssertEqual(NSNumber(value: UInt16(0)).doubleValue, 0.0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: UInt16.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: UInt16.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt16.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt16.max).int32Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt16.max).int64Value, 65535)
+
+ XCTAssertEqual(NSNumber(value: UInt16.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt16.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt16.max).uint32Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt16.max).uint64Value, 65535)
+
+ XCTAssertEqual(NSNumber(value: UInt16.max).intValue, 65535)
+ XCTAssertEqual(NSNumber(value: UInt16.max).uintValue, 65535)
+
+ XCTAssertEqual(NSNumber(value: UInt16.max).floatValue, Float(UInt16.max))
+ XCTAssertEqual(NSNumber(value: UInt16.max).doubleValue, Double(UInt16.max))
+ }
+
+ func test_numberWithLong() {
+ XCTAssertEqual(NSNumber(value: Int32(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: Int32(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int32(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int32(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: Int32(0)).floatValue, 0)
+ XCTAssertEqual(NSNumber(value: Int32(0)).doubleValue, 0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int32.min).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int32.min).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32.min).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32.min).int32Value, -2147483648)
+ XCTAssertEqual(NSNumber(value: Int32.min).int64Value, -2147483648)
+
+ XCTAssertEqual(NSNumber(value: Int32.min).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32.min).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int32.min).uint32Value, 2147483648)
+ XCTAssertEqual(NSNumber(value: Int32.min).uint64Value, 18446744071562067968)
+
+ XCTAssertEqual(NSNumber(value: Int32.min).intValue, -2147483648)
+ let uintSize = MemoryLayout<UInt>.size
+ switch uintSize {
+ case 4: XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 2147483648)
+ case 8: XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 18446744071562067968)
+ default: XCTFail("Unexpected UInt size: \(uintSize)")
+ }
+
+ XCTAssertEqual(NSNumber(value: Int32.min).floatValue, Float(Int32.min))
+ XCTAssertEqual(NSNumber(value: Int32.min).doubleValue, Double(Int32.min))
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int32.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int32.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: Int32.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: Int32.max).int32Value, 2147483647)
+ XCTAssertEqual(NSNumber(value: Int32.max).int64Value, 2147483647)
+
+ XCTAssertEqual(NSNumber(value: Int32.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: Int32.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: Int32.max).uint32Value, 2147483647)
+ XCTAssertEqual(NSNumber(value: Int32.max).uint64Value, 2147483647)
+
+ XCTAssertEqual(NSNumber(value: Int32.max).intValue, 2147483647)
+ XCTAssertEqual(NSNumber(value: Int32.max).uintValue, 2147483647)
+
+ XCTAssertEqual(NSNumber(value: Int32.max).floatValue, Float(Int32.max))
+ XCTAssertEqual(NSNumber(value: Int32.max).doubleValue, Double(Int32.max))
+ }
+
+ func test_numberWithUnsignedLong() {
+ XCTAssertEqual(NSNumber(value: UInt32(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: UInt32(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt32(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt32(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt32(0)).floatValue, 0.0)
+ XCTAssertEqual(NSNumber(value: UInt32(0)).doubleValue, 0.0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: UInt32.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: UInt32.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt32.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt32.max).int32Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt32.max).int64Value, 4294967295)
+
+ XCTAssertEqual(NSNumber(value: UInt32.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt32.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt32.max).uint32Value, 4294967295)
+ XCTAssertEqual(NSNumber(value: UInt32.max).uint64Value, 4294967295)
+
+ let intSize = MemoryLayout<Int>.size
+ switch intSize {
+ case 4: XCTAssertEqual(NSNumber(value: UInt32.max).intValue, -1)
+ case 8: XCTAssertEqual(NSNumber(value: UInt32.max).intValue, 4294967295)
+ default: XCTFail("Unexpected Int size: \(intSize)")
+ }
+ XCTAssertEqual(NSNumber(value: UInt32.max).uintValue, 4294967295)
+
+ XCTAssertEqual(NSNumber(value: UInt32.max).floatValue, Float(UInt32.max))
+ XCTAssertEqual(NSNumber(value: UInt32.max).doubleValue, Double(UInt32.max))
+ }
+
+ func test_numberWithLongLong() {
+ XCTAssertEqual(NSNumber(value: Int64(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: Int64(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int64(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int64(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: Int64(0)).floatValue, 0)
+ XCTAssertEqual(NSNumber(value: Int64(0)).doubleValue, 0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int64.min).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: Int64.min).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64.min).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64.min).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64.min).int64Value, -9223372036854775808)
+
+ XCTAssertEqual(NSNumber(value: Int64.min).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64.min).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64.min).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int64.min).uint64Value, 9223372036854775808)
+
+ let intSize = MemoryLayout<Int>.size
+ switch intSize {
+ case 4: XCTAssertEqual(NSNumber(value: Int64.min).intValue, 0)
+ case 8: XCTAssertEqual(NSNumber(value: Int64.min).intValue, -9223372036854775808)
+ default: XCTFail("Unexpected Int size: \(intSize)")
+ }
+
+ let uintSize = MemoryLayout<UInt>.size
+ switch uintSize {
+ case 4: XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 0)
+ case 8: XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 9223372036854775808)
+ default: XCTFail("Unexpected UInt size: \(uintSize)")
+ }
+
+ XCTAssertEqual(NSNumber(value: Int64.min).floatValue, Float(Int64.min))
+ XCTAssertEqual(NSNumber(value: Int64.min).doubleValue, Double(Int64.min))
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: Int64.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int64.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: Int64.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: Int64.max).int32Value, -1)
+ XCTAssertEqual(NSNumber(value: Int64.max).int64Value, 9223372036854775807)
+
+ XCTAssertEqual(NSNumber(value: Int64.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: Int64.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: Int64.max).uint32Value, 4294967295)
+ XCTAssertEqual(NSNumber(value: Int64.max).uint64Value, 9223372036854775807)
+
+ switch intSize {
+ case 4: XCTAssertEqual(NSNumber(value: Int64.max).intValue, -1)
+ case 8: XCTAssertEqual(NSNumber(value: Int64.max).intValue, 9223372036854775807)
+ default: XCTFail("Unexpected Int size: \(intSize)")
+ }
+
+ switch uintSize {
+ case 4: XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 4294967295)
+ case 8: XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 9223372036854775807)
+ default: XCTFail("Unexpected UInt size: \(uintSize)")
+ }
+
+ XCTAssertEqual(NSNumber(value: Int64.max).floatValue, Float(Int64.max))
+ XCTAssertEqual(NSNumber(value: Int64.max).doubleValue, Double(Int64.max))
+ }
+
+ func test_numberWithUnsignedLongLong() {
+ XCTAssertEqual(NSNumber(value: UInt64(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: UInt64(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt64(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt64(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt64(0)).floatValue, 0.0)
+ XCTAssertEqual(NSNumber(value: UInt64(0)).doubleValue, 0.0)
+
+ //------
+
+ XCTAssertEqual(NSNumber(value: UInt64.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: UInt64.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt64.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt64.max).int32Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt64.max).int64Value, -1)
+
+ XCTAssertEqual(NSNumber(value: UInt64.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt64.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt64.max).uint32Value, 4294967295)
+ XCTAssertEqual(NSNumber(value: UInt64.max).uint64Value, 18446744073709551615)
+
+ XCTAssertEqual(NSNumber(value: UInt64.max).intValue, -1)
+ let uintSize = MemoryLayout<UInt>.size
+ switch uintSize {
+ case 4: XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 4294967295)
+ case 8: XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 18446744073709551615)
+ default: XCTFail("Unexpected UInt size: \(uintSize)")
+ }
+
+ XCTAssertEqual(NSNumber(value: UInt64.max).floatValue, Float(UInt64.max))
+ XCTAssertEqual(NSNumber(value: UInt64.max).doubleValue, Double(UInt64.max))
+ }
+
+ func test_numberWithInt() {
+ XCTAssertEqual(NSNumber(value: Int(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: Int(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: Int(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: Int(0)).floatValue, 0)
+ XCTAssertEqual(NSNumber(value: Int(0)).doubleValue, 0)
+
+ //------
+
+ let intSize = MemoryLayout<Int>.size
+ let uintSize = MemoryLayout<UInt>.size
+ switch (intSize, uintSize) {
+ case (4, 4):
+ XCTAssertEqual(NSNumber(value: Int.min).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int.min).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).int32Value, -2147483648)
+ XCTAssertEqual(NSNumber(value: Int.min).int64Value, -2147483648)
+
+ XCTAssertEqual(NSNumber(value: Int.min).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).uint32Value, 2147483648)
+ XCTAssertEqual(NSNumber(value: Int.min).uint64Value, 18446744071562067968)
+
+ XCTAssertEqual(NSNumber(value: Int.min).intValue, -2147483648)
+ XCTAssertEqual(NSNumber(value: Int.min).uintValue, 18446744071562067968)
+
+ XCTAssertEqual(NSNumber(value: Int.min).floatValue, Float(Int.min))
+ XCTAssertEqual(NSNumber(value: Int.min).doubleValue, Double(Int.min))
+
+ //--------
+
+ XCTAssertEqual(NSNumber(value: Int.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: Int.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: Int.max).int32Value, 2147483647)
+ XCTAssertEqual(NSNumber(value: Int.max).int64Value, 2147483647)
+
+ XCTAssertEqual(NSNumber(value: Int.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: Int.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: Int.max).uint32Value, 2147483647)
+ XCTAssertEqual(NSNumber(value: Int.max).uint64Value, 2147483647)
+
+ XCTAssertEqual(NSNumber(value: Int.max).intValue, 2147483647)
+ XCTAssertEqual(NSNumber(value: Int.max).uintValue, 2147483647)
+
+ XCTAssertEqual(NSNumber(value: Int.max).floatValue, Float(Int.max))
+ XCTAssertEqual(NSNumber(value: Int.max).doubleValue, Double(Int.max))
+
+ case (8, 8):
+ XCTAssertEqual(NSNumber(value: Int.min).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: Int.min).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).int64Value, -9223372036854775808)
+
+ XCTAssertEqual(NSNumber(value: Int.min).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: Int.min).uint64Value, 9223372036854775808)
+
+ XCTAssertEqual(NSNumber(value: Int.min).intValue, -9223372036854775808)
+ XCTAssertEqual(NSNumber(value: Int.min).uintValue, 9223372036854775808)
+
+ XCTAssertEqual(NSNumber(value: Int.min).floatValue, Float(Int.min))
+ XCTAssertEqual(NSNumber(value: Int.min).doubleValue, Double(Int.min))
+
+ //--------
+
+ XCTAssertEqual(NSNumber(value: Int.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: Int.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: Int.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: Int.max).int32Value, -1)
+ XCTAssertEqual(NSNumber(value: Int.max).int64Value, 9223372036854775807)
+
+ XCTAssertEqual(NSNumber(value: Int.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: Int.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: Int.max).uint32Value, 4294967295)
+ XCTAssertEqual(NSNumber(value: Int.max).uint64Value, 9223372036854775807)
+
+ XCTAssertEqual(NSNumber(value: Int.max).intValue, 9223372036854775807)
+ XCTAssertEqual(NSNumber(value: Int.max).uintValue, 9223372036854775807)
+
+ XCTAssertEqual(NSNumber(value: Int.max).floatValue, Float(Int.max))
+ XCTAssertEqual(NSNumber(value: Int.max).doubleValue, Double(Int.max))
+
+ default: XCTFail("Unexpected mismatched Int & UInt sizes: \(intSize) & \(uintSize)")
+ }
+ }
+
+ func test_numberWithUInt() {
+ XCTAssertEqual(NSNumber(value: UInt(0)).boolValue, false)
+
+ XCTAssertEqual(NSNumber(value: UInt(0)).int8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).int16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).int32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).int64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt(0)).uint8Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).uint16Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).uint32Value, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).uint64Value, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt(0)).intValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).uintValue, 0)
+
+ XCTAssertEqual(NSNumber(value: UInt(0)).floatValue, 0)
+ XCTAssertEqual(NSNumber(value: UInt(0)).doubleValue, 0)
+
+ //------
+
+ let intSize = MemoryLayout<Int>.size
+ let uintSize = MemoryLayout<UInt>.size
+ switch (intSize, uintSize) {
+ case (4, 4):
+ XCTAssertEqual(NSNumber(value: UInt.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).int32Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).int64Value, 4294967295)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt.max).uint32Value, 4294967295)
+ XCTAssertEqual(NSNumber(value: UInt.max).uint64Value, 4294967295)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).intValue, 4294967295)
+ XCTAssertEqual(NSNumber(value: UInt.max).uintValue, 4294967295)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).floatValue, Float(UInt.max))
+ XCTAssertEqual(NSNumber(value: UInt.max).doubleValue, Double(UInt.max))
+
+ case (8, 8):
+ XCTAssertEqual(NSNumber(value: UInt.max).boolValue, true)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).int8Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).int16Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).int32Value, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).int64Value, -1)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).uint8Value, 255)
+ XCTAssertEqual(NSNumber(value: UInt.max).uint16Value, 65535)
+ XCTAssertEqual(NSNumber(value: UInt.max).uint32Value, 4294967295)
+ XCTAssertEqual(NSNumber(value: UInt.max).uint64Value, 18446744073709551615)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).intValue, -1)
+ XCTAssertEqual(NSNumber(value: UInt.max).uintValue, 18446744073709551615)
+
+ XCTAssertEqual(NSNumber(value: UInt.max).floatValue, Float(UInt.max))
+ XCTAssertEqual(NSNumber(value: UInt.max).doubleValue, Double(UInt.max))
+
+ default: XCTFail("Unexpected mismatched Int & UInt sizes: \(intSize) & \(uintSize)")
+ }
+ }
+
func test_numberWithFloat() {
XCTAssertEqual(NSNumber(value: Float(0)).boolValue, false)
XCTAssertEqual(NSNumber(value: Float(0)).int8Value, Int8(0))
diff --git a/TestFoundation/TestNSProgressFraction.swift b/TestFoundation/TestNSProgressFraction.swift
index 0e42e90..a1e8435 100644
--- a/TestFoundation/TestNSProgressFraction.swift
+++ b/TestFoundation/TestNSProgressFraction.swift
@@ -104,7 +104,7 @@
expectedResult = expectedResult + 1.0 / Double(d)
}
- XCTAssertEqualWithAccuracy(fractionResult, expectedResult, accuracy: 0.00001)
+ XCTAssertEqual(fractionResult, expectedResult, accuracy: 0.00001)
}
func test_addOverflow() {
@@ -126,7 +126,7 @@
// And it should have completed value of about 1.0/4.0 + f1.fractionCompleted
let expected = (1.0 / 4.0) + f1.fractionCompleted
- XCTAssertEqualWithAccuracy(expected, f2.fractionCompleted, accuracy: 0.00001)
+ XCTAssertEqual(expected, f2.fractionCompleted, accuracy: 0.00001)
}
func test_andAndSubtractOverflow() {
diff --git a/TestFoundation/TestNSScanner.swift b/TestFoundation/TestNSScanner.swift
index 4ed0ded..aec488d 100644
--- a/TestFoundation/TestNSScanner.swift
+++ b/TestFoundation/TestNSScanner.swift
@@ -33,7 +33,7 @@
func test_scanInteger() {
let scanner = Scanner(string: "123")
var value: Int = 0
- XCTAssert(scanner.scanInteger(&value), "An Integer should be found in the string `123`.")
+ XCTAssert(scanner.scanInt(&value), "An Integer should be found in the string `123`.")
XCTAssertEqual(value, 123, "Scanned Integer value of the string `123` should be `123`.")
XCTAssertTrue(scanner.isAtEnd)
}
@@ -48,7 +48,7 @@
func test_scanString() {
let scanner = Scanner(string: "apple sauce")
- guard let firstPart = scanner.scanString(string: "apple ") else {
+ guard let firstPart = scanner.scanString("apple ") else {
XCTFail()
return
}
@@ -56,7 +56,7 @@
XCTAssertEqual(firstPart, "apple ")
XCTAssertFalse(scanner.isAtEnd)
- let _ = scanner.scanString(string: "sauce")
+ let _ = scanner.scanString("sauce")
XCTAssertTrue(scanner.isAtEnd)
}
@@ -64,7 +64,7 @@
let scanner = Scanner(string: "xyz ")
scanner.charactersToBeSkipped = .whitespaces
- let _ = scanner.scanString(string: "xyz")
+ let _ = scanner.scanString("xyz")
XCTAssertTrue(scanner.isAtEnd)
}
}
diff --git a/TestFoundation/TestNSTimer.swift b/TestFoundation/TestNSTimer.swift
index 6715ed0..7fcb31d 100644
--- a/TestFoundation/TestNSTimer.swift
+++ b/TestFoundation/TestNSTimer.swift
@@ -59,7 +59,7 @@
XCTAssertEqual(timer.timeInterval, interval)
let currentInterval = Date().timeIntervalSince1970
- XCTAssertEqualWithAccuracy(currentInterval, previousInterval + interval, accuracy: 0.01)
+ XCTAssertEqual(currentInterval, previousInterval + interval, accuracy: 0.01)
previousInterval = currentInterval
flag += 1
diff --git a/TestFoundation/TestProgress.swift b/TestFoundation/TestProgress.swift
index 797058f..f9a9798 100644
--- a/TestFoundation/TestProgress.swift
+++ b/TestFoundation/TestProgress.swift
@@ -44,7 +44,7 @@
// Test self
parent.completedUnitCount = 50
- XCTAssertEqualWithAccuracy(0.5, parent.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(0.5, parent.fractionCompleted, accuracy: 0.01)
parent.completedUnitCount = 0
// Test child
@@ -53,24 +53,24 @@
child1.completedUnitCount = 50
// half of 10% is done in parent
- XCTAssertEqualWithAccuracy(0.05, parent.fractionCompleted, accuracy: 0.01)
- XCTAssertEqualWithAccuracy(0.5, child1.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(0.05, parent.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(0.5, child1.fractionCompleted, accuracy: 0.01)
// Up the total amount of work
parent.totalUnitCount = 200
- XCTAssertEqualWithAccuracy(0.5 * (10.0 / 200.0) /* 0.025 */, parent.fractionCompleted, accuracy: 0.01)
- XCTAssertEqualWithAccuracy(0.5, child1.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(0.5 * (10.0 / 200.0) /* 0.025 */, parent.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(0.5, child1.fractionCompleted, accuracy: 0.01)
// Change the total in the child, doubling total amount of work
child1.totalUnitCount = 200
- XCTAssertEqualWithAccuracy(50.0 / 200.0, child1.fractionCompleted, accuracy: 0.01)
- XCTAssertEqualWithAccuracy((50.0 / 200.0) * (10.0 / 200), parent.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(50.0 / 200.0, child1.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual((50.0 / 200.0) * (10.0 / 200), parent.fractionCompleted, accuracy: 0.01)
// Change the total in the child, the other direction, halving the amount of work
child1.totalUnitCount = 100
- XCTAssertEqualWithAccuracy(50.0 / 100.0, child1.fractionCompleted, accuracy: 0.01)
- XCTAssertEqualWithAccuracy((50.0 / 100.0) * (10.0 / 200), parent.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual(50.0 / 100.0, child1.fractionCompleted, accuracy: 0.01)
+ XCTAssertEqual((50.0 / 100.0) * (10.0 / 200), parent.fractionCompleted, accuracy: 0.01)
}
func test_multipleChildren() {
@@ -84,19 +84,19 @@
let child1 = Progress(totalUnitCount: 5)
let child2 = Progress(totalUnitCount: 5)
- XCTAssertEqualWithAccuracy(progress.fractionCompleted, 0, accuracy: 0.01)
+ XCTAssertEqual(progress.fractionCompleted, 0, accuracy: 0.01)
child2.completedUnitCount = 5
// Child2 does not affect the parent's fraction completed (it should only be child1 that makes a difference)
- XCTAssertEqualWithAccuracy(progress.fractionCompleted, 0, accuracy: 0.01)
+ XCTAssertEqual(progress.fractionCompleted, 0, accuracy: 0.01)
let _ = Progress(totalUnitCount: 5)
- XCTAssertEqualWithAccuracy(progress.fractionCompleted, 0, accuracy: 0.01)
+ XCTAssertEqual(progress.fractionCompleted, 0, accuracy: 0.01)
// Update child #1
child1.completedUnitCount = 5
- XCTAssertEqualWithAccuracy(progress.fractionCompleted, 1.0, accuracy: 0.01)
+ XCTAssertEqual(progress.fractionCompleted, 1.0, accuracy: 0.01)
}
func test_indeterminateChildrenAffectFractionCompleted() {
@@ -107,11 +107,11 @@
let child1 = Progress(totalUnitCount: 10)
child1.completedUnitCount = 5
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.05, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.05, accuracy: 0.01)
// Child1 becomes indeterminate
child1.completedUnitCount = -1
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.0, accuracy: 0.01)
// Become determinate
// childProgress1's completed unit count is 100% of its total of 10 (10)
@@ -119,11 +119,11 @@
// the overall count done should be 100% of 10% of 1000, or 1.0 * 0.1 * 1000 = 100
// the overall percentage done should be 100 / 1000 = 0.1
child1.completedUnitCount = 10
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.1, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.1, accuracy: 0.01)
// Become indeterminate again
child1.completedUnitCount = -1
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.0, accuracy: 0.01)
parent.resignCurrent()
}
@@ -140,21 +140,21 @@
let child2 = Progress(totalUnitCount: 2)
parent.resignCurrent()
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.0, accuracy: 0.01)
child1.completedUnitCount = 1
child2.completedUnitCount = 1
// half done
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.5, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.5, accuracy: 0.01)
// Move a child to indeterminate
child1.completedUnitCount = -1
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.25, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.25, accuracy: 0.01)
// Move it back to determinate
child1.completedUnitCount = 1
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 0.5, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 0.5, accuracy: 0.01)
}
func test_childCompletionFinishesGroups() {
@@ -166,10 +166,10 @@
root.addChild(child2, withPendingUnitCount: 1)
child1.completedUnitCount = 1
- XCTAssertEqualWithAccuracy(root.fractionCompleted, 0.5, accuracy: 0.01)
+ XCTAssertEqual(root.fractionCompleted, 0.5, accuracy: 0.01)
child2.completedUnitCount = 1
- XCTAssertEqualWithAccuracy(root.fractionCompleted, 1.0, accuracy: 0.01)
+ XCTAssertEqual(root.fractionCompleted, 1.0, accuracy: 0.01)
XCTAssertEqual(root.completedUnitCount, 2)
}
@@ -296,11 +296,11 @@
// child1 is half done. This means the parent is half of 1/3 done.
child1.completedUnitCount = 5
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, (1.0 / 3.0) / 2.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, (1.0 / 3.0) / 2.0, accuracy: 0.01)
// child2 is half done. This means the parent is (half of 1/3 done) + (half of 1/3 done).
child2.completedUnitCount = 5
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) * 2.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) * 2.0, accuracy: 0.01)
// add an implict child
parent.becomeCurrent(withPendingUnitCount: 1)
@@ -308,26 +308,26 @@
parent.resignCurrent()
// Total completed of parent should not change
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) * 2.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) * 2.0, accuracy: 0.01)
// child3 is half done. This means the parent is (half of 1/3 done) * 3.
child3.completedUnitCount = 5
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) * 3.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) * 3.0, accuracy: 0.01)
// Finish child3
child3.completedUnitCount = 10
XCTAssertTrue(child3.isFinished)
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, (((1.0 / 3.0) / 2.0) * 2.0) + (1.0 / 3.0), accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, (((1.0 / 3.0) / 2.0) * 2.0) + (1.0 / 3.0), accuracy: 0.01)
// Finish child2
child2.completedUnitCount = 10;
XCTAssertTrue(child2.isFinished)
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) + ((1.0 / 3.0) * 2.0), accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, ((1.0 / 3.0) / 2.0) + ((1.0 / 3.0) * 2.0), accuracy: 0.01)
// Finish child1
child1.completedUnitCount = 10;
XCTAssertTrue(child1.isFinished)
- XCTAssertEqualWithAccuracy(parent.fractionCompleted, 1.0, accuracy: 0.01)
+ XCTAssertEqual(parent.fractionCompleted, 1.0, accuracy: 0.01)
XCTAssertTrue(parent.isFinished)
XCTAssertEqual(parent.completedUnitCount, parent.totalUnitCount)
diff --git a/TestFoundation/TestUnitConverter.swift b/TestFoundation/TestUnitConverter.swift
index 86bf9e1..e03e6bb 100644
--- a/TestFoundation/TestUnitConverter.swift
+++ b/TestFoundation/TestUnitConverter.swift
@@ -86,186 +86,186 @@
return converter.value(fromBaseUnitValue: converter.baseUnitValue(fromValue: 1))
}
- XCTAssertEqualWithAccuracy(testIdentity(UnitAcceleration.metersPerSecondSquared), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAcceleration.gravity), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAcceleration.metersPerSecondSquared), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAcceleration.gravity), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAngle.degrees), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAngle.arcMinutes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAngle.arcSeconds), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAngle.radians), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAngle.gradians), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitAngle.revolutions), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAngle.degrees), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAngle.arcMinutes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAngle.arcSeconds), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAngle.radians), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAngle.gradians), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitAngle.revolutions), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareMegameters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareKilometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareMeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareCentimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareMillimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareMicrometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareNanometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareInches), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareFeet), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareYards), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.squareMiles), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.acres), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.ares), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitArea.hectares), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareMegameters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareKilometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareMeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareCentimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareMillimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareMicrometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareNanometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareInches), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareFeet), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareYards), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.squareMiles), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.acres), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.ares), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitArea.hectares), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitConcentrationMass.gramsPerLiter), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitConcentrationMass.milligramsPerDeciliter), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(
+ XCTAssertEqual(testIdentity(UnitConcentrationMass.gramsPerLiter), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitConcentrationMass.milligramsPerDeciliter), 1, accuracy: delta)
+ XCTAssertEqual(
testIdentity(UnitConcentrationMass.millimolesPerLiter(withGramsPerMole: 1)), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitDispersion.partsPerMillion), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitDispersion.partsPerMillion), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitDuration.seconds), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitDuration.minutes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitDuration.hours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitDuration.seconds), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitDuration.minutes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitDuration.hours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCharge.coulombs), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCharge.megaampereHours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCharge.kiloampereHours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCharge.ampereHours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCharge.milliampereHours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCharge.microampereHours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCharge.coulombs), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCharge.megaampereHours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCharge.kiloampereHours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCharge.ampereHours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCharge.milliampereHours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCharge.microampereHours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCurrent.megaamperes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCurrent.kiloamperes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCurrent.amperes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCurrent.milliamperes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricCurrent.microamperes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCurrent.megaamperes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCurrent.kiloamperes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCurrent.amperes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCurrent.milliamperes), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricCurrent.microamperes), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricPotentialDifference.megavolts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricPotentialDifference.kilovolts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricPotentialDifference.volts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricPotentialDifference.millivolts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricPotentialDifference.microvolts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricPotentialDifference.megavolts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricPotentialDifference.kilovolts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricPotentialDifference.volts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricPotentialDifference.millivolts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricPotentialDifference.microvolts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricResistance.megaohms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricResistance.kiloohms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricResistance.ohms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricResistance.milliohms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitElectricResistance.microohms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricResistance.megaohms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricResistance.kiloohms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricResistance.ohms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricResistance.milliohms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitElectricResistance.microohms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitEnergy.kilojoules), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitEnergy.joules), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitEnergy.kilocalories), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitEnergy.calories), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitEnergy.kilowattHours), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitEnergy.kilojoules), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitEnergy.joules), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitEnergy.kilocalories), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitEnergy.calories), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitEnergy.kilowattHours), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.terahertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.gigahertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.megahertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.kilohertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.hertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.millihertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.microhertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFrequency.nanohertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.terahertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.gigahertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.megahertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.kilohertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.hertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.millihertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.microhertz), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFrequency.nanohertz), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFuelEfficiency.litersPer100Kilometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFuelEfficiency.milesPerImperialGallon), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitFuelEfficiency.milesPerGallon), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFuelEfficiency.litersPer100Kilometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFuelEfficiency.milesPerImperialGallon), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitFuelEfficiency.milesPerGallon), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.megameters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.kilometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.hectometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.decameters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.meters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.decimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.centimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.millimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.micrometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.nanometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.picometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.inches), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.feet), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.yards), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.miles), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.scandinavianMiles), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.nauticalMiles), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.fathoms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.furlongs), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.astronomicalUnits), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitLength.parsecs), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.megameters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.kilometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.hectometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.decameters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.meters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.decimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.centimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.millimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.micrometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.nanometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.picometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.inches), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.feet), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.yards), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.miles), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.scandinavianMiles), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.nauticalMiles), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.fathoms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.furlongs), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.astronomicalUnits), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitLength.parsecs), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitIlluminance.lux), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitIlluminance.lux), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.kilograms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.grams), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.decigrams), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.milligrams), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.nanograms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.picograms), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.ounces), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.pounds), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.stones), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.metricTons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.carats), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.ouncesTroy), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitMass.slugs), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.kilograms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.grams), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.decigrams), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.milligrams), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.nanograms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.picograms), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.ounces), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.pounds), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.stones), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.metricTons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.carats), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.ouncesTroy), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitMass.slugs), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.terawatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.gigawatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.megawatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.kilowatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.watts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.milliwatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.microwatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.nanowatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.picowatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.femtowatts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPower.horsepower), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.terawatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.gigawatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.megawatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.kilowatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.watts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.milliwatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.microwatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.nanowatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.picowatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.femtowatts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPower.horsepower), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.newtonsPerMetersSquared), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.gigapascals), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.megapascals), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.kilopascals), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.hectopascals), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.inchesOfMercury), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.bars), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.millibars), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.millimetersOfMercury), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitPressure.poundsForcePerSquareInch), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.newtonsPerMetersSquared), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.gigapascals), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.megapascals), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.kilopascals), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.hectopascals), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.inchesOfMercury), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.bars), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.millibars), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.millimetersOfMercury), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitPressure.poundsForcePerSquareInch), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitSpeed.metersPerSecond), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitSpeed.kilometersPerHour), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitSpeed.milesPerHour), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitSpeed.knots), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitSpeed.metersPerSecond), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitSpeed.kilometersPerHour), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitSpeed.milesPerHour), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitSpeed.knots), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitTemperature.kelvin), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitTemperature.celsius), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitTemperature.fahrenheit), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitTemperature.kelvin), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitTemperature.celsius), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitTemperature.fahrenheit), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.megaliters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.kiloliters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.liters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.deciliters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.milliliters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicKilometers), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicMeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicDecimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicCentimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicMillimeters), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicInches), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicFeet), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicYards), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cubicMiles), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.acreFeet), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.bushels), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.teaspoons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.tablespoons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.fluidOunces), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.cups), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.pints), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.quarts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.gallons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.imperialTeaspoons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.imperialTablespoons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.imperialFluidOunces), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.imperialPints), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.imperialQuarts), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.imperialGallons), 1, accuracy: delta)
- XCTAssertEqualWithAccuracy(testIdentity(UnitVolume.metricCups), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.megaliters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.kiloliters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.liters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.deciliters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.milliliters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicKilometers), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicMeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicDecimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicCentimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicMillimeters), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicInches), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicFeet), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicYards), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cubicMiles), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.acreFeet), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.bushels), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.teaspoons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.tablespoons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.fluidOunces), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.cups), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.pints), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.quarts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.gallons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.imperialTeaspoons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.imperialTablespoons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.imperialFluidOunces), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.imperialPints), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.imperialQuarts), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.imperialGallons), 1, accuracy: delta)
+ XCTAssertEqual(testIdentity(UnitVolume.metricCups), 1, accuracy: delta)
}
}