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.
108 lines
4.0 KiB
Swift
108 lines
4.0 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/MutableSlice_Of_MinimalMutableCollection_WithPrefixAndSuffix.swift.gyb.a.out
|
|
// RUN: %S/../../../utils/line-directive %t/main.swift -- %target-run %t/MutableSlice_Of_MinimalMutableCollection_WithPrefixAndSuffix.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, -9996, -9995]
|
|
let suffix: [Int] = []
|
|
|
|
func makeCollection(elements: [OpaqueValue<Int>])
|
|
-> MutableSlice<MinimalMutableCollection<OpaqueValue<Int>>> {
|
|
var baseElements = prefix.map(OpaqueValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
|
|
let base = MinimalMutableCollection(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 MutableSlice(
|
|
base: base,
|
|
bounds: startIndex..<endIndex)
|
|
}
|
|
|
|
func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
|
|
-> MutableSlice<MinimalMutableCollection<MinimalEquatableValue>> {
|
|
var baseElements = prefix.map(MinimalEquatableValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
|
|
let base = MinimalMutableCollection(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 MutableSlice(
|
|
base: base,
|
|
bounds: startIndex..<endIndex)
|
|
}
|
|
|
|
func makeCollectionOfComparable(elements: [MinimalComparableValue])
|
|
-> MutableSlice<MinimalMutableCollection<MinimalComparableValue>> {
|
|
var baseElements = prefix.map(MinimalComparableValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
|
|
let base = MinimalMutableCollection(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 MutableSlice(
|
|
base: base,
|
|
bounds: startIndex..<endIndex)
|
|
}
|
|
|
|
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
|
|
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
|
|
resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior = .trap
|
|
resiliencyChecks.subscriptRangeOnOutOfBoundsRangesBehavior = .trap
|
|
|
|
SliceTests.addMutableCollectionTests(
|
|
"MutableSlice_Of_MinimalMutableCollection_WithPrefixAndSuffix.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()
|