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 170 171 172 173 174 175 176 177 178 179
|
%{
# This is a template of validation-test/stdlib/Collection/*.swift
#
# cd validation-test/stdlib/Collection
# ../../../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 = ''
ref_name = ''
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)
test.name = test.base + '.swift'
test.ref_name = test.base + 'OfRef.swift'
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)
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/Collection/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.
// rdar://problem/46878013
// REQUIRES: optimized_stdlib
import StdlibUnittest
import StdlibCollectionUnittest
var CollectionTests = TestSuite("Collection")
// Test collections using value types as elements.
do {
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
% for method in test_methods(test):
CollectionTests.add${method}Tests(
makeCollection: { (elements: [OpaqueValue<Int>]) in
return ${test.base}(elements: elements)
},
wrapValue: identity,
extractValue: identity,
makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) in
return ${test.base}(elements: elements)
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
% if 'Mutable' in method:
makeCollectionOfComparable: { (elements: [MinimalComparableValue]) in
return ${test.base}(elements: elements)
},
wrapValueIntoComparable: identityComp,
extractValueFromComparable: identityComp,
% end
resiliencyChecks: resiliencyChecks
% if 'Mutable' in method:
, withUnsafeMutableBufferPointerIsSupported: false,
isFixedLengthCollection: true
% end
)
% end
}
runAllTests()
// BEGIN ${test.ref_name}
// -*- swift -*-
//===----------------------------------------------------------------------===//
// Automatically Generated From validation-test/stdlib/Collection/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.
// rdar://problem/46878013
// REQUIRES: optimized_stdlib
import StdlibUnittest
import StdlibCollectionUnittest
var CollectionTests = TestSuite("Collection")
// Test collections using a reference type as element.
do {
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
% for method in test_methods(test):
CollectionTests.add${method}Tests(
makeCollection: { (elements: [LifetimeTracked]) in
return ${test.base}(elements: elements)
},
wrapValue: { (element: OpaqueValue<Int>) in
LifetimeTracked(element.value, identity: element.identity)
},
extractValue: { (element: LifetimeTracked) in
OpaqueValue(element.value, identity: element.identity)
},
makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) in
// FIXME: use LifetimeTracked.
return ${test.base}(elements: elements)
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
% if 'Mutable' in method:
makeCollectionOfComparable: { (elements: [MinimalComparableValue]) in
// FIXME: use LifetimeTracked.
return ${test.base}(elements: elements)
},
wrapValueIntoComparable: identityComp,
extractValueFromComparable: identityComp,
% end
resiliencyChecks: resiliencyChecks
% if 'Mutable' in method:
, withUnsafeMutableBufferPointerIsSupported: false,
isFixedLengthCollection: true
% end
)
% end
}
runAllTests()
% end
|