|
7 | 7 |
|
8 | 8 | % import os.path
|
9 | 9 | % import gyb
|
10 |
| -% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal |
| 10 | +% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal, sliceTypeName, defaultIndicesForTraversal |
11 | 11 |
|
12 | 12 | import StdlibUnittest
|
13 | 13 | import StdlibCollectionUnittest
|
@@ -788,4 +788,44 @@ CollectionTypeTests.test("_withUnsafeMutableBufferPointerIfSupported/dispatch")
|
788 | 788 | expectCustomizable(tester, tester.log._withUnsafeMutableBufferPointerIfSupported)
|
789 | 789 | }
|
790 | 790 |
|
| 791 | + |
| 792 | +//===----------------------------------------------------------------------===// |
| 793 | +// Associated Type Inference |
| 794 | +//===----------------------------------------------------------------------===// |
| 795 | + |
| 796 | +// This section verifies that only the absolutely minimal protocol requirements |
| 797 | +// are required to declare each kind of collection. All remaining requirements |
| 798 | +// and associated types should be either inferred from the declared properties |
| 799 | +// and methods or inherited as defaults via protocol extension. |
| 800 | + |
| 801 | +struct FatalIndex : Comparable { } |
| 802 | +func <(lhs: FatalIndex, rhs: FatalIndex) -> Bool { fatalError() } |
| 803 | +func ==(lhs: FatalIndex, rhs: FatalIndex) -> Bool { fatalError() } |
| 804 | + |
| 805 | +% for Traversal in TRAVERSALS: |
| 806 | +% Collection = collectionForTraversal(Traversal) |
| 807 | +% Self = 'Fatal' + Collection |
| 808 | +% Slice = sliceTypeName(Traversal, False, False) |
| 809 | +% Indices = defaultIndicesForTraversal(Traversal) |
| 810 | + |
| 811 | +struct ${Self}<T> : ${Collection} { |
| 812 | + var startIndex: FatalIndex { fatalError() } |
| 813 | + var endIndex: FatalIndex { fatalError() } |
| 814 | + subscript(i: FatalIndex) -> T { fatalError() } |
| 815 | + func index(after i: FatalIndex) -> FatalIndex { fatalError() } |
| 816 | +% if Traversal in ['Bidirectional', 'RandomAccess']: |
| 817 | + func index(before i: FatalIndex) -> FatalIndex { fatalError() } |
| 818 | +% end |
| 819 | +} |
| 820 | + |
| 821 | +CollectionTypeTests.test("AssociatedTypes/${Collection}") { |
| 822 | + expectTrue(${Self}<Void>.Index.self == FatalIndex.self) |
| 823 | + expectTrue(${Self}<Void>.Indices.self == ${Indices}<${Self}<Void>>.self) |
| 824 | + expectTrue(${Self}<Void>.IndexDistance.self == Int.self) |
| 825 | + expectTrue(${Self}<Void>.Iterator.self == IndexingIterator<${Self}<Void>>.self) |
| 826 | + expectTrue(${Self}<Void>.SubSequence.self == ${Slice}<${Self}<Void>>.self) |
| 827 | +} |
| 828 | +% end |
| 829 | + |
| 830 | + |
791 | 831 | runAllTests()
|
0 commit comments