Merge pull request #1408 from millenomi/ud-persistent-domains

diff --git a/CoreFoundation/Parsing.subproj/CFXMLInterface.c b/CoreFoundation/Parsing.subproj/CFXMLInterface.c
index 5be8bff..0bac2ae 100644
--- a/CoreFoundation/Parsing.subproj/CFXMLInterface.c
+++ b/CoreFoundation/Parsing.subproj/CFXMLInterface.c
@@ -885,8 +885,7 @@
     xmlXPathObjectPtr evalResult = xmlXPathNodeEval(node, xpath, context);
 
     xmlNodeSetPtr nodes = evalResult->nodesetval;
-    
-    int count = nodes->nodeNr;
+    int count = nodes ? nodes->nodeNr : 0;
 
     CFMutableArrayRef results = CFArrayCreateMutable(NULL, count, NULL);
     for (int i = 0; i < count; i++) {
diff --git a/CoreFoundation/RunLoop.subproj/CFRunLoop.c b/CoreFoundation/RunLoop.subproj/CFRunLoop.c
index da2e573..f179a82 100644
--- a/CoreFoundation/RunLoop.subproj/CFRunLoop.c
+++ b/CoreFoundation/RunLoop.subproj/CFRunLoop.c
@@ -3069,7 +3069,7 @@
     if (__CFMainThreadHasExited && rl == CFRunLoopGetMain()) {
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
-            os_log_error(_CFOSLog(), "Attempting to wake up main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.");
+            os_log_error(_CFOSLog(), "Attempting to wake up main runloop, but the main thread has exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.");
         });
         _CFRunLoopError_MainThreadHasExited();
         return;
@@ -3138,7 +3138,7 @@
     if (__CFMainThreadHasExited && rl == CFRunLoopGetMain()) {
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
-            os_log_error(_CFOSLog(), "Attempting to perform block on main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.");
+            os_log_error(_CFOSLog(), "Attempting to perform block on main runloop, but the main thread has exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug.");
         });
         _CFRunLoopError_MainThreadHasExited();
         return;
@@ -3225,7 +3225,7 @@
     if (__CFMainThreadHasExited && rl == CFRunLoopGetMain()) {
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
-            CFLog(kCFLogLevelError, CFSTR("Attempting to add source to main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug."));
+            CFLog(kCFLogLevelError, CFSTR("Attempting to add source to main runloop, but the main thread has exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug."));
         });
         _CFRunLoopError_MainThreadHasExited();
         return;
@@ -3422,7 +3422,7 @@
     if (__CFMainThreadHasExited && rl == CFRunLoopGetMain()) {
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
-            CFLog(kCFLogLevelError, CFSTR("Attempting to add observer to main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug."));
+            CFLog(kCFLogLevelError, CFSTR("Attempting to add observer to main runloop, but the main thread has exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug."));
         });
         _CFRunLoopError_MainThreadHasExited();
         return;
@@ -3532,7 +3532,7 @@
     if (__CFMainThreadHasExited && rl == CFRunLoopGetMain()) {
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
-            CFLog(kCFLogLevelError, CFSTR("Attempting to add timer to main runloop, but the main thread as exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug."));
+            CFLog(kCFLogLevelError, CFSTR("Attempting to add timer to main runloop, but the main thread has exited. This message will only log once. Break on _CFRunLoopError_MainThreadHasExited to debug."));
         });
         _CFRunLoopError_MainThreadHasExited();
         return;
diff --git a/Foundation/Calendar.swift b/Foundation/Calendar.swift
index 084c5fa..df3f0cc 100644
--- a/Foundation/Calendar.swift
+++ b/Foundation/Calendar.swift
@@ -588,7 +588,7 @@
     public func compare(_ date1: Date, to date2: Date, toUnitGranularity unit: NSCalendar.Unit) -> ComparisonResult { fatalError() }
     
     
-    /// Compares the given dates down to the given component, reporting them `orderedSame` if they are the same in the given component and all larger components, otherwise either `orderedAscending` or `orderedAscending`.
+    /// Compares the given dates down to the given component, reporting them `orderedSame` if they are the same in the given component and all larger components, otherwise either `orderedAscending` or `orderedDescending`.
     ///
     /// - parameter date1: A date to compare.
     /// - parameter date2: A date to compare.
