1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
%{
# 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: prefix.count)
let endIndex = base.index(
base.startIndex,
offsetBy: 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: prefix.count)
let endIndex = base.index(
base.startIndex,
offsetBy: 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: prefix.count)
let endIndex = base.index(
base.startIndex,
offsetBy: 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
|