mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* 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
170 lines
5.1 KiB
Plaintext
170 lines
5.1 KiB
Plaintext
%{
|
|
# This is a template of validation-test/stdlib/Slice/*.swift
|
|
#
|
|
# cd validation-test/stdlib/Slice
|
|
# ../../../utils/gyb --line-directive="" Inputs/Template.swift.gyb | ../../../utils/split_file.py
|
|
|
|
from gyb_stdlib_support import (
|
|
TRAVERSALS,
|
|
collectionForTraversal,
|
|
collectionTypeName
|
|
)
|
|
|
|
import itertools
|
|
|
|
class TestParameters(object):
|
|
name = ''
|
|
prefix = []
|
|
suffix = []
|
|
base = ''
|
|
traversal = ''
|
|
mutable = False
|
|
range_replaceable = False
|
|
base_kind = ''
|
|
|
|
def all_tests():
|
|
for traversal, base_kind, mutable, range_replaceable in itertools.product(
|
|
TRAVERSALS,
|
|
['Defaulted', 'Minimal'],
|
|
[False, True],
|
|
[False, True]):
|
|
test = TestParameters()
|
|
test.traversal = traversal
|
|
test.base_kind = base_kind
|
|
test.mutable = mutable
|
|
test.range_replaceable = range_replaceable
|
|
test.base = base_kind + collectionTypeName(
|
|
traversal=traversal,
|
|
mutable=mutable,
|
|
rangeReplaceable=range_replaceable)
|
|
|
|
for name, prefix, suffix in [
|
|
('FullWidth', '[]', '[]'),
|
|
('WithPrefix', '[-9999, -9998, -9997]', '[]'),
|
|
('WithSuffix', '[]', '[ -9999, -9998, -9997]'),
|
|
('WithPrefixAndSuffix', '[-9999, -9998, -9997, -9996, -9995]',
|
|
'[-9994, -9993, -9992]')
|
|
]:
|
|
test.name = 'Slice_Of_' + test.base + '_' + name + '.swift'
|
|
test.prefix = prefix
|
|
test.suffix
|
|
yield test
|
|
|
|
def test_methods(test):
|
|
traversal = test.traversal
|
|
mutable = test.mutable
|
|
range_replaceable = test.range_replaceable
|
|
name = collectionForTraversal(traversal)
|
|
result = []
|
|
if range_replaceable:
|
|
result.append('RangeReplaceable' + name.replace('Collection', 'Slice'))
|
|
|
|
if mutable:
|
|
result.append('Mutable' + name)
|
|
|
|
if not range_replaceable and not mutable:
|
|
result.append(name)
|
|
|
|
return result
|
|
|
|
}%
|
|
|
|
% for test in all_tests():
|
|
// BEGIN ${test.name}
|
|
// -*- 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] = ${test.prefix}
|
|
let suffix: [Int] = ${test.suffix}
|
|
|
|
func makeCollection(elements: [OpaqueValue<Int>])
|
|
-> Slice<${test.base}<OpaqueValue<Int>>> {
|
|
var baseElements = prefix.map(OpaqueValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
|
|
let base = ${test.base}(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<${test.base}<MinimalEquatableValue>> {
|
|
var baseElements = prefix.map(MinimalEquatableValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
|
|
let base = ${test.base}(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<${test.base}<MinimalComparableValue>> {
|
|
var baseElements = prefix.map(MinimalComparableValue.init)
|
|
baseElements.append(contentsOf: elements)
|
|
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
|
|
let base = ${test.base}(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
|
|
|
|
% for method in test_methods(test):
|
|
SliceTests.add${method}Tests(
|
|
"${test.name}.",
|
|
makeCollection: makeCollection,
|
|
wrapValue: identity,
|
|
extractValue: identity,
|
|
makeCollectionOfEquatable: makeCollectionOfEquatable,
|
|
wrapValueIntoEquatable: identityEq,
|
|
extractValueFromEquatable: identityEq,
|
|
% if 'Mutable' in method:
|
|
makeCollectionOfComparable: makeCollectionOfComparable,
|
|
wrapValueIntoComparable: identityComp,
|
|
extractValueFromComparable: identityComp,
|
|
% end
|
|
resiliencyChecks: resiliencyChecks,
|
|
outOfBoundsIndexOffset: 6
|
|
% if 'Mutable' in method:
|
|
, withUnsafeMutableBufferPointerIsSupported: false,
|
|
isFixedLengthCollection: true
|
|
% end
|
|
)
|
|
% end
|
|
|
|
runAllTests()
|
|
% end
|