diff --git a/Foundation/Data.swift b/Foundation/Data.swift
index 6035ea7..566657b 100644
--- a/Foundation/Data.swift
+++ b/Foundation/Data.swift
@@ -1005,7 +1005,7 @@
     public typealias Base64DecodingOptions = NSData.Base64DecodingOptions
     
     public typealias Index = Int
-    public typealias Indices = CountableRange<Int>
+    public typealias Indices = Range<Int>
     
     @_versioned internal var _backing : _DataStorage
     @_versioned internal var _sliceRange: Range<Index>
@@ -1546,12 +1546,6 @@
         }
     }
     
-    @inline(__always)
-    public mutating func replaceSubrange(_ subrange: CountableRange<Index>, with data: Data) {
-        let range: Range<Int> = subrange.lowerBound..<subrange.upperBound
-        replaceSubrange(range, with: data)
-    }
-    
     /// Replace a region of bytes in the data with new bytes from a buffer.
     ///
     /// This will resize the data if required, to fit the entire contents of `buffer`.
@@ -1752,7 +1746,7 @@
         return i + 1
     }
     
-    public var indices: CountableRange<Int> {
+    public var indices: Range<Int> {
         @inline(__always)
         get {
             return startIndex..<endIndex
diff --git a/Foundation/ExtraStringAPIs.swift b/Foundation/ExtraStringAPIs.swift
index 6085c22..0bc0414 100644
--- a/Foundation/ExtraStringAPIs.swift
+++ b/Foundation/ExtraStringAPIs.swift
@@ -2,21 +2,28 @@
 //
 // 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
 //
 //===----------------------------------------------------------------------===//
 
-// Random access for String.UTF16View, only when Foundation is
-// imported.  Making this API dependent on Foundation decouples the
-// Swift core from a UTF16 representation.
 extension String.UTF16View.Index {
-    public func advanced(by n: Int) -> String.UTF16View.Index {
-        return String.UTF16View.Index(encodedOffset: encodedOffset.advanced(by: n))
-    }
+  /// Construct from an integer offset.
+  @available(swift, obsoleted: 4.0)
+  public init(_ offset: Int) {
+    fatalError("Unavailable")
+  }
+
+  @available(swift, obsoleted: 4.0)
+  public func distance(to other: String.UTF16View.Index?) -> Int {
+    fatalError("Unavailable")
+  }
+
+  @available(swift, obsoleted: 4.0)
+  public func advanced(by n: Int) -> String.UTF16View.Index {
+    fatalError("Unavailable")
+  }
 }
-
-
diff --git a/Foundation/IndexSet.swift b/Foundation/IndexSet.swift
index 68464c9..74889fa 100644
--- a/Foundation/IndexSet.swift
+++ b/Foundation/IndexSet.swift
@@ -105,7 +105,7 @@
             return IndexingIterator(_elements: self)
         }
         
-        public subscript(index : Index) -> CountableRange<IndexSet.Element> {
+        public subscript(index : Index) -> Range<IndexSet.Element> {
             let indexSetRange = indexSet._range(at: index)
             if let intersectingRange = intersectingRange {
                 return Swift.max(intersectingRange.lowerBound, indexSetRange.lowerBound)..<Swift.min(intersectingRange.upperBound, indexSetRange.upperBound)
@@ -159,11 +159,9 @@
     }
     
     /// Initialize an `IndexSet` with a range of integers.
-    public init(integersIn range: ClosedRange<Element>) { self.init(integersIn: Range(range)) }
-    /// Initialize an `IndexSet` with a range of integers.
-    public init(integersIn range: CountableClosedRange<Element>) { self.init(integersIn: Range(range)) }
-    /// Initialize an `IndexSet` with a range of integers.
-    public init(integersIn range: CountableRange<Element>) { self.init(integersIn: Range(range)) }
+    public init<R: RangeExpression>(integersIn range: R) where R.Bound == Element { 
+      self.init(integersIn: range.relative(to: 0..<Int.max))
+    }
     
     /// Initialize an `IndexSet` with a single integer.
     public init(integer: Element) {
@@ -205,16 +203,9 @@
     /// Returns a `Range`-based view of `self`.
     ///
     /// - parameter range: A subrange of `self` to view.
-    public func rangeView(of range : ClosedRange<Element>) -> RangeView { return self.rangeView(of: Range(range)) }
-    /// Returns a `Range`-based view of `self`.
-    ///
-    /// - parameter range: A subrange of `self` to view.
-    public func rangeView(of range : CountableClosedRange<Element>) -> RangeView { return self.rangeView(of: Range(range)) }
-    /// Returns a `Range`-based view of `self`.
-    ///
-    /// - parameter range: A subrange of `self` to view.
-    public func rangeView(of range : CountableRange<Element>) -> RangeView { return self.rangeView(of: Range(range)) }
-    
+    public func rangeView<R: RangeExpression>(of range : R) -> RangeView where R.Bound == Element { 
+      return self.rangeView(of: range.relative(to: 0..<Int.max)) 
+    }    
     
     private func _indexOfRange(containing integer : Element) -> RangeView.Index? {
         let result = _handle.map {
@@ -344,20 +335,9 @@
     /// The resulting range is the range of the intersection of the integers in `range` with the index set.
     ///
     /// - parameter range: The range of integers to include.
-    public func indexRange(in range: CountableRange<Element>) -> Range<Index> { return self.indexRange(in: Range(range)) }
-    /// Return a `Range<IndexSet.Index>` which can be used to subscript the index set.
-    ///
-    /// The resulting range is the range of the intersection of the integers in `range` with the index set.
-    ///
-    /// - parameter range: The range of integers to include.
-    public func indexRange(in range: ClosedRange<Element>) -> Range<Index> { return self.indexRange(in: Range(range)) }
-    /// Return a `Range<IndexSet.Index>` which can be used to subscript the index set.
-    ///
-    /// The resulting range is the range of the intersection of the integers in `range` with the index set.
-    ///
-    /// - parameter range: The range of integers to include.
-    public func indexRange(in range: CountableClosedRange<Element>) -> Range<Index> { return self.indexRange(in: Range(range)) }
-    
+    public func indexRange<R: RangeExpression>(in range: R) -> Range<Index> where R.Bound == Element { 
+      return self.indexRange(in: range.relative(to: 0..<Int.max))
+    }
     
     /// Returns the count of integers in `self` that intersect `range`.
     public func count(in range: Range<Element>) -> Int {
@@ -365,11 +345,9 @@
     }
     
     /// Returns the count of integers in `self` that intersect `range`.
-    public func count(in range: CountableRange<Element>) -> Int { return self.count(in: Range(range)) }
-    /// Returns the count of integers in `self` that intersect `range`.
-    public func count(in range: ClosedRange<Element>) -> Int { return self.count(in: Range(range)) }
-    /// Returns the count of integers in `self` that intersect `range`.
-    public func count(in range: CountableClosedRange<Element>) -> Int { return self.count(in: Range(range)) }
+    public func count<R: RangeExpression>(in range: R) -> Int where R.Bound == Element { 
+      return self.count(in: range.relative(to: 0..<Int.max))
+    }
     
     /// Returns `true` if `self` contains `integer`.
     public func contains(_ integer: Element) -> Bool {
@@ -382,12 +360,9 @@
     }
     
     /// Returns `true` if `self` contains all of the integers in `range`.
-    public func contains(integersIn range: CountableRange<Element>) -> Bool { return self.contains(integersIn: Range(range)) }
-    /// Returns `true` if `self` contains all of the integers in `range`.
-    public func contains(integersIn range: ClosedRange<Element>) -> Bool { return self.contains(integersIn: Range(range)) }
-    /// Returns `true` if `self` contains all of the integers in `range`.
-    public func contains(integersIn range: CountableClosedRange<Element>) -> Bool { return self.contains(integersIn: Range(range)) }
-    
+    public func contains<R: RangeExpression>(integersIn range: R) -> Bool where R.Bound == Element { 
+      return self.contains(integersIn: range.relative(to: 0..<Int.max))
+    }
     
     /// Returns `true` if `self` contains all of the integers in `indexSet`.
     public func contains(integersIn indexSet: IndexSet) -> Bool {
@@ -400,11 +375,9 @@
     }
     
     /// Returns `true` if `self` intersects any of the integers in `range`.
-    public func intersects(integersIn range: CountableRange<Element>) -> Bool { return self.intersects(integersIn: Range(range)) }
-    /// Returns `true` if `self` intersects any of the integers in `range`.
-    public func intersects(integersIn range: ClosedRange<Element>) -> Bool { return self.intersects(integersIn: Range(range)) }
-    /// Returns `true` if `self` intersects any of the integers in `range`.
-    public func intersects(integersIn range: CountableClosedRange<Element>) -> Bool { return self.intersects(integersIn: Range(range)) }
+    public func intersects<R: RangeExpression>(integersIn range: R) -> Bool where R.Bound == Element { 
+      return self.intersects(integersIn: range.relative(to: 0..<Int.max))
+    }
     
     // MARK: -
     // Collection
@@ -490,7 +463,7 @@
         } else {
             let extent = 0..<0
             let rangeIndex = 0
-            return Index(value: value, extent: Range(extent), rangeIndex: rangeIndex, rangeCount: rangeCount)
+            return Index(value: value, extent: extent, rangeIndex: rangeIndex, rangeCount: rangeCount)
         }
     }
     
@@ -508,11 +481,11 @@
         
         var result = IndexSet()
         for r in self.rangeView {
-            result.insert(integersIn: Range(r))
+            result.insert(integersIn: r)
         }
         
         for r in other.rangeView {
-            result.insert(integersIn: Range(r))
+            result.insert(integersIn: r)
         }
         return result
     }
@@ -619,11 +592,9 @@
     }
     
     /// Insert a range of integers into the `IndexSet`.
-    public mutating func insert(integersIn range: CountableRange<Element>) { self.insert(integersIn: Range(range)) }
-    /// Insert a range of integers into the `IndexSet`.
-    public mutating func insert(integersIn range: ClosedRange<Element>) { self.insert(integersIn: Range(range)) }
-    /// Insert a range of integers into the `IndexSet`.
-    public mutating func insert(integersIn range: CountableClosedRange<Element>) { self.insert(integersIn: Range(range)) }
+    public mutating func insert<R: RangeExpression>(integersIn range: R) where R.Bound == Element { 
+      self.insert(integersIn: range.relative(to: 0..<Int.max))
+    }
     
     /// Remove a range of integers from the `IndexSet`.
     public mutating func remove(integersIn range: Range<Element>) {
@@ -631,11 +602,9 @@
     }
     
     /// Remove a range of integers from the `IndexSet`.
-    public mutating func remove(integersIn range: CountableRange<Element>) { self.remove(integersIn: Range(range)) }
-    /// Remove a range of integers from the `IndexSet`.
-    public mutating func remove(integersIn range: ClosedRange<Element>) { self.remove(integersIn: Range(range)) }
-    /// Remove a range of integers from the `IndexSet`.
-    public mutating func remove(integersIn range: CountableClosedRange<Element>) { self.remove(integersIn: Range(range)) }
+    public mutating func remove(integersIn range: ClosedRange<Element>) { 
+      self.remove(integersIn: Range(range))
+    }
     
     /// Returns `true` if self contains no values.
     public var isEmpty : Bool {
@@ -672,17 +641,9 @@
     ///
     /// - parameter range: A range of integers. For each integer in the range that intersects the integers in the IndexSet, then the `includeInteger` predicate will be invoked.
     /// - parameter includeInteger: The predicate which decides if an integer will be included in the result or not.
-    public func filteredIndexSet(in range : CountableRange<Element>, includeInteger: (Element) throws -> Bool) rethrows -> IndexSet { return try self.filteredIndexSet(in: Range(range), includeInteger: includeInteger) }
-    /// Returns an IndexSet filtered according to the result of `includeInteger`.
-    ///
-    /// - parameter range: A range of integers. For each integer in the range that intersects the integers in the IndexSet, then the `includeInteger` predicate will be invoked.
-    /// - parameter includeInteger: The predicate which decides if an integer will be included in the result or not.
-    public func filteredIndexSet(in range : ClosedRange<Element>, includeInteger: (Element) throws -> Bool) rethrows -> IndexSet { return try self.filteredIndexSet(in: Range(range), includeInteger: includeInteger) }
-    /// Returns an IndexSet filtered according to the result of `includeInteger`.
-    ///
-    /// - parameter range: A range of integers. For each integer in the range that intersects the integers in the IndexSet, then the `includeInteger` predicate will be invoked.
-    /// - parameter includeInteger: The predicate which decides if an integer will be included in the result or not.
-    public func filteredIndexSet(in range : CountableClosedRange<Element>, includeInteger: (Element) throws -> Bool) rethrows -> IndexSet { return try self.filteredIndexSet(in: Range(range), includeInteger: includeInteger) }
+    public func filteredIndexSet(in range : ClosedRange<Element>, includeInteger: (Element) throws -> Bool) rethrows -> IndexSet { 
+      return try self.filteredIndexSet(in: Range(range), includeInteger: includeInteger) 
+    }
     
     /// Returns an IndexSet filtered according to the result of `includeInteger`.
     ///
@@ -692,7 +653,7 @@
     }
     
     /// For a positive delta, shifts the indexes in [index, INT_MAX] to the right, thereby inserting an "empty space" [index, delta], for a negative delta, shifts the indexes in [index, INT_MAX] to the left, thereby deleting the indexes in the range [index - delta, delta].
-    public mutating func shift(startingAt integer: Element, by delta: IndexSet.IndexDistance) {
+    public mutating func shift(startingAt integer: Element, by delta: Int) {
         _applyMutation { $0.shiftIndexesStarting(at: integer, by: delta) }
     }
     
@@ -762,8 +723,8 @@
     
     private var i1: IndexSet.RangeView.Iterator
     private var i2: IndexSet.RangeView.Iterator
-    private var i1Range: CountableRange<Element>?
-    private var i2Range: CountableRange<Element>?
+    private var i1Range: Range<Element>?
+    private var i2Range: Range<Element>?
     private var i1UsedLower: Bool
     private var i2UsedLower: Bool
     
@@ -970,4 +931,3 @@
         }
     }
 }
-
diff --git a/Foundation/NSArray.swift b/Foundation/NSArray.swift
index d53b42e..0403c30 100644
--- a/Foundation/NSArray.swift
+++ b/Foundation/NSArray.swift
@@ -934,9 +934,6 @@
     open func sort(options opts: NSSortOptions = [], usingComparator cmptr: Comparator) {
         self.setArray(self.sortedArray(options: opts, usingComparator: cmptr))
     }
-    
-    public convenience init?(contentsOfFile path: String) { NSUnimplemented() }
-    public convenience init?(contentsOfURL url: URL) { NSUnimplemented() }
 }
 
 extension NSArray : Sequence {
diff --git a/Foundation/NSCFString.swift b/Foundation/NSCFString.swift
index 46f90f2..92177ca 100644
--- a/Foundation/NSCFString.swift
+++ b/Foundation/NSCFString.swift
@@ -167,7 +167,7 @@
         if let buffer = buffer {
             for idx in 0..<range.length {
                 // Since character is 2 bytes but the buffer is in term of 1 byte values, we have to split it up
-                let character = encodingView[start.advanced(by: idx + range.location)]
+                let character = encodingView[encodingView.index(start, offsetBy: idx + range.location)]
 #if _endian(big)
                 let byte0 = UInt8((character >> 8) & 0x00ff)
                 let byte1 = UInt8(character & 0x00ff)
diff --git a/Foundation/NSRegularExpression.swift b/Foundation/NSRegularExpression.swift
index e1f9625..73dc6de 100644
--- a/Foundation/NSRegularExpression.swift
+++ b/Foundation/NSRegularExpression.swift
@@ -258,8 +258,8 @@
             let currentRange = result.range
             let replacement = replacementString(for: result, in: string, offset: 0, template: templ)
             if currentRange.location > NSMaxRange(previousRange) {
-                let min = start.advanced(by: NSMaxRange(previousRange))
-                let max = start.advanced(by: currentRange.location)
+                let min = string.utf16.index(start, offsetBy: NSMaxRange(previousRange))
+                let max = string.utf16.index(start, offsetBy: currentRange.location)
                 str += String(string.utf16[min..<max])!
             }
             str += replacement
@@ -267,8 +267,8 @@
         }
         
         if length > NSMaxRange(previousRange) {
-            let min = start.advanced(by: NSMaxRange(previousRange))
-            let max = start.advanced(by: length)
+            let min = string.utf16.index(start, offsetBy: NSMaxRange(previousRange))
+            let max = string.utf16.index(start, offsetBy: length)
             str += String(string.utf16[min..<max])!
         }
         
@@ -344,8 +344,8 @@
                         }
                         if substringRange.location != NSNotFound && substringRange.length > 0 {
                             let start = string.utf16.startIndex
-                            let min = start.advanced(by: substringRange.location)
-                            let max = start.advanced(by: substringRange.location + substringRange.length)
+                            let min = string.utf16.index(start, offsetBy: substringRange.location)
+                            let max = string.utf16.index(start, offsetBy: substringRange.location + substringRange.length)
                             substring = String(string.utf16[min..<max])!
                         }
                         str.replaceCharacters(in: rangeToReplace, with: substring)
diff --git a/Foundation/NSString.swift b/Foundation/NSString.swift
index 30f3b5a..610294c 100644
--- a/Foundation/NSString.swift
+++ b/Foundation/NSString.swift
@@ -193,7 +193,7 @@
             NSRequiresConcreteImplementation()
         }
         let start = _storage.utf16.startIndex
