Skip to content

Commit d08cbd6

Browse files
ultramiraculousChris Williams
authored andcommitted
Test for Slice.base
1 parent e4ab106 commit d08cbd6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

validation-test/stdlib/Slice.swift.gyb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ import StdlibCollectionUnittest
1818
import SwiftPrivate
1919

2020

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+
2147
var SliceTests = TestSuite("Collection")
2248

2349
//===----------------------------------------------------------------------===//
@@ -69,6 +95,14 @@ SliceTests.test("${Slice}/init(base:bounds:)") {
6995
}
7096
}
7197

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+
72106
SliceTests.test("${Slice}.{startIndex,endIndex}") {
73107
for test in subscriptRangeTests {
74108
let c = ${Collection}(elements: test.collection)

0 commit comments

Comments
 (0)