Skip to content

Commit b50db27

Browse files
committed
[test] Update tests for stdlib behavior changes
1 parent ba3c403 commit b50db27

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func checkSortedPredicateThrow(
512512
}
513513
}
514514

515-
self.test("\(testNamePrefix).sorted/DispatchesThrough_withUnsafeMutableBufferPointerIfSupported/WhereElementIsComparable") {
515+
self.test("\(testNamePrefix).sorted/DispatchesThroughDirectStorageAccessors/WhereElementIsComparable") {
516516
let sequence = [ 5, 4, 3, 2, 1 ]
517517
let elements: [MinimalComparableValue] =
518518
zip(sequence, 0..<sequence.count).map {
@@ -525,13 +525,16 @@ self.test("\(testNamePrefix).sorted/DispatchesThrough_withUnsafeMutableBufferPoi
525525
let result = lc.sorted()
526526
let extractedResult = result.map(extractValueFromComparable)
527527

528+
let actualWUMBPIF = lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)]
529+
let actualWCMSIA = lc.log.withContiguousMutableStorageIfAvailable[type(of: lc)]
530+
531+
let actualWUMBPIFNonNil = lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)]
532+
let actualWCMSIANonNil = lc.log.withContiguousMutableStorageIfAvailableNonNilReturns[type(of: lc)]
533+
528534
// This sort operation is not in-place.
529535
// The collection is copied into an array before sorting.
530-
expectEqual(
531-
0, lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)])
532-
expectEqual(
533-
0,
534-
lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)])
536+
expectEqual(0, actualWUMBPIF + actualWCMSIA)
537+
expectEqual(0, actualWUMBPIFNonNil + actualWCMSIANonNil)
535538

536539
expectEqualSequence([ 1, 2, 3, 4, 5 ], extractedResult.map { $0.value })
537540
}
@@ -631,7 +634,7 @@ self.test("\(testNamePrefix).sorted/ThrowingPredicateWithLargeNumberElements") {
631634
}
632635

633636

634-
self.test("\(testNamePrefix).sorted/DispatchesThrough_withUnsafeMutableBufferPointerIfSupported/Predicate") {
637+
self.test("\(testNamePrefix).sorted/DispatchesThroughDirectStorageAccessors/Predicate") {
635638
let sequence = [ 5, 4, 3, 2, 1 ]
636639
let elements: [OpaqueValue<Int>] =
637640
zip(sequence, 0..<sequence.count).map {
@@ -644,13 +647,16 @@ self.test("\(testNamePrefix).sorted/DispatchesThrough_withUnsafeMutableBufferPoi
644647
let result = lc.sorted { extractValue($0).value < extractValue($1).value }
645648
let extractedResult = result.map(extractValue)
646649

650+
let actualWUMBPIF = lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)]
651+
let actualWCMSIA = lc.log.withContiguousMutableStorageIfAvailable[type(of: lc)]
652+
653+
let actualWUMBPIFNonNil = lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)]
654+
let actualWUMBPIFNonNil = lc.log.withContiguousMutableStorageIfAvailableNonNilReturns[type(of: lc)]
655+
647656
// This sort operation is not in-place.
648657
// The collection is copied into an array before sorting.
649-
expectEqual(
650-
0, lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)])
651-
expectEqual(
652-
0,
653-
lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)])
658+
expectEqual(0, actualWUMBPIF + actualWCMSIA)
659+
expectEqual(0, actualWUMBPIFNonNil + actualWUMBPIFNonNil)
654660

655661
expectEqualSequence([ 1, 2, 3, 4, 5 ], extractedResult.map { $0.value })
656662
}
@@ -949,7 +955,7 @@ self.test("\(testNamePrefix).reverse()") {
949955
// partition(by:)
950956
//===----------------------------------------------------------------------===//
951957

952-
self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBufferPointerIfSupported") {
958+
self.test("\(testNamePrefix).partition/DispatchesThroughDirectStorageAccessors") {
953959
let sequence = [ 5, 4, 3, 2, 1 ]
954960
let elements: [OpaqueValue<Int>] =
955961
zip(sequence, 0..<sequence.count).map {
@@ -965,11 +971,23 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
965971
return !(extractValue(val).value < extractValue(first!).value)
966972
})
967973

968-
expectEqual(
969-
1, lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)])
974+
let actualWUMBPIF = lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)]
975+
let actualWCMSIA = lc.log.withContiguousMutableStorageIfAvailable[type(of: lc)]
976+
977+
let actualWUMBPIFNonNil = lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)]
978+
let actualWUMBPIFNonNil = lc.log.withContiguousMutableStorageIfAvailableNonNilReturns[type(of: lc)]
979+
980+
expectEqual(1, actualWUMBPIF + actualWCMSIA)
970981
expectEqual(
971982
withUnsafeMutableBufferPointerIsSupported ? 1 : 0,
972-
lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)])
983+
actualWUMBPIFNonNil + actualWUMBPIFNonNil)
984+
985+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
986+
// `partition(by:)` is expected to dispatch to the public API in releases
987+
// that contain https://github.com/apple/swift/pull/36003.
988+
expectEqual(0, actualWUMBPIF)
989+
expectEqual(0, actualWUMBPIFNonNil)
990+
}
973991

974992
expectEqual(4, lc.distance(from: lc.startIndex, to: pivot))
975993
expectEqualsUnordered([1, 2, 3, 4], lc.prefix(upTo: pivot).map { extractValue($0).value })

0 commit comments

Comments
 (0)