-        return _storage.utf16[start.advanced(by: index)]
+        return _storage.utf16[_storage.utf16.index(start, offsetBy: index)]
     }
     
     public override convenience init() {
@@ -347,7 +347,7 @@
     
     public func substring(from: Int) -> String {
         if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
-            return String(_storage.utf16.suffix(from: _storage.utf16.startIndex.advanced(by: from)))!
+            return String(_storage.utf16.suffix(from: _storage.utf16.index(_storage.utf16.startIndex, offsetBy: from)))!
         } else {
             return substring(with: NSRange(location: from, length: length - from))
         }
@@ -355,8 +355,7 @@
     
     public func substring(to: Int) -> String {
         if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
-            return String(_storage.utf16.prefix(upTo: _storage.utf16.startIndex
-            .advanced(by: to)))!
+            return String(_storage.utf16.prefix(upTo: _storage.utf16.index(_storage.utf16.startIndex, offsetBy: to)))!
         } else {
             return substring(with: NSRange(location: 0, length: to))
         }
@@ -365,8 +364,8 @@
     public func substring(with range: NSRange) -> String {
         if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
             let start = _storage.utf16.startIndex
-            let min = start.advanced(by: range.location)
-            let max = start.advanced(by: range.location + range.length)
+            let min = _storage.utf16.index(start, offsetBy: range.location)
+            let max = _storage.utf16.index(start, offsetBy: range.location + range.length)
             return String(decoding: _storage.utf16[min..<max], as: UTF16.self)
         } else {
             let buff = UnsafeMutablePointer<unichar>.allocate(capacity: range.length)
diff --git a/TestFoundation/TestAffineTransform.swift b/TestFoundation/TestAffineTransform.swift
index 15480e0..86da70f 100644
--- a/TestFoundation/TestAffineTransform.swift
+++ b/TestFoundation/TestAffineTransform.swift
@@ -41,6 +41,7 @@
             ("test_hashing_identity", test_hashing_identity),
             ("test_hashing_values", test_hashing_values),
             ("test_rotation_compose", test_rotation_compose),
+            ("test_translation_and_rotation", test_translation_and_rotation),
             ("test_Equal", test_Equal),
             ("test_NSCoding", test_NSCoding),
         ]
@@ -358,7 +359,14 @@
         XCTAssertEqual(0.0, Double(result.x), accuracy: accuracyThreshold)
         XCTAssertEqual(1.0, Double(result.y), accuracy: accuracyThreshold)
     }
