-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathMinimalMutableRangeReplaceableCollection.swift
125 lines (115 loc) · 4.76 KB
/
MinimalMutableRangeReplaceableCollection.swift
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
// -*- swift -*-
//===----------------------------------------------------------------------===//
// Automatically Generated From validation-test/stdlib/Collection/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/MinimalMutableRangeReplaceableCollection.swift.a.out
// RUN: %S/../../../utils/line-directive %t/main.swift -- %target-run %t/MinimalMutableRangeReplaceableCollection.swift.a.out
// REQUIRES: executable_test
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 CollectionTests = TestSuite("Collection")
// Test collections using value types as elements.
do {
var checksAdded: Box<Set<String>> = Box([])
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
CollectionTests.addRangeReplaceableCollectionTests(
makeCollection: { (elements: [OpaqueValue<Int>]) in
return MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValue: identity,
extractValue: identity,
makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) in
return MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
checksAdded: checksAdded,
resiliencyChecks: resiliencyChecks
)
CollectionTests.addMutableCollectionTests(
makeCollection: { (elements: [OpaqueValue<Int>]) in
return MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValue: identity,
extractValue: identity,
makeCollectionOfEquatable: { (elements: [MinimalEquatableValue]) in
return MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
makeCollectionOfComparable: { (elements: [MinimalComparableValue]) in
return MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValueIntoComparable: identityComp,
extractValueFromComparable: identityComp,
checksAdded: checksAdded,
resiliencyChecks: resiliencyChecks
, withUnsafeMutableBufferPointerIsSupported: false,
isFixedLengthCollection: true
)
}
// Test collections using a reference type as element.
do {
var checksAdded: Box<Set<String>> = Box([])
var resiliencyChecks = CollectionMisuseResiliencyChecks.all
resiliencyChecks.creatingOutOfBoundsIndicesBehavior = .trap
CollectionTests.addRangeReplaceableCollectionTests(
makeCollection: { (elements: [LifetimeTracked]) in
return MinimalMutableRangeReplaceableCollection(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 MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
checksAdded: checksAdded,
resiliencyChecks: resiliencyChecks
)
CollectionTests.addMutableCollectionTests(
makeCollection: { (elements: [LifetimeTracked]) in
return MinimalMutableRangeReplaceableCollection(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 MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValueIntoEquatable: identityEq,
extractValueFromEquatable: identityEq,
makeCollectionOfComparable: { (elements: [MinimalComparableValue]) in
// FIXME: use LifetimeTracked.
return MinimalMutableRangeReplaceableCollection(elements: elements)
},
wrapValueIntoComparable: identityComp,
extractValueFromComparable: identityComp,
checksAdded: checksAdded,
resiliencyChecks: resiliencyChecks
, withUnsafeMutableBufferPointerIsSupported: false,
isFixedLengthCollection: true
)
}
runAllTests()