// -*- swift -*- // RUN: %target-run-simple-swiftgyb // REQUIRES: executable_test %{ from gyb_stdlib_support import ( TRAVERSALS, collectionForTraversal, protocolsForCollectionFeatures, collectionTypeName ) }% import SwiftPrivate import StdlibUnittest import StdlibCollectionUnittest %for traversal in TRAVERSALS: // This comment is a workaround for gyb miscompiles nested loops % for mutable in [ False, True ]: // This comment is a workaround for gyb miscompiles nested loops % Self = 'Minimal' + collectionTypeName(traversal=traversal, mutable=mutable, rangeReplaceable=False) var ${Self}TestSuite = TestSuite("${Self}") ${Self}TestSuite.test("startIndex/InterchangeableCollections") { var c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) var c2 = c1 expectEqual(c1.startIndex, c1.startIndex) expectEqual(c2.startIndex, c2.startIndex) expectEqual(c1.startIndex, c2.startIndex) _blackHole(c2) } ${Self}TestSuite.test("startIndex/DifferentCollections") { let c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) expectEqual(c1.startIndex, c1.startIndex) expectEqual(c2.startIndex, c2.startIndex) let i1 = c1.startIndex let i2 = c2.startIndex expectCrashLater() _ = i1 == i2 } ${Self}TestSuite.test("endIndex/InterchangeableCollections") { var c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = c1 expectEqual(c1.endIndex, c1.endIndex) expectEqual(c2.endIndex, c2.endIndex) expectEqual(c1.endIndex, c2.endIndex) _blackHole(c2) } ${Self}TestSuite.test("endIndex/DifferentCollections") { let c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) expectEqual(c1.endIndex, c1.endIndex) expectEqual(c2.endIndex, c2.endIndex) let i1 = c1.endIndex let i2 = c2.endIndex expectCrashLater() _ = i1 == i2 } % if mutable: ${Self}TestSuite.test("subscript(_:Index)/InterchangeableCollections") { var c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = c1 var i1 = c1.startIndex c1[c1.startIndex] = OpaqueValue(4040) var i2 = c1.startIndex expectEqual(i1, i2) expectEqual(1010, c2[i1].value) expectEqual(4040, c1[i2].value) i1 = c1.index(i1, offsetBy: 1) i2 = c1.index(i2, offsetBy: 1) expectEqual(i1, i2) expectEqual(2020, c2[i1].value) expectEqual(2020, c1[i2].value) i1 = c1.index(i1, offsetBy: 1) i2 = c1.index(i2, offsetBy: 1) expectEqual(i1, i2) expectEqual(3030, c2[i1].value) expectEqual(3030, c1[i2].value) } ${Self}TestSuite.test("subscript(_:Index)/Get/DifferentCollections") { let c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) expectCrashLater() c2[c1.startIndex] } ${Self}TestSuite.test("subscript(_:Index)/Set/DifferentCollections") { let c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) var c2 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) expectCrashLater() c2[c1.startIndex] = OpaqueValue(4040) } % end % end %end %for traversal in TRAVERSALS: % Self = 'Minimal' + collectionTypeName(traversal=traversal, mutable=False, rangeReplaceable=True) func getTwoInterchangeable${Self}(_ elements: [Int]) -> (${Self}>, ${Self}>) { var c1 = ${Self}>() c1.append(contentsOf: elements.map(OpaqueValue.init)) var c2 = ${Self}>() c2.append(contentsOf: elements.map(OpaqueValue.init)) return (c1, c2) } var ${Self}TestSuite = TestSuite("${Self}") ${Self}TestSuite.test("startIndex/InterchangeableCollections") { let (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ]) expectEqual(c1.startIndex, c1.startIndex) expectEqual(c2.startIndex, c2.startIndex) expectEqual(c1.startIndex, c2.startIndex) _blackHole(c2) } ${Self}TestSuite.test("startIndex/DifferentCollections") { let c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) expectEqual(c1.startIndex, c1.startIndex) expectEqual(c2.startIndex, c2.startIndex) let i1 = c1.startIndex let i2 = c2.startIndex expectCrashLater() _ = i1 == i2 } ${Self}TestSuite.test("endIndex/InterchangeableCollections") { let (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ]) expectEqual(c1.endIndex, c1.endIndex) expectEqual(c2.endIndex, c2.endIndex) expectEqual(c1.endIndex, c2.endIndex) _blackHole(c2) } ${Self}TestSuite.test("endIndex/DifferentCollections") { let c1 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let c2 = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) expectEqual(c1.endIndex, c1.endIndex) expectEqual(c2.endIndex, c2.endIndex) let i1 = c1.endIndex let i2 = c2.endIndex expectCrashLater() _ = i1 == i2 } ${Self}TestSuite.test("reserveCapacity()/IndexInvalidation/DifferentCollections") { var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ]) let i = c1.startIndex c1.reserveCapacity(0) expectCrashLater() _ = i == c1.startIndex _blackHole(c2) } ${Self}TestSuite.test("reserveCapacity()/IndexInvalidation/DifferentMutationEpoch") { var c = ${Self}(elements: [ 1010, 2020, 3030 ].map(OpaqueValue.init)) let i = c.startIndex c.reserveCapacity(0) expectCrashLater() _ = i == c.startIndex } ${Self}TestSuite.test("append()/IndexInvalidation") { var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ]) let i1 = c1.endIndex c1.append(OpaqueValue(4040)) let i2 = c1.index(c1.startIndex, offsetBy: 3) expectCrashLater() _ = i1 == i2 _blackHole(c2) } ${Self}TestSuite.test("append(contentsOf:)/IndexInvalidation") { var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ]) let i1 = c1.endIndex c1.append(contentsOf: [ 4040, 5050 ].map(OpaqueValue.init)) let i2 = c1.index(c1.startIndex, offsetBy: 3) expectCrashLater() _ = i1 == i2 _blackHole(c2) } ${Self}TestSuite.test("replaceSubrange()/IndexInvalidation") { var (c1, c2) = getTwoInterchangeable${Self}([ 1010, 2020, 3030 ]) let i1 = c1.index(c1.startIndex, offsetBy: 1) c1.replaceSubrange( i1..