diff --git a/benchmark/single-source/unit-tests/ObjectiveCBridging.swift b/benchmark/single-source/unit-tests/ObjectiveCBridging.swift index fb35d04a3e523..af05f05740978 100644 --- a/benchmark/single-source/unit-tests/ObjectiveCBridging.swift +++ b/benchmark/single-source/unit-tests/ObjectiveCBridging.swift @@ -73,7 +73,7 @@ public func run_ObjectiveCBridgeFromNSStringForced(_ N: Int) { @inline(never) func testObjectiveCBridgeToNSString() { - let nativeString = String("Native") + let nativeString = "Native" var s: NSString? for _ in 0 ..< 10_000 { diff --git a/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb b/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb index a81fa90d9cd1f..9995fed02a6fa 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb @@ -561,7 +561,7 @@ extension TestSuite { return makeCollectionOfEquatable(elements.map(wrapValueIntoEquatable)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===------------------------------------------------------------------===// // generate() @@ -1209,7 +1209,7 @@ extension TestSuite { return makeCollection(elements.map(wrapValue)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) // FIXME: swift-3-indexing-model - add tests for the follow? // index(before: of i: Index) -> Index @@ -1522,7 +1522,7 @@ extension TestSuite { addBidirectionalCollectionTests(${forwardTestArgs}) - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) func makeWrappedCollection(_ elements: [OpaqueValue]) -> C { return makeCollection(elements.map(wrapValue)) diff --git a/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb b/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb index 6b969283a9cfd..69e6879e1d843 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb @@ -148,7 +148,7 @@ extension TestSuite { return makeCollectionOfComparable(elements.map(wrapValueIntoComparable)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===----------------------------------------------------------------------===// // subscript(_: Index) @@ -749,7 +749,7 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") { return makeCollection(elements.map(wrapValue)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===----------------------------------------------------------------------===// // subscript(_: Index) @@ -906,7 +906,7 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer return makeCollectionOfComparable(elements.map(wrapValueIntoComparable)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===----------------------------------------------------------------------===// // sort() diff --git a/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift b/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift index 9cc512008766c..e6949c07a4782 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift +++ b/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift @@ -497,7 +497,7 @@ extension TestSuite { return makeCollection(elements.map(wrapValue)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===----------------------------------------------------------------------===// // init() @@ -1218,7 +1218,7 @@ self.test("\(testNamePrefix).OperatorPlus") { return makeCollection(elements.map(wrapValue)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===----------------------------------------------------------------------===// // removeLast() @@ -1340,7 +1340,7 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove resiliencyChecks: resiliencyChecks, outOfBoundsIndexOffset: outOfBoundsIndexOffset) - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) // No extra checks for collections with random access traversal so far. } // addRangeReplaceableRandomAccessCollectionTests diff --git a/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift b/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift index 9db580482a451..9eed4712f461a 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift +++ b/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift @@ -65,7 +65,7 @@ extension TestSuite { return makeCollection(elements.map(wrapValue)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===------------------------------------------------------------------===// // removeFirst() @@ -210,7 +210,7 @@ extension TestSuite { return makeCollection(elements.map(wrapValue)) } - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) //===------------------------------------------------------------------===// // removeLast() @@ -351,7 +351,7 @@ extension TestSuite { resiliencyChecks: resiliencyChecks, outOfBoundsIndexOffset: outOfBoundsIndexOffset) - testNamePrefix += String(C.Type.self) + testNamePrefix += String(describing: C.Type.self) // No tests yet. } // addRangeReplaceableRandomAccessSliceTests diff --git a/stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift b/stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift index e699a9b0ffd09..b8030968d08af 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift +++ b/stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift @@ -1484,7 +1484,7 @@ extension TestSuite { return makeSequenceOfEquatable(elements.map(wrapValueIntoEquatable)) } - testNamePrefix += String(S.Type.self) + testNamePrefix += String(describing: S.Type.self) let isMultiPass = makeSequence([]) ._preprocessingPass { true } ?? false diff --git a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift index 4b5d0a85b9301..1b81648957589 100644 --- a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift +++ b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift @@ -127,7 +127,7 @@ public func == (lhs: TypeIdentifier, rhs: TypeIdentifier) -> Bool { extension TypeIdentifier : CustomStringConvertible, CustomDebugStringConvertible { public var description: String { - return String(value) + return String(describing: value) } public var debugDescription: String { return "TypeIdentifier(\(description))" diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb index ec5262c8eb227..a871e764c469a 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb @@ -2215,6 +2215,12 @@ public func checkStrideable( } } +public func checkLosslessStringConvertible( + _ instances: [Instance] +) where Instance : LosslessStringConvertible & Equatable { + expectEqualFunctionsForDomain(instances, { $0 }, { Instance(String($0))! }) +} + public func nthIndex(_ x: C, _ n: Int) -> C.Index { return x.index(x.startIndex, offsetBy: numericCast(n)) } diff --git a/stdlib/private/StdlibUnittest/StringConvertible.swift.gyb b/stdlib/private/StdlibUnittest/StringConvertible.swift.gyb index 512162656d50a..2494b1d0fe40f 100644 --- a/stdlib/private/StdlibUnittest/StringConvertible.swift.gyb +++ b/stdlib/private/StdlibUnittest/StringConvertible.swift.gyb @@ -112,7 +112,7 @@ extension CustomPrintableValue : CustomDebugStringConvertible { public func expectPrinted( expectedOneOf patterns: [String], _ object: T, ${TRACE} ) { - let actual = String(object) + let actual = String(describing: object) if !patterns.contains(actual) { expectationFailure( "expected: any of \(String(reflecting: patterns))\n" diff --git a/stdlib/public/core/AnyHashable.swift b/stdlib/public/core/AnyHashable.swift index d93bc654fb483..5f421b3675c50 100644 --- a/stdlib/public/core/AnyHashable.swift +++ b/stdlib/public/core/AnyHashable.swift @@ -151,7 +151,7 @@ extension AnyHashable : Hashable { extension AnyHashable : CustomStringConvertible { public var description: String { - return String(base) + return String(describing: base) } } diff --git a/stdlib/public/core/Bool.swift b/stdlib/public/core/Bool.swift index 9fde254c74c4b..c267b13aba806 100644 --- a/stdlib/public/core/Bool.swift +++ b/stdlib/public/core/Bool.swift @@ -146,6 +146,18 @@ extension Bool : Equatable, Hashable { } } +extension Bool : LosslessStringConvertible { + public init?(_ description: String) { + if description == "true" { + self = true + } else if description == "false" { + self = false + } else { + return nil + } + } +} + //===----------------------------------------------------------------------===// // Operators //===----------------------------------------------------------------------===// diff --git a/stdlib/public/core/Character.swift b/stdlib/public/core/Character.swift index 2f9577c6a8f72..73afa5cc9f2a8 100644 --- a/stdlib/public/core/Character.swift +++ b/stdlib/public/core/Character.swift @@ -353,6 +353,14 @@ public struct Character : internal var _representation: Representation } +extension Character : CustomStringConvertible { + public var description: String { + return String(describing: self) + } +} + +extension Character : LosslessStringConvertible {} + extension Character : CustomDebugStringConvertible { /// A textual representation of the character, suitable for debugging. public var debugDescription: String { diff --git a/stdlib/public/core/FloatingPointParsing.swift.gyb b/stdlib/public/core/FloatingPointParsing.swift.gyb index 83c13344eb119..6e30d94afe302 100644 --- a/stdlib/public/core/FloatingPointParsing.swift.gyb +++ b/stdlib/public/core/FloatingPointParsing.swift.gyb @@ -42,7 +42,7 @@ internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool { % end //===--- Parsing ----------------------------------------------------------===// -extension ${Self} { +extension ${Self} : LosslessStringConvertible { /// Construct from an ASCII representation. /// /// Returns the result of calling the POSIX function diff --git a/stdlib/public/core/ImplicitlyUnwrappedOptional.swift b/stdlib/public/core/ImplicitlyUnwrappedOptional.swift index f5a0e1f10cd91..407f2d38db450 100644 --- a/stdlib/public/core/ImplicitlyUnwrappedOptional.swift +++ b/stdlib/public/core/ImplicitlyUnwrappedOptional.swift @@ -45,7 +45,7 @@ extension ImplicitlyUnwrappedOptional : CustomStringConvertible { public var description: String { switch self { case .some(let value): - return String(value) + return String(describing: value) case .none: return "nil" } diff --git a/stdlib/public/core/Integers.swift.gyb b/stdlib/public/core/Integers.swift.gyb index 2bf7dc873089e..4b7aebd26f689 100644 --- a/stdlib/public/core/Integers.swift.gyb +++ b/stdlib/public/core/Integers.swift.gyb @@ -688,7 +688,7 @@ public protocol SignedInteger_ : BinaryInteger, SignedArithmetic { extension SignedInteger_ { public var description: String { - let base = String(magnitude) + let base = String(describing: magnitude) return self < 0 ? "-" + base : base } diff --git a/stdlib/public/core/Mirror.swift b/stdlib/public/core/Mirror.swift index 88b352dd7216a..6134bd990b8ce 100644 --- a/stdlib/public/core/Mirror.swift +++ b/stdlib/public/core/Mirror.swift @@ -855,7 +855,7 @@ extension String { /// } /// /// let p = Point(x: 21, y: 30) - /// print(String(p)) + /// print(String(describing: p)) /// // Prints "Point(x: 21, y: 30)" /// /// After adding `CustomStringConvertible` conformance by implementing the @@ -867,11 +867,11 @@ extension String { /// } /// } /// - /// print(String(p)) + /// print(String(describing: p)) /// // Prints "(21, 30)" /// /// - SeeAlso: `String.init(reflecting: Subject)` - public init(_ instance: Subject) { + public init(describing instance: Subject) { self.init() _print_unlocked(instance, &self) } diff --git a/stdlib/public/core/OutputStream.swift b/stdlib/public/core/OutputStream.swift index a820103f8fe60..c4b0645bb6f24 100644 --- a/stdlib/public/core/OutputStream.swift +++ b/stdlib/public/core/OutputStream.swift @@ -164,6 +164,20 @@ public protocol CustomStringConvertible { var description: String { get } } +/// A type that can be represented as a string in a lossless, unambiguous way. +/// +/// For example, the integer value 1050 can be represented in its entirety as +/// the string "1050". +/// +/// The description property of a conforming type must be a value-preserving +/// representation of the original value. As such, it should be possible to +/// re-create an instance from its string representation. +public protocol LosslessStringConvertible : CustomStringConvertible { + /// Instantiates an instance of the conforming type from a string + /// representation. + init?(_ description: String) +} + /// A type with a customized textual representation suitable for debugging /// purposes. /// diff --git a/stdlib/public/core/StaticString.swift b/stdlib/public/core/StaticString.swift index 4a075b8030098..832abbd41a6de 100644 --- a/stdlib/public/core/StaticString.swift +++ b/stdlib/public/core/StaticString.swift @@ -255,7 +255,7 @@ public struct StaticString extension StaticString { public var customMirror: Mirror { - return Mirror(reflecting: String(self)) + return Mirror(reflecting: description) } } diff --git a/stdlib/public/core/String.swift b/stdlib/public/core/String.swift index 45f67a6dbc36b..b46c9d8cad75c 100644 --- a/stdlib/public/core/String.swift +++ b/stdlib/public/core/String.swift @@ -981,6 +981,24 @@ extension String { return _nativeUnicodeUppercaseString(self) #endif } + + /// Creates an instance from the description of a given + /// `LosslessStringConvertible` instance. + public init(_ value: T) { + self = value.description + } +} + +extension String : CustomStringConvertible { + public var description: String { + return self + } +} + +extension String : LosslessStringConvertible { + public init?(_ description: String) { + self = description + } } extension String { diff --git a/stdlib/public/core/StringInterpolation.swift.gyb b/stdlib/public/core/StringInterpolation.swift.gyb index bec13b14e3e76..384785dec715c 100644 --- a/stdlib/public/core/StringInterpolation.swift.gyb +++ b/stdlib/public/core/StringInterpolation.swift.gyb @@ -65,7 +65,7 @@ extension String : ExpressibleByStringInterpolation { /// /// - SeeAlso: `ExpressibleByStringInterpolation` public init(stringInterpolationSegment expr: T) { - self = String(expr) + self = String(describing: expr) } % for Type in StreamableTypes: diff --git a/stdlib/public/core/StringUTF16.swift b/stdlib/public/core/StringUTF16.swift index be09394143296..916a1c9bcc628 100644 --- a/stdlib/public/core/StringUTF16.swift +++ b/stdlib/public/core/StringUTF16.swift @@ -314,7 +314,7 @@ extension String { return UTF16View(_core) } set { - self = String(newValue) + self = String(describing: newValue) } } diff --git a/stdlib/public/core/StringUTF8.swift b/stdlib/public/core/StringUTF8.swift index 009a49608a367..8a9dd318a5f44 100644 --- a/stdlib/public/core/StringUTF8.swift +++ b/stdlib/public/core/StringUTF8.swift @@ -375,7 +375,7 @@ extension String { return UTF8View(self._core) } set { - self = String(newValue) + self = String(describing: newValue) } } diff --git a/stdlib/public/core/UnicodeScalar.swift b/stdlib/public/core/UnicodeScalar.swift index 2ca3feb45db3f..822b6263aafea 100644 --- a/stdlib/public/core/UnicodeScalar.swift +++ b/stdlib/public/core/UnicodeScalar.swift @@ -271,10 +271,13 @@ public struct UnicodeScalar : } extension UnicodeScalar : CustomStringConvertible, CustomDebugStringConvertible { - /// An escaped textual representation of the Unicode scalar. + /// A textual representation of the Unicode scalar. public var description: String { - return "\"\(escaped(asASCII: false))\"" + return String._fromWellFormedCodeUnitSequence( + UTF32.self, + input: repeatElement(self.value, count: 1)) } + /// An escaped textual representation of the Unicode scalar, suitable for /// debugging. public var debugDescription: String { @@ -282,6 +285,16 @@ extension UnicodeScalar : CustomStringConvertible, CustomDebugStringConvertible } } +extension UnicodeScalar : LosslessStringConvertible { + public init?(_ description: String) { + let scalars = description.unicodeScalars + guard let v = scalars.first, scalars.count == 1 else { + return nil + } + self = v + } +} + extension UnicodeScalar : Hashable { /// The Unicode scalar's hash value. /// diff --git a/stdlib/public/core/UnsafeBufferPointer.swift.gyb b/stdlib/public/core/UnsafeBufferPointer.swift.gyb index a10f11f4bbe12..a5b972127cce1 100644 --- a/stdlib/public/core/UnsafeBufferPointer.swift.gyb +++ b/stdlib/public/core/UnsafeBufferPointer.swift.gyb @@ -219,7 +219,7 @@ extension Unsafe${Mutable}BufferPointer : CustomDebugStringConvertible { /// A textual representation of `self`, suitable for debugging. public var debugDescription: String { return "Unsafe${Mutable}BufferPointer" - + "(start: \(_position.map(String.init(_:)) ?? "nil"), count: \(count))" + + "(start: \(_position.map(String.init(describing:)) ?? "nil"), count: \(count))" } } %end diff --git a/test/1_stdlib/Character.swift b/test/1_stdlib/Character.swift index 6e6ac0c9db331..e61cf9e66bfac 100644 --- a/test/1_stdlib/Character.swift +++ b/test/1_stdlib/Character.swift @@ -14,7 +14,7 @@ import SwiftPrivate // // These scalars should be "base characters" with regards to their position in // a grapheme cluster. -let baseScalars = [ +let baseScalars: [UnicodeScalar] = [ // U+0065 LATIN SMALL LETTER E "\u{0065}", @@ -54,7 +54,7 @@ let baseScalars = [ // Single Unicode scalars that are "continuing characters" with regards to // their position in a grapheme cluster. -let continuingScalars = [ +let continuingScalars: [UnicodeScalar] = [ // U+0300 COMBINING GRAVE ACCENT "\u{0300}", @@ -94,9 +94,9 @@ let testCharacters = [ func randomGraphemeCluster(_ minSize: Int, _ maxSize: Int) -> String { let n = pickRandom((minSize + 1)..= CharA) } +UnicodeScalarTests.test("LosslessStringConvertible") { + // FIXME: these tests are insufficient. + + checkLosslessStringConvertible((0xE000...0xF000).map { UnicodeScalar(Int($0))! }) + checkLosslessStringConvertible((0...127).map { UnicodeScalar(Int($0))! }) +} + runAllTests() diff --git a/test/1_stdlib/FloatingPoint.swift.gyb b/test/1_stdlib/FloatingPoint.swift.gyb index 2c7266d735840..1e004c7f28404 100644 --- a/test/1_stdlib/FloatingPoint.swift.gyb +++ b/test/1_stdlib/FloatingPoint.swift.gyb @@ -370,6 +370,17 @@ FloatingPoint.test("${Self}.addingProduct") { let ulp = ${Self}.ulpOfOne expectEqual(ulp*ulp, one.addingProduct(ulp + one, ulp - one)) } + +FloatingPoint.test("${Self}/LosslessStringConvertible") { + let instances = [ + 1.0, -1.0, + 0.0, -0.0, + ${Self}.infinity, -${Self}.infinity + ] + + checkLosslessStringConvertible(instances) + expectTrue(Float(String(Float.nan))!.isNaN) +} % if Self == 'Float80': #endif % end diff --git a/test/1_stdlib/Inputs/PrintTestTypes.swift b/test/1_stdlib/Inputs/PrintTestTypes.swift index 489827ffc96c0..f8edbacf4d57b 100644 --- a/test/1_stdlib/Inputs/PrintTestTypes.swift +++ b/test/1_stdlib/Inputs/PrintTestTypes.swift @@ -151,7 +151,7 @@ public struct MyString : ExpressibleByStringLiteral, } public init(stringInterpolationSegment expr: T) { - self.init(str: "") + self.init(str: "") } } diff --git a/test/1_stdlib/NSArrayAPI.swift b/test/1_stdlib/NSArrayAPI.swift index f8cf980f51d7f..1f38438401a66 100644 --- a/test/1_stdlib/NSArrayAPI.swift +++ b/test/1_stdlib/NSArrayAPI.swift @@ -24,10 +24,7 @@ NSArrayAPI.test("mixed types with AnyObject") { } NSArrayAPI.test("CustomStringConvertible") { - // FIXME: rdar://problem/27515965 Type checker tries to use the - // sequence-of-Character initializer here instead of the printing initializer - // without the 'Any' cast. - let result = String(NSArray(objects:"A", "B", "C", "D") as Any) + let result = String(describing: NSArray(objects:"A", "B", "C", "D")) let expect = "(\n A,\n B,\n C,\n D\n)" expectEqual(expect, result) } @@ -43,10 +40,7 @@ NSArrayAPI.test("copy construction") { var NSMutableArrayAPI = TestSuite("NSMutableArrayAPI") NSMutableArrayAPI.test("CustomStringConvertible") { - // FIXME: rdar://problem/27515965 Type checker tries to use the - // sequence-of-Character initializer here instead of the printing initializer - // without the 'Any' cast. - let result = String(NSMutableArray(objects:"A", "B", "C", "D") as Any) + let result = String(describing: NSMutableArray(objects:"A", "B", "C", "D")) let expect = "(\n A,\n B,\n C,\n D\n)" expectEqual(expect, result) } diff --git a/test/1_stdlib/NSSetAPI.swift b/test/1_stdlib/NSSetAPI.swift index a407dd346f357..81c03b8503878 100644 --- a/test/1_stdlib/NSSetAPI.swift +++ b/test/1_stdlib/NSSetAPI.swift @@ -38,10 +38,7 @@ NSSetAPI.test("ExpressibleByArrayLiteral") { } NSSetAPI.test("CustomStringConvertible") { - // FIXME: rdar://problem/27515965 Type checker tries to use the - // sequence-of-Character initializer here instead of the printing initializer - // without the 'Any' cast. - let result = String(NSSet(objects:"a", "b", "c", "42") as Any) + let result = String(describing: NSSet(objects:"a", "b", "c", "42")) let expect = "{(\n b,\n 42,\n c,\n a\n)}" expectEqual(expect, result) } @@ -64,10 +61,7 @@ NSOrderedSetAPI.test("ExpressibleByArrayLiteral") { } NSOrderedSetAPI.test("CustomStringConvertible") { - // FIXME: rdar://problem/27515965 Type checker tries to use the - // sequence-of-Character initializer here instead of the printing initializer - // without the 'Any' cast. - let result = String(NSOrderedSet(objects:"a", "b", "c", "42") as Any) + let result = String(describing: NSOrderedSet(objects:"a", "b", "c", "42")) let expect = "{(\n a,\n b,\n c,\n 42\n)}" expectEqual(expect, result) } diff --git a/test/1_stdlib/Optional.swift b/test/1_stdlib/Optional.swift index 470d7cba1bbf0..1a1fb868bcb4d 100644 --- a/test/1_stdlib/Optional.swift +++ b/test/1_stdlib/Optional.swift @@ -375,7 +375,7 @@ OptionalTests.test("Optional TextOutputStream") { expectFalse(canGenericCast(optNoString, Streamable.self)) expectTrue(optNoString is CustomDebugStringConvertible) expectTrue(canGenericCast(optNoString, CustomDebugStringConvertible.self)) - expectEqual(String(optNoString), "Optional(main.TestNoString)") + expectEqual(String(describing: optNoString), "Optional(main.TestNoString)") expectEqual(debugPrintStr(optNoString), "Optional(main.TestNoString)") let optString: TestString? = TestString() @@ -383,8 +383,8 @@ OptionalTests.test("Optional TextOutputStream") { expectTrue(canGenericCast(optString, CustomStringConvertible.self)) expectTrue(optString is CustomDebugStringConvertible) expectTrue(canGenericCast(optString, CustomDebugStringConvertible.self)) - expectEqual(String(TestString()), "AString") - expectEqual(String(optString), "Optional(XString)") + expectEqual(String(describing: TestString()), "AString") + expectEqual(String(describing: optString), "Optional(XString)") expectEqual(debugPrintStr(optString), "Optional(XString)") let optStream: TestStream? = TestStream() @@ -392,8 +392,8 @@ OptionalTests.test("Optional TextOutputStream") { expectTrue(canGenericCast(optStream, Streamable.self)) expectTrue(optStream is CustomDebugStringConvertible) expectTrue(canGenericCast(optStream, CustomDebugStringConvertible.self)) - expectEqual(String(TestStream()), "AStream") - expectEqual(String(optStream), "Optional(AStream)") + expectEqual(String(describing: TestStream()), "AStream") + expectEqual(String(describing: optStream), "Optional(AStream)") expectEqual(debugPrintStr(optStream), "Optional(AStream)") } diff --git a/test/1_stdlib/PrintBoolean.swift b/test/1_stdlib/PrintBoolean.swift index 728501977095c..3aba38adbaccb 100644 --- a/test/1_stdlib/PrintBoolean.swift +++ b/test/1_stdlib/PrintBoolean.swift @@ -26,4 +26,8 @@ PrintTests.test("Printable") { expectPrinted("false", false) } +PrintTests.test("LosslessStringConvertible") { + checkLosslessStringConvertible([ true, false ]) +} + runAllTests() diff --git a/test/1_stdlib/Runtime.swift.gyb b/test/1_stdlib/Runtime.swift.gyb index be305de7a6eb4..71a6c3b964a99 100644 --- a/test/1_stdlib/Runtime.swift.gyb +++ b/test/1_stdlib/Runtime.swift.gyb @@ -74,8 +74,8 @@ protocol Q1 {} extension P1 { var success: Bool { - print(String(customMirror)) - return String(customMirror) == "Mirror for ()" + print(String(describing: customMirror)) + return String(describing: customMirror) == "Mirror for ()" } } diff --git a/test/1_stdlib/RuntimeObjC.swift b/test/1_stdlib/RuntimeObjC.swift index e669b6739d5d0..054604520d38e 100644 --- a/test/1_stdlib/RuntimeObjC.swift +++ b/test/1_stdlib/RuntimeObjC.swift @@ -694,7 +694,7 @@ Reflection.test("MetatypeMirror") { expectEqual(expectedComposition, output) let objcDefinedProtoType = NSObjectProtocol.self - expectEqual(String(objcDefinedProtoType), "NSObject") + expectEqual(String(describing: objcDefinedProtoType), "NSObject") } } diff --git a/test/1_stdlib/StaticString.swift b/test/1_stdlib/StaticString.swift index 45065276cda3e..cbf2b9f4d1f93 100644 --- a/test/1_stdlib/StaticString.swift +++ b/test/1_stdlib/StaticString.swift @@ -15,7 +15,7 @@ StaticStringTestSuite.test("PointerRepresentation/ASCII/Empty") { utf8 in expectEqual(0, utf8.count) } - expectEqual("", String(str)) + expectEqual("", str.description) expectPrinted("", str) expectDebugPrinted("\"\"", str) @@ -36,7 +36,7 @@ StaticStringTestSuite.test("PointerRepresentation/ASCII") { expectEqual(0x62, utf8[1]) expectEqual(0x63, utf8[2]) } - expectEqual("abc", String(str)) + expectEqual("abc", str.description) expectPrinted("abc", str) expectDebugPrinted("\"abc\"", str) @@ -63,7 +63,7 @@ StaticStringTestSuite.test("PointerRepresentation/NonASCII") { expectEqual(0xd0, utf8[4]) expectEqual(0xb2, utf8[5]) } - expectEqual("абв", String(str)) + expectEqual("абв", str.description) expectPrinted("абв", str) expectDebugPrinted("\"абв\"", str) @@ -96,7 +96,7 @@ StaticStringTestSuite.test("UnicodeScalarRepresentation/ASCII") { expectEqual(1, utf8.count) expectEqual(0x5a, utf8[0]) } - expectEqual("Z", String(str)) + expectEqual("Z", str.description) expectPrinted("Z", str) expectDebugPrinted("\"Z\"", str) @@ -113,7 +113,7 @@ StaticStringTestSuite.test("UnicodeScalarRepresentation/NonASCII") { expectEqual(0xd0, utf8[0]) expectEqual(0xab, utf8[1]) } - expectEqual("Ы", String(str)) + expectEqual("Ы", str.description) expectPrinted("Ы", str) expectDebugPrinted("\"Ы\"", str) diff --git a/test/1_stdlib/StringAPI.swift b/test/1_stdlib/StringAPI.swift index f5ebe3753f3d4..5e63afd7a4c96 100644 --- a/test/1_stdlib/StringAPI.swift +++ b/test/1_stdlib/StringAPI.swift @@ -256,6 +256,11 @@ func checkHasPrefixHasSuffix( #endif } +StringTests.test("LosslessStringConvertible") { + checkLosslessStringConvertible(comparisonTests.map { $0.lhs }) + checkLosslessStringConvertible(comparisonTests.map { $0.rhs }) +} + StringTests.test("hasPrefix,hasSuffix") .skip(.nativeRuntime( "String.has{Prefix,Suffix} defined when _runtime(_ObjC)")) diff --git a/test/1_stdlib/TestAffineTransform.swift b/test/1_stdlib/TestAffineTransform.swift index eb890dc9fa608..9bd6a167ab892 100644 --- a/test/1_stdlib/TestAffineTransform.swift +++ b/test/1_stdlib/TestAffineTransform.swift @@ -337,9 +337,9 @@ class TestAffineTransform : TestAffineTransformSuper { AffineTransform(m11: -55.66, m12: 22.7, m21: 1.5, m22: 0.0, tX: -22, tY: -33) ] let anyHashables = values.map(AnyHashable.init) - expectEqual("AffineTransform", String(anyHashables[0].base.dynamicType)) - expectEqual("AffineTransform", String(anyHashables[1].base.dynamicType)) - expectEqual("AffineTransform", String(anyHashables[2].base.dynamicType)) + expectEqual("AffineTransform", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("AffineTransform", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("AffineTransform", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -356,9 +356,9 @@ class TestAffineTransform : TestAffineTransformSuper { makeNSAffineTransform(rotatedByDegrees: 10), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("AffineTransform", String(anyHashables[0].base.dynamicType)) - expectEqual("AffineTransform", String(anyHashables[1].base.dynamicType)) - expectEqual("AffineTransform", String(anyHashables[2].base.dynamicType)) + expectEqual("AffineTransform", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("AffineTransform", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("AffineTransform", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestCalendar.swift b/test/1_stdlib/TestCalendar.swift index be4682404449c..a7e72d829eae6 100644 --- a/test/1_stdlib/TestCalendar.swift +++ b/test/1_stdlib/TestCalendar.swift @@ -263,9 +263,9 @@ class TestCalendar : TestCalendarSuper { Calendar(identifier: .japanese) ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Calendar", String(anyHashables[0].base.dynamicType)) - expectEqual("Calendar", String(anyHashables[1].base.dynamicType)) - expectEqual("Calendar", String(anyHashables[2].base.dynamicType)) + expectEqual("Calendar", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Calendar", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Calendar", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -278,9 +278,9 @@ class TestCalendar : TestCalendarSuper { NSCalendar(identifier: .japanese)!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Calendar", String(anyHashables[0].base.dynamicType)) - expectEqual("Calendar", String(anyHashables[1].base.dynamicType)) - expectEqual("Calendar", String(anyHashables[2].base.dynamicType)) + expectEqual("Calendar", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Calendar", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Calendar", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestCharacterSet.swift b/test/1_stdlib/TestCharacterSet.swift index f49936592cc6f..ca2630a8729f1 100644 --- a/test/1_stdlib/TestCharacterSet.swift +++ b/test/1_stdlib/TestCharacterSet.swift @@ -160,9 +160,9 @@ class TestCharacterSet : TestCharacterSetSuper { CharacterSet(charactersIn: "XYZ") ] let anyHashables = values.map(AnyHashable.init) - expectEqual("CharacterSet", String(anyHashables[0].base.dynamicType)) - expectEqual("CharacterSet", String(anyHashables[1].base.dynamicType)) - expectEqual("CharacterSet", String(anyHashables[2].base.dynamicType)) + expectEqual("CharacterSet", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("CharacterSet", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("CharacterSet", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -174,9 +174,9 @@ class TestCharacterSet : TestCharacterSetSuper { NSCharacterSet(charactersIn: "XYZ"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("CharacterSet", String(anyHashables[0].base.dynamicType)) - expectEqual("CharacterSet", String(anyHashables[1].base.dynamicType)) - expectEqual("CharacterSet", String(anyHashables[2].base.dynamicType)) + expectEqual("CharacterSet", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("CharacterSet", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("CharacterSet", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestData.swift b/test/1_stdlib/TestData.swift index 6f40061c7a35b..5bf53f0982a26 100644 --- a/test/1_stdlib/TestData.swift +++ b/test/1_stdlib/TestData.swift @@ -875,9 +875,9 @@ class TestData : TestDataSuper { Data(base64Encoded: "AAAB")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Data", String(anyHashables[0].base.dynamicType)) - expectEqual("Data", String(anyHashables[1].base.dynamicType)) - expectEqual("Data", String(anyHashables[2].base.dynamicType)) + expectEqual("Data", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Data", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Data", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -889,9 +889,9 @@ class TestData : TestDataSuper { NSData(base64Encoded: "AAAB")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Data", String(anyHashables[0].base.dynamicType)) - expectEqual("Data", String(anyHashables[1].base.dynamicType)) - expectEqual("Data", String(anyHashables[2].base.dynamicType)) + expectEqual("Data", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Data", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Data", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestDate.swift b/test/1_stdlib/TestDate.swift index 63bff78062d1d..f84dde936b255 100644 --- a/test/1_stdlib/TestDate.swift +++ b/test/1_stdlib/TestDate.swift @@ -143,9 +143,9 @@ class TestDate : TestDateSuper { dateWithString("2010-05-17 14:49:47 -0700"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Date", String(anyHashables[0].base.dynamicType)) - expectEqual("Date", String(anyHashables[1].base.dynamicType)) - expectEqual("Date", String(anyHashables[2].base.dynamicType)) + expectEqual("Date", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Date", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Date", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -157,9 +157,9 @@ class TestDate : TestDateSuper { NSDate(timeIntervalSince1970: 1000000001), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Date", String(anyHashables[0].base.dynamicType)) - expectEqual("Date", String(anyHashables[1].base.dynamicType)) - expectEqual("Date", String(anyHashables[2].base.dynamicType)) + expectEqual("Date", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Date", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Date", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -171,9 +171,9 @@ class TestDate : TestDateSuper { DateComponents(year: 1995), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateComponents", String(anyHashables[0].base.dynamicType)) - expectEqual("DateComponents", String(anyHashables[1].base.dynamicType)) - expectEqual("DateComponents", String(anyHashables[2].base.dynamicType)) + expectEqual("DateComponents", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("DateComponents", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("DateComponents", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -190,9 +190,9 @@ class TestDate : TestDateSuper { makeNSDateComponents(year: 1995), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateComponents", String(anyHashables[0].base.dynamicType)) - expectEqual("DateComponents", String(anyHashables[1].base.dynamicType)) - expectEqual("DateComponents", String(anyHashables[2].base.dynamicType)) + expectEqual("DateComponents", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("DateComponents", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("DateComponents", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestDateInterval.swift b/test/1_stdlib/TestDateInterval.swift index 8300ae21cd1e2..e0f2e083b15f6 100644 --- a/test/1_stdlib/TestDateInterval.swift +++ b/test/1_stdlib/TestDateInterval.swift @@ -140,9 +140,9 @@ class TestDateInterval : TestDateIntervalSuper { DateInterval(start: start, duration: duration / 2), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateInterval", String(anyHashables[0].base.dynamicType)) - expectEqual("DateInterval", String(anyHashables[1].base.dynamicType)) - expectEqual("DateInterval", String(anyHashables[2].base.dynamicType)) + expectEqual("DateInterval", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("DateInterval", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("DateInterval", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -158,9 +158,9 @@ class TestDateInterval : TestDateIntervalSuper { NSDateInterval(start: start, duration: duration / 2), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateInterval", String(anyHashables[0].base.dynamicType)) - expectEqual("DateInterval", String(anyHashables[1].base.dynamicType)) - expectEqual("DateInterval", String(anyHashables[2].base.dynamicType)) + expectEqual("DateInterval", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("DateInterval", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("DateInterval", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestIndexPath.swift b/test/1_stdlib/TestIndexPath.swift index 063663335db58..80d7a8a6e27fb 100644 --- a/test/1_stdlib/TestIndexPath.swift +++ b/test/1_stdlib/TestIndexPath.swift @@ -89,9 +89,9 @@ class TestIndexPath : TestIndexPathSuper { IndexPath(indexes: [1, 2, 3]), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexPath", String(anyHashables[0].base.dynamicType)) - expectEqual("IndexPath", String(anyHashables[1].base.dynamicType)) - expectEqual("IndexPath", String(anyHashables[2].base.dynamicType)) + expectEqual("IndexPath", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("IndexPath", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("IndexPath", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -103,9 +103,9 @@ class TestIndexPath : TestIndexPathSuper { NSIndexPath(index: 2), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexPath", String(anyHashables[0].base.dynamicType)) - expectEqual("IndexPath", String(anyHashables[1].base.dynamicType)) - expectEqual("IndexPath", String(anyHashables[2].base.dynamicType)) + expectEqual("IndexPath", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("IndexPath", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("IndexPath", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestIndexSet.swift b/test/1_stdlib/TestIndexSet.swift index bfd36966f393d..43a931d93947f 100644 --- a/test/1_stdlib/TestIndexSet.swift +++ b/test/1_stdlib/TestIndexSet.swift @@ -765,9 +765,9 @@ class TestIndexSet : TestIndexSetSuper { IndexSet([0, 1, 2]), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexSet", String(anyHashables[0].base.dynamicType)) - expectEqual("IndexSet", String(anyHashables[1].base.dynamicType)) - expectEqual("IndexSet", String(anyHashables[2].base.dynamicType)) + expectEqual("IndexSet", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("IndexSet", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("IndexSet", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -779,9 +779,9 @@ class TestIndexSet : TestIndexSetSuper { NSIndexSet(index: 1), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexSet", String(anyHashables[0].base.dynamicType)) - expectEqual("IndexSet", String(anyHashables[1].base.dynamicType)) - expectEqual("IndexSet", String(anyHashables[2].base.dynamicType)) + expectEqual("IndexSet", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("IndexSet", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("IndexSet", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestLocale.swift b/test/1_stdlib/TestLocale.swift index ee4448184ba32..96a5f92e74fab 100644 --- a/test/1_stdlib/TestLocale.swift +++ b/test/1_stdlib/TestLocale.swift @@ -116,9 +116,9 @@ class TestLocale : TestLocaleSuper { Locale(identifier: "uk"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Locale", String(anyHashables[0].base.dynamicType)) - expectEqual("Locale", String(anyHashables[1].base.dynamicType)) - expectEqual("Locale", String(anyHashables[2].base.dynamicType)) + expectEqual("Locale", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Locale", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Locale", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -130,9 +130,9 @@ class TestLocale : TestLocaleSuper { NSLocale(localeIdentifier: "uk"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Locale", String(anyHashables[0].base.dynamicType)) - expectEqual("Locale", String(anyHashables[1].base.dynamicType)) - expectEqual("Locale", String(anyHashables[2].base.dynamicType)) + expectEqual("Locale", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Locale", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Locale", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestPersonNameComponents.swift b/test/1_stdlib/TestPersonNameComponents.swift index d3ce6a54b2a6a..b8313f5a189f2 100644 --- a/test/1_stdlib/TestPersonNameComponents.swift +++ b/test/1_stdlib/TestPersonNameComponents.swift @@ -37,9 +37,9 @@ class TestPersonNameComponents : TestPersonNameComponentsSuper { makePersonNameComponents(givenName: "John", familyName: "Appleseed"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("PersonNameComponents", String(anyHashables[0].base.dynamicType)) - expectEqual("PersonNameComponents", String(anyHashables[1].base.dynamicType)) - expectEqual("PersonNameComponents", String(anyHashables[2].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -61,9 +61,9 @@ class TestPersonNameComponents : TestPersonNameComponentsSuper { makeNSPersonNameComponents(givenName: "John", familyName: "Appleseed"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("PersonNameComponents", String(anyHashables[0].base.dynamicType)) - expectEqual("PersonNameComponents", String(anyHashables[1].base.dynamicType)) - expectEqual("PersonNameComponents", String(anyHashables[2].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestTimeZone.swift b/test/1_stdlib/TestTimeZone.swift index bbafd2c4180bc..a10fa527a7e26 100644 --- a/test/1_stdlib/TestTimeZone.swift +++ b/test/1_stdlib/TestTimeZone.swift @@ -70,9 +70,9 @@ class TestTimeZone : TestTimeZoneSuper { TimeZone(identifier: "Europe/Kiev")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("TimeZone", String(anyHashables[0].base.dynamicType)) - expectEqual("TimeZone", String(anyHashables[1].base.dynamicType)) - expectEqual("TimeZone", String(anyHashables[2].base.dynamicType)) + expectEqual("TimeZone", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("TimeZone", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("TimeZone", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -84,9 +84,9 @@ class TestTimeZone : TestTimeZoneSuper { NSTimeZone(name: "Europe/Kiev")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("TimeZone", String(anyHashables[0].base.dynamicType)) - expectEqual("TimeZone", String(anyHashables[1].base.dynamicType)) - expectEqual("TimeZone", String(anyHashables[2].base.dynamicType)) + expectEqual("TimeZone", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("TimeZone", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("TimeZone", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestURL.swift b/test/1_stdlib/TestURL.swift index 5ae8665342bc2..504fecdf7c8fc 100644 --- a/test/1_stdlib/TestURL.swift +++ b/test/1_stdlib/TestURL.swift @@ -212,9 +212,9 @@ class TestURL : TestURLSuper { URL(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URL", String(anyHashables[0].base.dynamicType)) - expectEqual("URL", String(anyHashables[1].base.dynamicType)) - expectEqual("URL", String(anyHashables[2].base.dynamicType)) + expectEqual("URL", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URL", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URL", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -226,9 +226,9 @@ class TestURL : TestURLSuper { NSURL(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URL", String(anyHashables[0].base.dynamicType)) - expectEqual("URL", String(anyHashables[1].base.dynamicType)) - expectEqual("URL", String(anyHashables[2].base.dynamicType)) + expectEqual("URL", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URL", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URL", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -240,9 +240,9 @@ class TestURL : TestURLSuper { URLComponents(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLComponents", String(anyHashables[0].base.dynamicType)) - expectEqual("URLComponents", String(anyHashables[1].base.dynamicType)) - expectEqual("URLComponents", String(anyHashables[2].base.dynamicType)) + expectEqual("URLComponents", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URLComponents", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URLComponents", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -254,9 +254,9 @@ class TestURL : TestURLSuper { NSURLComponents(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLComponents", String(anyHashables[0].base.dynamicType)) - expectEqual("URLComponents", String(anyHashables[1].base.dynamicType)) - expectEqual("URLComponents", String(anyHashables[2].base.dynamicType)) + expectEqual("URLComponents", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URLComponents", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URLComponents", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -269,9 +269,9 @@ class TestURL : TestURLSuper { URLQueryItem(name: "bar", value: nil), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLQueryItem", String(anyHashables[0].base.dynamicType)) - expectEqual("URLQueryItem", String(anyHashables[1].base.dynamicType)) - expectEqual("URLQueryItem", String(anyHashables[2].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -285,9 +285,9 @@ class TestURL : TestURLSuper { NSURLQueryItem(name: "bar", value: nil), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLQueryItem", String(anyHashables[0].base.dynamicType)) - expectEqual("URLQueryItem", String(anyHashables[1].base.dynamicType)) - expectEqual("URLQueryItem", String(anyHashables[2].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -300,9 +300,9 @@ class TestURL : TestURLSuper { URLRequest(url: URL(string: "https://example.org/")!), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLRequest", String(anyHashables[0].base.dynamicType)) - expectEqual("URLRequest", String(anyHashables[1].base.dynamicType)) - expectEqual("URLRequest", String(anyHashables[2].base.dynamicType)) + expectEqual("URLRequest", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URLRequest", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URLRequest", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -314,9 +314,9 @@ class TestURL : TestURLSuper { NSURLRequest(url: URL(string: "https://example.org/")!), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLRequest", String(anyHashables[0].base.dynamicType)) - expectEqual("URLRequest", String(anyHashables[1].base.dynamicType)) - expectEqual("URLRequest", String(anyHashables[2].base.dynamicType)) + expectEqual("URLRequest", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("URLRequest", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("URLRequest", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestUUID.swift b/test/1_stdlib/TestUUID.swift index e041e76eda864..31ac9f6c775dc 100644 --- a/test/1_stdlib/TestUUID.swift +++ b/test/1_stdlib/TestUUID.swift @@ -97,9 +97,9 @@ class TestUUID : TestUUIDSuper { UUID(uuidString: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("UUID", String(anyHashables[0].base.dynamicType)) - expectEqual("UUID", String(anyHashables[1].base.dynamicType)) - expectEqual("UUID", String(anyHashables[2].base.dynamicType)) + expectEqual("UUID", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("UUID", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("UUID", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -111,9 +111,9 @@ class TestUUID : TestUUIDSuper { NSUUID(uuidString: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("UUID", String(anyHashables[0].base.dynamicType)) - expectEqual("UUID", String(anyHashables[1].base.dynamicType)) - expectEqual("UUID", String(anyHashables[2].base.dynamicType)) + expectEqual("UUID", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("UUID", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("UUID", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestUserInfo.swift b/test/1_stdlib/TestUserInfo.swift index 0b66bcf9a1ade..f5cadc76a4296 100644 --- a/test/1_stdlib/TestUserInfo.swift +++ b/test/1_stdlib/TestUserInfo.swift @@ -124,9 +124,9 @@ class TestUserInfo : TestUserInfoSuper { Notification(name: Notification.Name(rawValue: "TestOtherSwiftNotification")), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Notification", String(anyHashables[0].base.dynamicType)) - expectEqual("Notification", String(anyHashables[1].base.dynamicType)) - expectEqual("Notification", String(anyHashables[2].base.dynamicType)) + expectEqual("Notification", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Notification", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Notification", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -138,9 +138,9 @@ class TestUserInfo : TestUserInfoSuper { NSNotification(name: Notification.Name(rawValue: "TestOtherSwiftNotification"), object: nil), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Notification", String(anyHashables[0].base.dynamicType)) - expectEqual("Notification", String(anyHashables[1].base.dynamicType)) - expectEqual("Notification", String(anyHashables[2].base.dynamicType)) + expectEqual("Notification", String(describing: anyHashables[0].base.dynamicType)) + expectEqual("Notification", String(describing: anyHashables[1].base.dynamicType)) + expectEqual("Notification", String(describing: anyHashables[2].base.dynamicType)) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/UnsafePointer.swift.gyb b/test/1_stdlib/UnsafePointer.swift.gyb index 0705a8a0abfb0..ad28cc15cdcf1 100644 --- a/test/1_stdlib/UnsafePointer.swift.gyb +++ b/test/1_stdlib/UnsafePointer.swift.gyb @@ -407,9 +407,9 @@ ${SelfName}TestSuite.test("customMirror") { let mirror = ptr.customMirror expectEqual(1, mirror.children.count) #if arch(i386) || arch(arm) - expectEqual("18446744071562067968", String(mirror.children.first!.1)) + expectEqual("18446744071562067968", String(describing: mirror.children.first!.1)) #elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) - expectEqual("9223372036854775808", String(mirror.children.first!.1)) + expectEqual("9223372036854775808", String(describing: mirror.children.first!.1)) #else fatalError("Unimplemented") #endif diff --git a/test/Interpreter/SDK/Foundation_test.swift b/test/Interpreter/SDK/Foundation_test.swift index 579acb7924e6d..4b888438ddc46 100644 --- a/test/Interpreter/SDK/Foundation_test.swift +++ b/test/Interpreter/SDK/Foundation_test.swift @@ -191,7 +191,7 @@ FoundationTestSuite.test("rdar://17584531") { // Type checker used to be confused by this. var dict: NSDictionary = ["status": 200, "people": [["id": 255, "name": ["first": "John", "last": "Appleseed"]]]] var dict2 = dict["people"].map { $0 as AnyObject }?[0] as! NSDictionary - expectEqual("Optional(255)", String(dict2["id"])) + expectEqual("Optional(255)", String(describing: dict2["id"])) } FoundationTestSuite.test("DarwinBoolean smoke test") {