@@ -1596,83 +1596,87 @@ extension TestSuite {
1596
1596
}
1597
1597
}
1598
1598
% end
1599
-
1599
+
1600
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)
1604
- if backwards && !collectionIsBidirectional {
1605
- expectCrashLater()
1606
- }
1601
+ .forEach(in: distanceFromToTests) {
1602
+ test in
1603
+ let c = toCollection(0..<20)
1604
+ let backwards = (test.startOffset > test.endOffset)
1605
+ if backwards && !collectionIsBidirectional {
1606
+ expectCrashLater()
1607
+ }
1607
1608
1608
- let d = c.distance(
1609
- from: c.nthIndex(test.startOffset), to: c.nthIndex(test.endOffset))
1610
- expectEqual(
1611
- numericCast(test.expectedDistance),
1612
- d, stackTrace: SourceLocStack().with(test.loc))
1609
+ let d = c.distance(
1610
+ from: c.nthIndex(test.startOffset), to: c.nthIndex(test.endOffset))
1611
+ expectEqual(
1612
+ numericCast(test.expectedDistance),
1613
+ d, stackTrace: SourceLocStack().with(test.loc))
1613
1614
}
1614
1615
1615
1616
self.test("\(testNamePrefix)/index(_:offsetBy: n)/semantics")
1616
- .forEach(in: indexOffsetByTests.filter(
1617
- {$0.limit == nil && $0.distance >= 0}
1618
- )) { (test) in
1619
- let max = 10
1620
- let c = toCollection(0..<max)
1621
-
1622
- if test.expectedOffset! >= max {
1623
- expectCrashLater()
1624
- }
1625
- let new = c.index(
1626
- c.nthIndex(test.startOffset),
1627
- offsetBy: numericCast(test.distance))
1628
-
1629
- // Since the `nthIndex(offset:)` method performs the same operation
1630
- // (i.e. advances `c.startIndex` by `test.distance`, it would be
1631
- // silly to compare index values. Luckily the underlying collection
1632
- // contains exactly index offsets.
1633
- expectEqual(test.expectedOffset!, extractValue(c[new]).value,
1634
- stackTrace: SourceLocStack().with(test.loc))
1617
+ .forEach(
1618
+ in: indexOffsetByTests.filter { $0.limit == nil && $0.distance >= 0 }
1619
+ ) {
1620
+ test in
1621
+ let max = 10
1622
+ let c = toCollection(0..<max)
1623
+
1624
+ if test.expectedOffset! >= max {
1625
+ expectCrashLater()
1626
+ }
1627
+ let new = c.index(
1628
+ c.nthIndex(test.startOffset),
1629
+ offsetBy: numericCast(test.distance))
1630
+
1631
+ // Since the `nthIndex(offset:)` method performs the same operation
1632
+ // (i.e. advances `c.startIndex` by `test.distance`, it would be
1633
+ // silly to compare index values. Luckily the underlying collection
1634
+ // contains exactly index offsets.
1635
+ expectEqual(test.expectedOffset!, extractValue(c[new]).value,
1636
+ stackTrace: SourceLocStack().with(test.loc))
1635
1637
}
1636
1638
1637
1639
self.test("\(testNamePrefix)/formIndex(_:offsetBy: n)/semantics")
1638
- .forEach(in: indexOffsetByTests.filter(
1639
- {$0.limit == nil && $0.distance >= 0}
1640
- )) { (test) in
1641
- let max = 10
1642
- let c = toCollection(0..<max)
1640
+ .forEach(
1641
+ in: indexOffsetByTests.filter { $0.limit == nil && $0.distance >= 0 }
1642
+ ) {
1643
+ test in
1644
+ let max = 10
1645
+ let c = toCollection(0..<max)
1643
1646
1644
- var new = c.nthIndex(test.startOffset)
1647
+ var new = c.nthIndex(test.startOffset)
1645
1648
1646
- if test.expectedOffset! >= max {
1647
- expectCrashLater()
1648
- }
1649
- c.formIndex(&new, offsetBy: numericCast(test.distance))
1650
- expectEqual(test.expectedOffset!, extractValue(c[new]).value,
1651
- stackTrace: SourceLocStack().with(test.loc))
1649
+ if test.expectedOffset! >= max {
1650
+ expectCrashLater()
1651
+ }
1652
+ c.formIndex(&new, offsetBy: numericCast(test.distance))
1653
+ expectEqual(test.expectedOffset!, extractValue(c[new]).value,
1654
+ stackTrace: SourceLocStack().with(test.loc))
1652
1655
}
1653
1656
1654
1657
% for function_name in ['index', 'formIndex']:
1655
1658
self.test("\(testNamePrefix)/${function_name}(_:offsetBy: -n)/semantics")
1656
- .forEach(in: indexOffsetByTests.filter(
1657
- {$0.limit == nil && $0.distance < 0}
1658
- )) { (test) in
1659
- let c = toCollection(0..<20)
1659
+ .forEach(
1660
+ in: indexOffsetByTests.filter { $0.limit == nil && $0.distance < 0 }
1661
+ ) {
1662
+ test in
1663
+ let c = toCollection(0..<20)
1660
1664
% if function_name is 'index':
1661
- let start = c.nthIndex(test.startOffset)
1665
+ let start = c.nthIndex(test.startOffset)
1662
1666
% else:
1663
- var new = c.nthIndex(test.startOffset)
1667
+ var new = c.nthIndex(test.startOffset)
1664
1668
% end
1665
1669
1666
- if test.expectedOffset! < 0 || !collectionIsBidirectional {
1667
- expectCrashLater()
1668
- }
1670
+ if test.expectedOffset! < 0 || !collectionIsBidirectional {
1671
+ expectCrashLater()
1672
+ }
1669
1673
% if function_name is 'index':
1670
- let new = c.index(start, offsetBy: numericCast(test.distance))
1674
+ let new = c.index(start, offsetBy: numericCast(test.distance))
1671
1675
% else:
1672
- c.formIndex(&new, offsetBy: numericCast(test.distance))
1676
+ c.formIndex(&new, offsetBy: numericCast(test.distance))
1673
1677
% end
1674
- expectEqual(test.expectedOffset!, extractValue(c[new]).value,
1675
- stackTrace: SourceLocStack().with(test.loc))
1678
+ expectEqual(test.expectedOffset!, extractValue(c[new]).value,
1679
+ stackTrace: SourceLocStack().with(test.loc))
1676
1680
}
1677
1681
% end
1678
1682
@@ -1716,55 +1720,57 @@ extension TestSuite {
1716
1720
}
1717
1721
1718
1722
self.test("\(testNamePrefix)/index(_:offsetBy: -n, limitedBy:)/semantics")
1719
- .forEach(in: indexOffsetByTests.filter(
1720
- {$0.limit != nil && $0.distance < 0}
1721
- )) { (test) in
1722
- let c = toCollection(0..<20)
1723
- let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
1724
- if collectionIsBidirectional {
1725
- let new = c.index(
1726
- c.nthIndex(test.startOffset),
1727
- offsetBy: numericCast(test.distance),
1728
- limitedBy: limit)
1729
- if let expectedOffset = test.expectedOffset {
1730
- expectEqual(c.nthIndex(expectedOffset), new!,
1731
- stackTrace: SourceLocStack().with(test.loc))
1732
- } else {
1733
- expectEmpty(new)
1734
- }
1723
+ .forEach(
1724
+ in: indexOffsetByTests.filter { $0.limit != nil && $0.distance < 0 }
1725
+ ) {
1726
+ test in
1727
+ let c = toCollection(0..<20)
1728
+ let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
1729
+ if collectionIsBidirectional {
1730
+ let new = c.index(
1731
+ c.nthIndex(test.startOffset),
1732
+ offsetBy: numericCast(test.distance),
1733
+ limitedBy: limit)
1734
+ if let expectedOffset = test.expectedOffset {
1735
+ expectEqual(c.nthIndex(expectedOffset), new!,
1736
+ stackTrace: SourceLocStack().with(test.loc))
1735
1737
} else {
1736
- expectCrashLater()
1737
- _ = c.index(
1738
- c.nthIndex(test.startOffset),
1739
- offsetBy: numericCast(test.distance),
1740
- limitedBy: limit)
1738
+ expectEmpty(new)
1741
1739
}
1740
+ } else {
1741
+ expectCrashLater()
1742
+ _ = c.index(
1743
+ c.nthIndex(test.startOffset),
1744
+ offsetBy: numericCast(test.distance),
1745
+ limitedBy: limit)
1746
+ }
1742
1747
}
1743
1748
1744
1749
self.test("\(testNamePrefix)/formIndex(_:offsetBy: -n, limitedBy:)/semantics")
1745
- .forEach(in: indexOffsetByTests.filter(
1746
- {$0.limit != nil && $0.distance < 0}
1747
- )) { (test) in
1748
- let c = toCollection(0..<20)
1749
- let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
1750
- var new = c.nthIndex(test.startOffset)
1751
- if collectionIsBidirectional {
1752
- let exact = c.formIndex(
1753
- &new,
1754
- offsetBy: numericCast(test.distance),
1755
- limitedBy: limit)
1756
- if let expectedOffset = test.expectedOffset {
1757
- expectEqual(c.nthIndex(expectedOffset), new,
1758
- stackTrace: SourceLocStack().with(test.loc))
1759
- expectTrue(exact, stackTrace: SourceLocStack().with(test.loc))
1760
- } else {
1761
- expectEqual(limit, new, stackTrace: SourceLocStack().with(test.loc))
1762
- expectFalse(exact, stackTrace: SourceLocStack().with(test.loc))
1763
- }
1750
+ .forEach(
1751
+ in: indexOffsetByTests.filter { $0.limit != nil && $0.distance < 0 }
1752
+ ) {
1753
+ test in
1754
+ let c = toCollection(0..<20)
1755
+ let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
1756
+ var new = c.nthIndex(test.startOffset)
1757
+ if collectionIsBidirectional {
1758
+ let exact = c.formIndex(
1759
+ &new,
1760
+ offsetBy: numericCast(test.distance),
1761
+ limitedBy: limit)
1762
+ if let expectedOffset = test.expectedOffset {
1763
+ expectEqual(c.nthIndex(expectedOffset), new,
1764
+ stackTrace: SourceLocStack().with(test.loc))
1765
+ expectTrue(exact, stackTrace: SourceLocStack().with(test.loc))
1764
1766
} else {
1765
- expectCrashLater( )
1766
- _ = c.formIndex(&new, offsetBy: numericCast( test.distance), limitedBy: limit )
1767
+ expectEqual(limit, new, stackTrace: SourceLocStack().with(test.loc) )
1768
+ expectFalse(exact, stackTrace: SourceLocStack().with( test.loc) )
1767
1769
}
1770
+ } else {
1771
+ expectCrashLater()
1772
+ _ = c.formIndex(&new, offsetBy: numericCast(test.distance), limitedBy: limit)
1773
+ }
1768
1774
}
1769
1775
1770
1776
}
0 commit comments