-    
+
+    func test_translation_and_rotation() {
+        let point = NSPoint(x: CGFloat(10), y: CGFloat(10))
+        var translateThenRotate = AffineTransform(translationByX: 20, byY: -30)
+        translateThenRotate.rotate(byRadians: .pi / 2)
+        checkPointTransformation(NSAffineTransform(transform: translateThenRotate), point: point, expectedPoint: NSPoint(x: CGFloat(10), y: CGFloat(-20)))
+    }
+
     func test_Equal() {
         let transform = NSAffineTransform()
         let transform1 = NSAffineTransform()
diff --git a/TestFoundation/TestNSArray.swift b/TestFoundation/TestNSArray.swift
index 69b8eb7..bce61e2 100644
--- a/TestFoundation/TestNSArray.swift
+++ b/TestFoundation/TestNSArray.swift
@@ -47,6 +47,8 @@
             ("test_mutableCopying", test_mutableCopying),
             ("test_writeToFile", test_writeToFile),
             ("test_initWithContentsOfFile", test_initWithContentsOfFile),
+            ("test_initMutableWithContentsOfFile", test_initMutableWithContentsOfFile),
+            ("test_initMutableWithContentsOfURL", test_initMutableWithContentsOfURL),
             ("test_readWriteURL", test_readWriteURL),
             ("test_insertObjectAtIndex", test_insertObjectAtIndex),
             ("test_insertObjectsAtIndexes", test_insertObjectsAtIndexes),
@@ -647,7 +649,46 @@
             XCTFail("Temporary file creation failed")
         }
     }
