Skip to content

Commit 38b483d

Browse files
committed
Revert "Move the testsuite off ++/-- completely."
This reverts commit bc65836.
1 parent fc6a406 commit 38b483d

File tree

6 files changed

+43
-53
lines changed

6 files changed

+43
-53
lines changed

test/1_stdlib/Collection.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ func isPalindrome2<
114114
if (b == --e) {
115115
break
116116
}
117-
if seq[b] != seq[e] {
117+
if seq[b++] != seq[e] {
118118
return false
119119
}
120-
b = b.successor()
121120
}
122121
return true
123122
}

test/1_stdlib/ExistentialCollection.swift

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ tests.test("AnyGenerator") {
7070
expectEqual(["0", "1", "2", "3", "4"], Array(countStrings()))
7171

7272
var x = 7
73-
let g = AnyGenerator<Int> {
74-
if x >= 15 { return nil }
75-
x += 1
76-
return x-1
77-
}
73+
let g = AnyGenerator { x < 15 ? x++ : nil }
7874
expectEqual([ 7, 8, 9, 10, 11, 12, 13, 14 ], Array(g))
7975
}
8076

@@ -100,32 +96,32 @@ struct InstrumentedIndex<I : RandomAccessIndexType> : RandomAccessIndexType {
10096
}
10197

10298
func successor() -> InstrumentedIndex {
103-
callCounts["successor"]! += 1
99+
++callCounts["successor"]!
104100
return InstrumentedIndex(base.successor())
105101
}
106102

107103
mutating func _successorInPlace() {
108-
callCounts["_successorInPlace"]! += 1
104+
++callCounts["_successorInPlace"]!
109105
base._successorInPlace()
110106
}
111107

112108
func predecessor() -> InstrumentedIndex {
113-
callCounts["predecessor"]! += 1
109+
++callCounts["predecessor"]!
114110
return InstrumentedIndex(base.predecessor())
115111
}
116112

117113
mutating func _predecessorInPlace() {
118-
callCounts["_predecessorInPlace"]! += 1
114+
++callCounts["_predecessorInPlace"]!
119115
base._predecessorInPlace()
120116
}
121117

122118
func advancedBy(distance: Distance) -> InstrumentedIndex {
123-
callCounts["advancedBy"]! += 1
119+
++callCounts["advancedBy"]!
124120
return InstrumentedIndex(base.advancedBy(distance))
125121
}
126122

