Files
swift-mirror/validation-test/stdlib/Slice/Slice_Of_DefaultedRandomAccessCollection_WithPrefix.swift
Ben Cohen 83823f5f7f [stdlib] Obsolete various compatibility shims in 5.0 (#19008)
* Obsolete ModifierSlice typealiases in 5.0

* Obsolete *Indexable in 5.0

* Obsolete IteratorOverOne/EmptyIterator in 5.0

* Obsolete lazy typealiases in 5.0

* Drop .characters from tests

* Obsolete old literal protocols in 5.0

* Obsolete Range conversion helpers in 5.0

* Obsolete IndexDistance helpers in 5.0

* Obsolete Unsafe compat helpers in 5.0

* Obsolete flatMap compatibility helper in 5.0

* Obsolete withMutableCharacters in 5.0

* Obsolete customPlaygroundQuickLook in 5.0

* Deprecate Zip2Sequence streams in 5.0

* Replace * with swift on lotsa stuff

* Back off obsoleting playground conformances for now
2018-08-28 13:20:25 -07:00

85 lines
3.1 KiB
Swift

// -*- swift -*-
//===----------------------------------------------------------------------===//
// Automatically Generated From validation-test/stdlib/Slice/Inputs/Template.swift.gyb
// Do Not Edit Directly!
//===----------------------------------------------------------------------===//
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// FIXME: the test is too slow when the standard library is not optimized.
// REQUIRES: optimized_stdlib
import StdlibUnittest
import StdlibCollectionUnittest
var SliceTests = TestSuite("Collection")
let prefix: [Int] = [-9999, -9998, -9997]
let suffix: [Int] = []
func makeCollection(elements: [OpaqueValue<Int>])
-> Slice<DefaultedRandomAccessCollection<OpaqueValue<Int>>> {
var baseElements = prefix.map(OpaqueValue.init)
baseElements.append(contentsOf: elements)
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
let base = DefaultedRandomAccessCollection(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 Slice(base: base, bounds: startIndex..<endIndex)
}
func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
-> Slice<DefaultedRandomAccessCollection<MinimalEquatableValue>> {
var baseElements = prefix.map(MinimalEquatableValue.init)
baseElements.append(contentsOf: elements)
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
let base = DefaultedRandomAccessCollection(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 Slice(base: base, bounds: startIndex..<endIndex)
}
func makeCollectionOfComparable(elements: [MinimalComparableValue])
-> Slice<DefaultedRandomAccessCollection<MinimalComparableValue>> {
var baseElements = prefix.map(MinimalComparableValue.init)
baseElements.append(contentsOf: elements)
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
let base = DefaultedRandomAccessCollection(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 Slice(base: base, bounds: startIndex..<endIndex)
}
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior = .trap
resiliencyChecks.subscriptRangeOnOutOfBoundsRangesBehavior = .trap
SliceTests.addRandomAccessCollectionTests(
"Slice_Of_DefaultedRandomAccessCollection_WithPrefix.swift.",
makeCollection: makeCollection,
wrapValue: identity,
extractValue: identity,
makeCollectionOfEquatable: makeCollectionOfEquatable,
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
resiliencyChecks: resiliencyChecks,
outOfBoundsIndexOffset: 6
)
runAllTests()