-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathSlice.swift.gyb
114 lines (95 loc) · 3.34 KB
/
Slice.swift.gyb
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
// -*- swift -*-
// RUN: rm -rf %t ; mkdir -p %t
// RUN: %S/../../utils/gyb %s -o %t/Slice.swift
// RUN: %S/../../utils/line-directive %t/Slice.swift -- %target-build-swift %t/Slice.swift -o %t/a.out
// RUN: %S/../../utils/line-directive %t/Slice.swift -- %target-run %t/a.out
// REQUIRES: executable_test
%{
from gyb_stdlib_support import (
TRAVERSALS,
sliceTypeName,
defaultIndicesForTraversal
)
}%
import StdlibUnittest
import StdlibCollectionUnittest
import SwiftPrivate
var SliceTests = TestSuite("Collection")
//===----------------------------------------------------------------------===//
// Slice<Base>
//===----------------------------------------------------------------------===//
% for Traversal in TRAVERSALS:
% for Mutable in [ False, True ]:
% for RangeReplaceable in [ False, True ]:
% Slice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Collection = 'Minimal' + Slice.replace('Slice', 'Collection')
SliceTests.test("${Slice}/AssociatedTypes") {
do {
typealias Collection = ${Collection}<OpaqueValue<Int>>
typealias CollectionSlice = ${Slice}<Collection>
expectSliceType(CollectionSlice.self)
expectCollectionAssociatedTypes(
collectionType: CollectionSlice.self,
iteratorType: IndexingIterator<CollectionSlice>.self,
subSequenceType: CollectionSlice.self,
indexType: MinimalIndex.self,
indexDistanceType: Int.self,
indicesType: ${defaultIndicesForTraversal(Traversal)}<CollectionSlice>.self)
}
func checkStaticTypealiases1<Base : Collection>(_: Base) {
expectEqualType(Base.Index.self, Slice<Base>.Index.self)
}
func checkStaticTypealiases2<
Base : MutableCollection
>(_: Base) {
expectEqualType(Base.Index.self, MutableSlice<Base>.Index.self)
}
}
SliceTests.test("${Slice}/init(base:bounds:)") {
for test in subscriptRangeTests {
let base = ${Collection}(elements: test.collection)
var slice = ${Slice}(base: base, bounds: test.bounds(in: base))
expectType(${Slice}<${Collection}<OpaqueValue<Int>>>.self, &slice)
checkCollection(
slice,
expected: test.expected,
stackTrace: SourceLocStack().with(test.loc))
{ $0.value == $1.value }
}
}
SliceTests.test("${Slice}.{startIndex,endIndex}") {
for test in subscriptRangeTests {
let c = ${Collection}(elements: test.collection)
let bounds = test.bounds(in: c)
var slice = ${Slice}(base: c, bounds: bounds)
expectType(${Slice}<${Collection}<OpaqueValue<Int>>>.self, &slice)
expectEqual(bounds.lowerBound, slice.startIndex)
expectEqual(bounds.upperBound, slice.endIndex)
}
}
% end
% end
% end
//===----------------------------------------------------------------------===//
// MutableSlice<Base>
//===----------------------------------------------------------------------===//
/*
FIXME: uncomment this test when the following bug is fixed:
<rdar://problem/21935030> Recast Slice and MutableSlice in terms of Collection
and MutableCollection
extension MutableSlice {
func _checkBaseSubSequenceElementIsElement() {
Element.self,
Iterator.Element.self)
expectEqualType(
Element.self,
Iterator.Element.self,
Base.Iterator.Element.self)
expectEqualType(
Element.self,
Iterator.Element.self,
Base.SubSequence.Iterator.Element.self)
}
}
*/
runAllTests()