127123
func distanceTo(other: InstrumentedIndex) -> Distance {
128-
callCounts["distanceTo"]! += 1
124+
++callCounts["distanceTo"]!
129125
return base.distanceTo(other.base)
130126
}
131127
}
@@ -171,11 +167,10 @@ tests.test("ForwardIndex") {
171167
i = i.successor()
172168
expectEqual(1, callCounts["successor"])
173169
expectEqual(0, callCounts["_successorInPlace"])
174-
i._successorInPlace()
170+
++i
175171
expectEqual(1, callCounts["successor"])
176172
expectEqual(1, callCounts["_successorInPlace"])
177-
var x = i
178-
i = i.successor()
173+
var x = i++
179174
expectEqual(2, callCounts["successor"])
180175
expectEqual(1, callCounts["_successorInPlace"])
181176
_blackHole(x)
@@ -189,11 +184,10 @@ tests.test("BidirectionalIndex") {
189184
i = i.predecessor()
190185
expectEqual(1, callCounts["predecessor"])
191186
expectEqual(0, callCounts["_predecessorInPlace"])
192-
i._predecessorInPlace()
187+
--i
193188
expectEqual(1, callCounts["predecessor"])
194189
expectEqual(1, callCounts["_predecessorInPlace"])
195-
var x = i
196-
i = i.predecessor()
190+
var x = i--
197191
expectEqual(2, callCounts["predecessor"])
198192
expectEqual(1, callCounts["_predecessorInPlace"])
199193
_blackHole(x)

test/1_stdlib/Mirror.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ func find(substring: String, within domain: String) -> String.Index? {
6363
if (domainCount < substringCount) { return nil }
6464
var sliceStart = domain.startIndex
6565
var sliceEnd = domain.startIndex.advancedBy(substringCount)
66-
var i = 0
67-
while true {
66+
for var i = 0;; ++i {
6867
if domain[sliceStart..<sliceEnd] == substring {
6968
return sliceStart
7069
}
7170
if i == domainCount - substringCount { break }
72-
sliceStart = sliceStart.successor()
73-
sliceEnd = sliceEnd.successor()
74-
i += 1
71+
++sliceStart
72+
++sliceEnd
7573
}
7674
return nil
7775
}

test/1_stdlib/StringTraps.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ StringTraps.test("startIndex/predecessor")
2929
.code {
3030
var s = "abc"
3131
var i = s.startIndex
32-
i = i.successor()
33-
i = i.predecessor()
32+
++i
33+
--i
3434
expectCrashLater()
35-
i = i.predecessor()
35+
--i
3636
}
3737

3838
StringTraps.test("endIndex/successor")
@@ -42,11 +42,11 @@ StringTraps.test("endIndex/successor")
4242
.code {
4343
var s = "abc"
4444
var i = s.startIndex
45-
i = i.successor()
46-
i = i.successor()
47-
i = i.successor()
45+
++i
46+
++i
47+
++i
4848
expectCrashLater()
49-
i = i.successor()
49+
++i
5050
}
5151

5252
StringTraps.test("subscript(_:)/endIndex")
@@ -56,9 +56,9 @@ StringTraps.test("subscript(_:)/endIndex")
5656
.code {
5757
var s = "abc"
5858
var i = s.startIndex
59-
i = i.successor()
60-
i = i.successor()
61-
i = i.successor()
59+
++i
60+
++i
61+
++i
6262
expectCrashLater()
6363
s[i]
6464
}
@@ -70,11 +70,11 @@ StringTraps.test("UTF8ViewEndIndexSuccessor")
7070
.code {
7171
var s = "abc"
7272
var i = s.utf8.startIndex
73-
i = i.successor()
74-
i = i.successor()
75-
i = i.successor()
73+
++i
74+
++i
75+
++i
7676
expectCrashLater()
77-
i = i.successor()
77+
++i
7878
}
7979

8080
StringTraps.test("UTF8ViewSubscript/endIndex")
@@ -84,9 +84,9 @@ StringTraps.test("UTF8ViewSubscript/endIndex")
8484
.code {
8585
var s = "abc"
8686
var i = s.utf8.startIndex
87-
i = i.successor()
88-
i = i.successor()
89-
i = i.successor()
87+
++i
88+
++i
89+
++i
9090
expectCrashLater()
9191
s.utf8[i]
9292
}
@@ -98,7 +98,7 @@ StringTraps.test("UTF16ViewSubscript/DecrementedStartIndex")
9898
.code {
9999
var s = "abc"
100100
var i = s.utf16.startIndex
101-
i = i.predecessor()
101+
--i
102102
expectCrashLater()
103103
s.utf16[i]
104104
}
@@ -110,9 +110,9 @@ StringTraps.test("UTF16ViewSubscript/endIndex")
110110
.code {
111111
var s = "abc"
112112
var i = s.utf16.startIndex
113-
i = i.successor()
114-
i = i.successor()
115-
i = i.successor()
113+
++i
114+
++i
115+
++i
116116
expectCrashLater()
117117
s.utf16[i]
118118
}

test/Prototypes/CollectionsMoveIndices.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ extension MyForwardCollectionType {
178178
"Only BidirectionalIndexType can be advanced by a negative amount")
179179

180180
var i = i
181-
for var offset: Index.Distance = 0; offset != n; offset = offset + 1 {
181+
for var offset: Index.Distance = 0; offset != n; ++offset {
182182
_nextInPlace(&i)
183183
}
184184
return i
@@ -194,7 +194,7 @@ extension MyForwardCollectionType {
194194
"Only BidirectionalIndexType can be advanced by a negative amount")
195195

196196
var i = i
197-
for var offset: Index.Distance = 0; offset != n && i != limit; offset = offset + 1 {
197+
for var offset: Index.Distance = 0; offset != n && i != limit; ++offset {
198198
_nextInPlace(&i)
199199
}
200200
return i
@@ -215,7 +215,7 @@ extension MyForwardCollectionType {
215215
var start = start
216216
var count: Index.Distance = 0
217217
while start != end {
218-
count = count + 1
218+
++count
219219
_nextInPlace(&start)
220220
}
221221
return count
@@ -376,7 +376,7 @@ extension MyBidirectionalCollectionType {
376376
return _advanceForward(i, by: n)
377377
}
378378
var i = i
379-
for var offset: Index.Distance = n; offset != 0; offset = offset + 1 {
379+
for var offset: Index.Distance = n; offset != 0; ++offset {
380380
_previousInPlace(&i)
381381
}
382382
return i
@@ -388,8 +388,7 @@ extension MyBidirectionalCollectionType {
388388
return _advanceForward(i, by: n, limit: limit)
389389
}
390390
var i = i
391-
for var offset: Index.Distance = n; offset != 0 && i != limit;
392-
offset = offset + 1 {
391+
for var offset: Index.Distance = n; offset != 0 && i != limit; ++offset {
393392
_previousInPlace(&i)
394393
}
395394
return i

test/decl/ext/protocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ struct MyIndexedGenerator<C : _MyCollection> : GeneratorType {
361361
mutating func next() -> C._Element? {
362362
if index == container.myEndIndex { return nil }
363363
let result = container[index]
364-
index = index.successor()
364+
++index
365365
return result
366366
}
367367
}
@@ -373,7 +373,7 @@ struct OtherIndexedGenerator<C : _MyCollection> : GeneratorType {
373373
mutating func next() -> C._Element? {
374374
if index == container.myEndIndex { return nil }
375375
let result = container[index]
376-
index = index.successor()
376+
++index
377377
return result
378378
}
379379
}

0 commit comments

Comments
 (0)