File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -435,6 +435,11 @@ public struct ${Self}<Base : ${BaseRequirements}>
435
435
% else:
436
436
internal let _base: Base
437
437
% end
438
+
439
+ /// The underlying collection of the slice.
440
+ public var base: Base {
441
+ return _base
442
+ }
438
443
}
439
444
440
445
% end
Original file line number Diff line number Diff line change @@ -18,6 +18,32 @@ import StdlibCollectionUnittest
18
18
import SwiftPrivate
19
19
20
20
21
+ /// Reference-type collection for testing the `base` property.
22
+ class ReferenceCollection : RandomAccessCollection {
23
+ typealias Index = Int
24
+
25
+ var startIndex : Int {
26
+ return 0
27
+ }
28
+
29
+ var endIndex : Int {
30
+ return 1
31
+ }
32
+
33
+ subscript( index: Int ) -> String {
34
+ return " "
35
+ }
36
+
37
+ func index( after i: Int ) -> Int {
38
+ return 1
39
+ }
40
+
41
+ func index( before i: Int ) -> Int {
42
+ return 0
43
+ }
44
+ }
45
+
46
+
21
47
var SliceTests = TestSuite ( " Collection " )
22
48
23
49
//===----------------------------------------------------------------------===//
@@ -69,6 +95,14 @@ SliceTests.test("${Slice}/init(base:bounds:)") {
69
95
}
70
96
}
71
97
98
+ % if RangeReplaceable == False and Mutable == False:
99
+ SliceTests. test ( " ${Slice}/baseProperty " ) {
100
+ let referenceCollection = ReferenceCollection ( )
101
+ let testSlice = ${ Slice} ( base: referenceCollection, bounds: 0 ..< 1 )
102
+ expectTrue ( testSlice. base === referenceCollection)
103
+ }
104
+ % end
105
+
72
106
SliceTests. test( " ${Slice}.{startIndex,endIndex} " ) {
73
107
for test in subscriptRangeTests {
74
108
let c = ${ Collection} ( elements: test. collection)
You can’t perform that action at this time.
0 commit comments