mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Removing the “checksAdded” parameter from collection unit tests and simply sharing a global variable is a better way to go. We don't use threads at that level, so there's no thread safety issue, and we already committed to globals when we introduced the logging wrappers.
119 lines
4.9 KiB
Swift
119 lines
4.9 KiB
Swift
// -*- swift -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Automatically Generated From validation-test/stdlib/Slice/Inputs/Template.swift.gyb
|
|
// Do Not Edit Directly!
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RUN: rm -rf %t
|
|
// RUN: mkdir -p %t
|
|
// RUN: %S/../../../utils/gyb %s -o %t/main.swift
|
|
// RUN: %S/../../../utils/line-directive %t/main.swift -- %target-build-swift %t/main.swift -o %t/MutableRangeReplaceableRandomAccessSlice_Of_MinimalMutableRangeReplaceableRandomAccessCollection_WithPrefix.swift.gyb.a.out
|
|
// RUN: %S/../../../utils/line-directive %t/main.swift -- %target-run %t/MutableRangeReplaceableRandomAccessSlice_Of_MinimalMutableRangeReplaceableRandomAccessCollection_WithPrefix.swift.gyb.a.out
|
|
// REQUIRES: executable_test
|
|
|
|
// FIXME: the test is too slow when the standard library is not optimized.
|
|
// REQUIRES: optimized_stdlib
|
|
|
|
import StdlibUnittest
|
|
import StdlibCollectionUnittest
|
|
|
|
// Also import modules which are used by StdlibUnittest internally. This
|
|
// workaround is needed to link all required libraries in case we compile
|
|
// StdlibUnittest with -sil-serialize-all.
|
|
import SwiftPrivate
|
|
#if _runtime(_ObjC)
|
|
import ObjectiveC
|
|
#endif
|
|
|
|
var SliceTests = TestSuite("Collection")
|
|
|
|
let prefix: [Int] = [-9999, -9998, -9997]
|
|
let suffix: [Int] = []
|
|
|
|
func makeCollection(elements: [OpaqueValue<Int>])
|
|
-> MutableRangeReplaceableRandomAccessSlice<MinimalMutableRangeReplaceableRandomAccessCollection<OpaqueValue<Int>>> {
|
|
var baseElements = prefix.map(OpaqueValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
|
|
let base = MinimalMutableRangeReplaceableRandomAccessCollection(elements: baseElements)
|
|
let startIndex = base.index(
|
|
base.startIndex,
|
|
offsetBy: numericCast(prefix.count))
|
|
let endIndex = base.index(
|
|
base.startIndex,
|
|
offsetBy: numericCast(prefix.count + elements.count))
|
|
return MutableRangeReplaceableRandomAccessSlice(
|
|
base: base,
|
|
bounds: startIndex..<endIndex)
|
|
}
|
|
|
|
func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
|
|
-> MutableRangeReplaceableRandomAccessSlice<MinimalMutableRangeReplaceableRandomAccessCollection<MinimalEquatableValue>> {
|
|
var baseElements = prefix.map(MinimalEquatableValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
|
|
let base = MinimalMutableRangeReplaceableRandomAccessCollection(elements: baseElements)
|
|
let startIndex = base.index(
|
|
base.startIndex,
|
|
offsetBy: numericCast(prefix.count))
|
|
let endIndex = base.index(
|
|
base.startIndex,
|
|
offsetBy: numericCast(prefix.count + elements.count))
|
|
return MutableRangeReplaceableRandomAccessSlice(
|
|
base: base,
|
|
bounds: startIndex..<endIndex)
|
|
}
|
|
|
|
func makeCollectionOfComparable(elements: [MinimalComparableValue])
|
|
-> MutableRangeReplaceableRandomAccessSlice<MinimalMutableRangeReplaceableRandomAccessCollection<MinimalComparableValue>> {
|
|
var baseElements = prefix.map(MinimalComparableValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
|
|
let base = MinimalMutableRangeReplaceableRandomAccessCollection(elements: baseElements)
|
|
let startIndex = base.index(
|
|
base.startIndex,
|
|
offsetBy: numericCast(prefix.count))
|
|
let endIndex = base.index(
|
|
base.startIndex,
|
|
offsetBy: numericCast(prefix.count + elements.count))
|
|
return MutableRangeReplaceableRandomAccessSlice(
|
|
base: base,
|
|
bounds: startIndex..<endIndex)
|
|
}
|
|
|
|
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
|
|
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
|
|
resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior = .trap
|
|
resiliencyChecks.subscriptRangeOnOutOfBoundsRangesBehavior = .trap
|
|
|
|
SliceTests.addRangeReplaceableRandomAccessSliceTests(
|
|
"MutableRangeReplaceableRandomAccessSlice_Of_MinimalMutableRangeReplaceableRandomAccessCollection_WithPrefix.swift.gyb.",
|
|
makeCollection: makeCollection,
|
|
wrapValue: identity,
|
|
extractValue: identity,
|
|
makeCollectionOfEquatable: makeCollectionOfEquatable,
|
|
wrapValueIntoEquatable: identityEq,
|
|
extractValueFromEquatable: identityEq,
|
|
resiliencyChecks: resiliencyChecks,
|
|
outOfBoundsIndexOffset: 6
|
|
)
|
|
SliceTests.addMutableRandomAccessCollectionTests(
|
|
"MutableRangeReplaceableRandomAccessSlice_Of_MinimalMutableRangeReplaceableRandomAccessCollection_WithPrefix.swift.gyb.",
|
|
makeCollection: makeCollection,
|
|
wrapValue: identity,
|
|
extractValue: identity,
|
|
makeCollectionOfEquatable: makeCollectionOfEquatable,
|
|
wrapValueIntoEquatable: identityEq,
|
|
extractValueFromEquatable: identityEq,
|
|
makeCollectionOfComparable: makeCollectionOfComparable,
|
|
wrapValueIntoComparable: identityComp,
|
|
extractValueFromComparable: identityComp,
|
|
resiliencyChecks: resiliencyChecks,
|
|
outOfBoundsIndexOffset: 6
|
|
, withUnsafeMutableBufferPointerIsSupported: false,
|
|
isFixedLengthCollection: true
|
|
)
|
|
|
|
runAllTests()
|