Skip to content

Commit aa384c6

Browse files
authored
Merge pull request #4812 from apple/stdlib-tests-for-repeated
stdlib: Improve tests for Repeated<Element>
2 parents 92d932d + f06c343 commit aa384c6

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

test/stdlib/Repeat.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

validation-test/stdlib/Lazy.swift.gyb

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var LazyTestSuite = TestSuite("Lazy")
2323
protocol TestProtocol1 {}
2424

2525
//===----------------------------------------------------------------------===//
26-
// Repeated
26+
// repeatElement(), Repeated<Element>
2727
//===----------------------------------------------------------------------===//
2828

2929
// Check that the generic parameter is called 'Element'.
@@ -33,20 +33,40 @@ extension Repeated where Element : TestProtocol1 {
3333
}
3434
}
3535

36-
LazyTestSuite.test("Repeated") {
37-
checkRandomAccessCollection(
38-
[] as Array<OpaqueValue<Int>>,
39-
repeatElement(OpaqueValue(42), count: 0))
40-
{ $0.value == $1.value }
36+
LazyTestSuite.test("Repeated/AssociatedTypes") {
37+
typealias Subject = Repeated<OpaqueValue<Int>>
38+
expectRandomAccessCollectionAssociatedTypes(
39+
collectionType: Subject.self,
40+
iteratorType: IndexingIterator<Subject>.self,
41+
subSequenceType: RandomAccessSlice<Subject>.self,
42+
indexType: Int.self,
43+
indexDistanceType: Int.self,
44+
indicesType: CountableRange<Int>.self)
45+
}
4146

42-
checkRandomAccessCollection(
43-
[ OpaqueValue(42) ] as Array<OpaqueValue<Int>>,
44-
repeatElement(OpaqueValue(42), count: 1))
45-
{ $0.value == $1.value }
47+
LazyTestSuite.test("repeatedValue()/TypeInference") {
48+
var r = repeatElement(OpaqueValue(42), count: 42)
49+
expectType(Repeated<OpaqueValue<Int>>.self, &r)
50+
}
51+
52+
LazyTestSuite.test("repeatedValue()/NegativeCount") {
53+
expectCrashLater()
54+
_ = repeatElement(OpaqueValue(42), count: -1)
55+
}
56+
57+
LazyTestSuite.test("Repeated")
58+
.forEach(in: [ 0, 1, 3 ]) {
59+
count in
60+
61+
let c = repeatElement(OpaqueValue(42), count: count)
62+
expectEqual(0, c.startIndex)
63+
expectEqual(count, c.endIndex)
64+
expectEqual(count, c.count)
65+
expectEqual(42, c.repeatedValue.value)
4666

67+
let expected = (0..<count).map { _ in OpaqueValue(42) }
4768
checkRandomAccessCollection(
48-
[ OpaqueValue(42), OpaqueValue(42), OpaqueValue(42) ] as Array<OpaqueValue<Int>>,
49-
repeatElement(OpaqueValue(42), count: 3))
69+
expected, c)
5070
{ $0.value == $1.value }
5171
}
5272

0 commit comments

Comments
 (0)