-    
+
+    func test_initMutableWithContentsOfFile() {
+        if let testFilePath = createTestFile("TestFileOut.txt", _contents: Data(capacity: 234)) {
+            let a1: NSArray = ["foo", "bar"]
+            let isWritten = a1.write(toFile: testFilePath, atomically: true)
+            if isWritten {
+                let array = NSMutableArray.init(contentsOfFile: testFilePath)
+                XCTAssert(array == a1)
+                XCTAssertEqual(array?.count, 2)
+                array?.removeAllObjects()
+                XCTAssertEqual(array?.count, 0)
+            } else {
+                XCTFail("Write to file failed")
+            }
+            removeTestFile(testFilePath)
+        } else {
+            XCTFail("Temporary file creation failed")
+        }
+    }
+
+    func test_initMutableWithContentsOfURL() {
+        if let testFilePath = createTestFile("TestFileOut.txt", _contents: Data(capacity: 234)) {
+            let a1: NSArray = ["foo", "bar"]
+            let isWritten = a1.write(toFile: testFilePath, atomically: true)
+            if isWritten {
+                let url = URL(fileURLWithPath: testFilePath, isDirectory: false)
+                let array = NSMutableArray.init(contentsOf: url)
+                XCTAssert(array == a1)
+                XCTAssertEqual(array?.count, 2)
+                array?.removeAllObjects()
+                XCTAssertEqual(array?.count, 0)
+            } else {
+                XCTFail("Write to file failed")
+            }
+            removeTestFile(testFilePath)
+        } else {
+            XCTFail("Temporary file creation failed")
+        }
+    }
+
     func test_writeToFile() {
         let testFilePath = createTestFile("TestFileOut.txt", _contents: Data(capacity: 234))
         if let _ = testFilePath {
diff --git a/TestFoundation/TestNSAttributedString.swift b/TestFoundation/TestNSAttributedString.swift
index 3c536f9..308b595 100644
--- a/TestFoundation/TestNSAttributedString.swift
+++ b/TestFoundation/TestNSAttributedString.swift
@@ -587,7 +587,7 @@
         let deleteRange = NSRange(location: 0, length: 10)
         mutableAttrString.deleteCharacters(in: deleteRange)
         
-        let expectedString = String(string[string.startIndex.advanced(by: 10)...])
+        let expectedString = String(string[string.index(string.startIndex, offsetBy: 10)...])
         XCTAssertEqual(mutableAttrString.string, expectedString)
         
         let expectedLongestEffectiveRange = NSRange(expectedString.startIndex..., in: expectedString)
diff --git a/TestFoundation/TestXMLDocument.swift b/TestFoundation/TestXMLDocument.swift
index 36b6eea..b4d2a83 100644
--- a/TestFoundation/TestXMLDocument.swift
+++ b/TestFoundation/TestXMLDocument.swift
@@ -158,7 +158,10 @@
         XCTAssertEqual(nodes[0], bar1)
         XCTAssertEqual(nodes[1], bar2)
         XCTAssertEqual(nodes[2], bar3)
-        
+
+        let emptyResults = try! doc.nodes(forXPath: "/items/item/name[@type='alternate']/@value")
+        XCTAssertEqual(emptyResults.count, 0)
+
         let xmlString = """
         <?xml version="1.0" encoding="utf-8" standalone="yes"?>
             <D:propfind xmlns:D="DAV:">