Skip to content

Commit 8f632a4

Browse files
authored
Merge pull request #3056 from austinzheng/az-fix-tests
2 parents c404785 + f074bf7 commit 8f632a4

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,13 @@ public struct IndexOffsetByTest {
349349
}
350350

351351
public let distanceFromToTests = [
352+
// 0 - 1: no distance.
352353
DistanceFromToTest(start: 0, end: 0),
353354
DistanceFromToTest(start: 10, end: 10),
355+
// 2 - 3: forward distance.
354356
DistanceFromToTest(start: 10, end: 13),
355357
DistanceFromToTest(start: 7, end: 10),
358+
// 4 - 6: backward distance.
356359
DistanceFromToTest(start: 12, end: 4),
357360
DistanceFromToTest(start: 8, end: 2),
358361
DistanceFromToTest(start: 19, end: 0)
@@ -1594,26 +1597,25 @@ extension TestSuite {
15941597
}
15951598
% end
15961599

1597-
self.test("\(testNamePrefix)/distance(from:to:)/semantics") {
1598-
let c = toCollection(0..<20)
1599-
for test in distanceFromToTests {
1600-
let d = c.distance(
1601-
from: c.nthIndex(test.startOffset), to: c.nthIndex(test.endOffset))
1602-
1603-
let backwards = (test.startOffset < test.endOffset)
1600+
self.test("\(testNamePrefix)/distance(from:to:)/semantics")
1601+
.forEach(in: distanceFromToTests) { (test) in
1602+
let c = toCollection(0..<20)
1603+
let backwards = (test.startOffset > test.endOffset)
16041604
if backwards && !collectionIsBidirectional {
16051605
expectCrashLater()
16061606
}
1607+
1608+
let d = c.distance(
1609+
from: c.nthIndex(test.startOffset), to: c.nthIndex(test.endOffset))
16071610
expectEqual(
16081611
numericCast(test.expectedDistance),
16091612
d, stackTrace: SourceLocStack().with(test.loc))
1610-
}
16111613
}
16121614

1613-
self.test("\(testNamePrefix)/index(_:offsetBy: n)/semantics") {
1614-
for test in indexOffsetByTests.filter(
1615+
self.test("\(testNamePrefix)/index(_:offsetBy: n)/semantics")
1616+
.forEach(in: indexOffsetByTests.filter(
16151617
{$0.limit == nil && $0.distance >= 0}
1616-
) {
1618+
)) { (test) in
16171619
let max = 10
16181620
let c = toCollection(0..<max)
16191621

@@ -1630,13 +1632,12 @@ extension TestSuite {
16301632
// contains exactly index offsets.
16311633
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
16321634
stackTrace: SourceLocStack().with(test.loc))
1633-
}
16341635
}
16351636

1636-
self.test("\(testNamePrefix)/formIndex(_:offsetBy: n)/semantics") {
1637-
for test in indexOffsetByTests.filter(
1637+
self.test("\(testNamePrefix)/formIndex(_:offsetBy: n)/semantics")
1638+
.forEach(in: indexOffsetByTests.filter(
16381639
{$0.limit == nil && $0.distance >= 0}
1639-
) {
1640+
)) { (test) in
16401641
let max = 10
16411642
let c = toCollection(0..<max)
16421643

@@ -1648,14 +1649,13 @@ extension TestSuite {
16481649
c.formIndex(&new, offsetBy: numericCast(test.distance))
16491650
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
16501651
stackTrace: SourceLocStack().with(test.loc))
1651-
}
16521652
}
16531653

16541654
% for function_name in ['index', 'formIndex']:
1655-
self.test("\(testNamePrefix)/${function_name}(_:offsetBy: -n)/semantics") {
1656-
for test in indexOffsetByTests.filter(
1655+
self.test("\(testNamePrefix)/${function_name}(_:offsetBy: -n)/semantics")
1656+
.forEach(in: indexOffsetByTests.filter(
16571657
{$0.limit == nil && $0.distance < 0}
1658-
) {
1658+
)) { (test) in
16591659
let c = toCollection(0..<20)
16601660
% if function_name is 'index':
16611661
let start = c.nthIndex(test.startOffset)
@@ -1673,7 +1673,6 @@ extension TestSuite {
16731673
% end
16741674
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
16751675
stackTrace: SourceLocStack().with(test.loc))
1676-
}
16771676
}
16781677
% end
16791678

@@ -1716,10 +1715,10 @@ extension TestSuite {
17161715
}
17171716
}
17181717

1719-
self.test("\(testNamePrefix)/index(_:offsetBy: -n, limitedBy:)/semantics") {
1720-
for test in indexOffsetByTests.filter(
1718+
self.test("\(testNamePrefix)/index(_:offsetBy: -n, limitedBy:)/semantics")
1719+
.forEach(in: indexOffsetByTests.filter(
17211720
{$0.limit != nil && $0.distance < 0}
1722-
) {
1721+
)) { (test) in
17231722
let c = toCollection(0..<20)
17241723
let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
17251724
if collectionIsBidirectional {
@@ -1740,13 +1739,12 @@ extension TestSuite {
17401739
offsetBy: numericCast(test.distance),
17411740
limitedBy: limit)
17421741
}
1743-
}
17441742
}
17451743

1746-
self.test("\(testNamePrefix)/formIndex(_:offsetBy: -n, limitedBy:)/semantics") {
1747-
for test in indexOffsetByTests.filter(
1748-
{$0.limit != nil && $0.distance < 0}
1749-
) {
1744+
self.test("\(testNamePrefix)/formIndex(_:offsetBy: -n, limitedBy:)/semantics")
1745+
.forEach(in: indexOffsetByTests.filter(
1746+
{$0.limit != nil && $0.distance < 0}
1747+
)) { (test) in
17501748
let c = toCollection(0..<20)
17511749
let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
17521750
var new = c.nthIndex(test.startOffset)
@@ -1767,7 +1765,6 @@ extension TestSuite {
17671765
expectCrashLater()
17681766
_ = c.formIndex(&new, offsetBy: numericCast(test.distance), limitedBy: limit)
17691767
}
1770-
}
17711768
}
17721769

17731770
}

0 commit comments

Comments
 (0)