Skip to content

Commit 4c2dbe1

Browse files
CodaFitkremenek
authored andcommitted
[stdlib][SE-0089] Finish off Lossless String Conversion (#3761)
* Rename string reflection init * Addressing PR comments and updating some tests * Update test suite for lossless string conversion
1 parent b712f0e commit 4c2dbe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+266
-180
lines changed

benchmark/single-source/unit-tests/ObjectiveCBridging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public func run_ObjectiveCBridgeFromNSStringForced(_ N: Int) {
7373

7474
@inline(never)
7575
func testObjectiveCBridgeToNSString() {
76-
let nativeString = String("Native")
76+
let nativeString = "Native"
7777

7878
var s: NSString?
7979
for _ in 0 ..< 10_000 {

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ extension TestSuite {
561561
return makeCollectionOfEquatable(elements.map(wrapValueIntoEquatable))
562562
}
563563

564-
testNamePrefix += String(C.Type.self)
564+
testNamePrefix += String(describing: C.Type.self)
565565

566566
//===------------------------------------------------------------------===//
567567
// generate()
@@ -1209,7 +1209,7 @@ extension TestSuite {
12091209
return makeCollection(elements.map(wrapValue))
12101210
}
12111211

1212-
testNamePrefix += String(C.Type.self)
1212+
testNamePrefix += String(describing: C.Type.self)
12131213

12141214
// FIXME: swift-3-indexing-model - add tests for the follow?
12151215
// index(before: of i: Index) -> Index
@@ -1522,7 +1522,7 @@ extension TestSuite {
15221522

15231523
addBidirectionalCollectionTests(${forwardTestArgs})
15241524

1525-
testNamePrefix += String(C.Type.self)
1525+
testNamePrefix += String(describing: C.Type.self)
15261526

15271527
func makeWrappedCollection(_ elements: [OpaqueValue<Int>]) -> C {
15281528
return makeCollection(elements.map(wrapValue))

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ extension TestSuite {
148148
return makeCollectionOfComparable(elements.map(wrapValueIntoComparable))
149149
}
150150

151-
testNamePrefix += String(C.Type.self)
151+
testNamePrefix += String(describing: C.Type.self)
152152

153153
//===----------------------------------------------------------------------===//
154154
// subscript(_: Index)
@@ -749,7 +749,7 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") {
749749
return makeCollection(elements.map(wrapValue))
750750
}
751751

752-
testNamePrefix += String(C.Type.self)
752+
testNamePrefix += String(describing: C.Type.self)
753753

754754
//===----------------------------------------------------------------------===//
755755
// subscript(_: Index)
@@ -906,7 +906,7 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
906906
return makeCollectionOfComparable(elements.map(wrapValueIntoComparable))
907907
}
908908

909-
testNamePrefix += String(C.Type.self)
909+
testNamePrefix += String(describing: C.Type.self)
910910

911911
//===----------------------------------------------------------------------===//
912912
// sort()

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ extension TestSuite {
497497
return makeCollection(elements.map(wrapValue))
498498
}
499499

500-
testNamePrefix += String(C.Type.self)
500+
testNamePrefix += String(describing: C.Type.self)
501501

502502
//===----------------------------------------------------------------------===//
503503
// init()
@@ -1218,7 +1218,7 @@ self.test("\(testNamePrefix).OperatorPlus") {
12181218
return makeCollection(elements.map(wrapValue))
12191219
}
12201220

1221-
testNamePrefix += String(C.Type.self)
1221+
testNamePrefix += String(describing: C.Type.self)
12221222

12231223
//===----------------------------------------------------------------------===//
12241224
// removeLast()
@@ -1340,7 +1340,7 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
13401340
resiliencyChecks: resiliencyChecks,
13411341
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
13421342

1343-
testNamePrefix += String(C.Type.self)
1343+
testNamePrefix += String(describing: C.Type.self)
13441344

13451345
// No extra checks for collections with random access traversal so far.
13461346
} // addRangeReplaceableRandomAccessCollectionTests

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension TestSuite {
6565
return makeCollection(elements.map(wrapValue))
6666
}
6767

68-
testNamePrefix += String(C.Type.self)
68+
testNamePrefix += String(describing: C.Type.self)
6969

7070
//===------------------------------------------------------------------===//
7171
// removeFirst()
@@ -210,7 +210,7 @@ extension TestSuite {
210210
return makeCollection(elements.map(wrapValue))
211211
}
212212

213-
testNamePrefix += String(C.Type.self)
213+
testNamePrefix += String(describing: C.Type.self)
214214

215215
//===------------------------------------------------------------------===//
216216
// removeLast()
@@ -351,7 +351,7 @@ extension TestSuite {
351351
resiliencyChecks: resiliencyChecks,
352352
outOfBoundsIndexOffset: outOfBoundsIndexOffset)
353353

354-
testNamePrefix += String(C.Type.self)
354+
testNamePrefix += String(describing: C.Type.self)
355355

356356
// No tests yet.
357357
} // addRangeReplaceableRandomAccessSliceTests

stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ extension TestSuite {
14841484
return makeSequenceOfEquatable(elements.map(wrapValueIntoEquatable))
14851485
}
14861486

1487-
testNamePrefix += String(S.Type.self)
1487+
testNamePrefix += String(describing: S.Type.self)
14881488

14891489
let isMultiPass = makeSequence([])
14901490
._preprocessingPass { true } ?? false

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public func == (lhs: TypeIdentifier, rhs: TypeIdentifier) -> Bool {
127127
extension TypeIdentifier
128128
: CustomStringConvertible, CustomDebugStringConvertible {
129129
public var description: String {
130-
return String(value)
130+
return String(describing: value)
131131
}
132132
public var debugDescription: String {
133133
return "TypeIdentifier(\(description))"

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,12 @@ public func checkStrideable<Instances : Collection, Strides : Collection>(
22152215
}
22162216
}
22172217

2218+
public func checkLosslessStringConvertible<Instance>(
2219+
_ instances: [Instance]
2220+
) where Instance : LosslessStringConvertible & Equatable {
2221+
expectEqualFunctionsForDomain(instances, { $0 }, { Instance(String($0))! })
2222+
}
2223+
22182224
public func nthIndex<C: Collection>(_ x: C, _ n: Int) -> C.Index {
22192225
return x.index(x.startIndex, offsetBy: numericCast(n))
22202226
}

stdlib/private/StdlibUnittest/StringConvertible.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ extension CustomPrintableValue : CustomDebugStringConvertible {
112112
public func expectPrinted<T>(
113113
expectedOneOf patterns: [String], _ object: T, ${TRACE}
114114
) {
115-
let actual = String(object)
115+
let actual = String(describing: object)
116116
if !patterns.contains(actual) {
117117
expectationFailure(
118118
"expected: any of \(String(reflecting: patterns))\n"

stdlib/public/core/AnyHashable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extension AnyHashable : Hashable {
151151

152152
extension AnyHashable : CustomStringConvertible {
153153
public var description: String {
154-
return String(base)
154+
return String(describing: base)
155155
}
156156
}
157157

0 commit comments

Comments
 (0)