Skip to content

Commit 82e5c0c

Browse files
committed
Update various tests to stop using ++/--
1 parent 66f7ef1 commit 82e5c0c

25 files changed

+89
-79
lines changed

test/1_stdlib/ArrayBridge.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ class Tracked : NSObject, Fooable {
4747
func foo() { }
4848

4949
required init(_ value: Int) {
50-
++trackedCount
51-
serialNumber = ++nextTrackedSerialNumber
50+
trackedCount += 1
51+
nextTrackedSerialNumber += 1
52+
serialNumber = nextTrackedSerialNumber
5253
self.value = value
5354
}
5455

5556
deinit {
5657
assert(serialNumber > 0, "double destruction!")
57-
--trackedCount
58+
trackedCount -= 1
5859
serialNumber = -serialNumber
5960
}
6061

@@ -102,7 +103,7 @@ struct BridgedSwift : CustomStringConvertible, _ObjectiveCBridgeable {
102103
}
103104

104105
func _bridgeToObjectiveC() -> BridgedObjC {
105-
++bridgeToOperationCount
106+
bridgeToOperationCount += 1
106107
return BridgedObjC(trak.value)
107108
}
108109

@@ -115,7 +116,7 @@ struct BridgedSwift : CustomStringConvertible, _ObjectiveCBridgeable {
115116
inout result: BridgedSwift?
116117
) {
117118
assert(x.value >= 0, "not bridged")
118-
++bridgeFromOperationCount
119+
bridgeFromOperationCount += 1
119120
result = BridgedSwift(x.value)
120121
}
121122

@@ -527,7 +528,7 @@ func testRoundTrip() {
527528
}
528529
}
529530

530-
var test = Test()
531+
let test = Test()
531532

532533
let array = [
533534
BridgedSwift(10), BridgedSwift(20), BridgedSwift(30),
@@ -555,7 +556,7 @@ print(x.objectAtIndex(0) as Base)
555556
*/
556557

557558
func testMutableArray() {
558-
var m = NSMutableArray(array: ["fu", "bar", "buzz"])
559+
let m = NSMutableArray(array: ["fu", "bar", "buzz"])
559560
let a = m as NSArray as! [NSString]
560561
print(a) // CHECK-NEXT: [fu, bar, buzz]
561562
m.addObject("goop")

test/1_stdlib/ArrayCore.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ var nextTrackedSerialNumber = 0
2323

2424
final class Tracked : ForwardIndexType, CustomStringConvertible {
2525
required init(_ value: Int) {
26-
++trackedCount
27-
serialNumber = ++nextTrackedSerialNumber
26+
trackedCount += 1
27+
nextTrackedSerialNumber += 1
28+
serialNumber = nextTrackedSerialNumber
2829
self.value = value
2930
}
3031

3132
deinit {
3233
assert(serialNumber > 0, "double destruction!")
33-
--trackedCount
34+
trackedCount -= 1
3435
serialNumber = -serialNumber
3536
}
3637

test/1_stdlib/BridgeNonVerbatim.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ var nextTrackedSerialNumber = 0
3535

3636
final class Tracked : ForwardIndexType, CustomStringConvertible {
3737
required init(_ value: Int) {
38-
++trackedCount
39-
serialNumber = ++nextTrackedSerialNumber
38+
trackedCount += 1
39+
nextTrackedSerialNumber += 1
40+
serialNumber = nextTrackedSerialNumber
4041
self.value = value
4142
}
4243

4344
deinit {
4445
assert(serialNumber > 0, "double destruction!")
45-
--trackedCount
46+
trackedCount -= 1
4647
serialNumber = -serialNumber
4748
}
4849

@@ -111,12 +112,12 @@ func testScope() {
111112

112113
// We can get a single element out
113114
// CHECK-NEXT: nsx[0]: 1 .
114-
var one = nsx.objectAtIndex(0) as! Tracked
115+
let one = nsx.objectAtIndex(0) as! Tracked
115116
print("nsx[0]: \(one.value) .")
116117

117118
// We can get the element again, but it may not have the same identity
118119
// CHECK-NEXT: object identity matches?
119-
var anotherOne = nsx.objectAtIndex(0) as! Tracked
120+
let anotherOne = nsx.objectAtIndex(0) as! Tracked
120121
print("object identity matches? \(one === anotherOne)")
121122

122123
// Because the elements come back at +0, we really don't want to

test/1_stdlib/Builtins.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ var NoisyDeathCount = 0
119119
protocol P {}
120120

121121
class Noisy : P {
122-
init() { ++NoisyLifeCount }
123-
deinit { ++NoisyDeathCount }
122+
init() { NoisyLifeCount += 1 }
123+
deinit { NoisyDeathCount += 1}
124124
}
125125

126126
struct Large : P {

test/1_stdlib/Collection.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func isPalindrome0<
4545
>(seq: S) -> Bool {
4646
typealias Index = S.Index
4747

48-
var a = seq.indices
48+
let a = seq.indices
4949
var i = seq.indices
5050
var ir = i.lazy.reverse()
5151
var b = ir.generate()
@@ -111,7 +111,8 @@ func isPalindrome2<
111111
var b = seq.startIndex, e = seq.endIndex
112112

113113
while (b != e) {
114-
if (b == --e) {
114+
e = e.predecessor()
115+
if (b == e) {
115116
break
116117
}
117118
if seq[b++] != seq[e] {

test/1_stdlib/ErrorHandling.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import ObjectiveC
1818
var NoisyCount = 0
1919

2020
class Noisy {
21-
init() { NoisyCount++ }
22-
deinit { NoisyCount-- }
21+
init() { NoisyCount += 1 }
22+
deinit { NoisyCount -= 1 }
2323
}
2424
enum SillyError: ErrorType { case JazzHands }
2525

test/1_stdlib/ErrorType.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ protocol OtherClassProtocol : class {
2525
}
2626

2727
class NoisyError : ErrorType, OtherProtocol, OtherClassProtocol {
28-
init() { ++NoisyErrorLifeCount }
29-
deinit { ++NoisyErrorDeathCount }
28+
init() { NoisyErrorLifeCount += 1 }
29+
deinit { NoisyErrorDeathCount += 1 }
3030

3131
let _domain = "NoisyError"
3232
let _code = 123

test/1_stdlib/ErrorTypeBridging.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ protocol OtherClassProtocol : class {
2222
}
2323

2424
class NoisyError : ErrorType, OtherProtocol, OtherClassProtocol {
25-
init() { ++NoisyErrorLifeCount }
26-
deinit { ++NoisyErrorDeathCount }
25+
init() { NoisyErrorLifeCount += 1 }
26+
deinit { NoisyErrorDeathCount += 1 }
2727

2828
let _domain = "NoisyError"
2929
let _code = 123

test/1_stdlib/Experimental.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ ExperimentalTestSuite.test("ComposeOperator/CountCalls") {
4646

4747
var aCalled = 0
4848
var bCalled = 0
49-
func a(_: A) -> B { ++aCalled; return B() }
50-
func b(_: B) -> C { ++bCalled; return C() }
49+
func a(_: A) -> B { aCalled += 1; return B() }
50+
func b(_: B) -> C { bCalled += 1; return C() }
5151

5252
var result = b a
5353
expectEqual(0, aCalled)
@@ -64,8 +64,8 @@ struct C {}
6464

6565
var aCalled = 0
6666
var bCalled = 0
67-
func a(_: A) -> B { ++aCalled; return B() }
68-
func b(_: B) -> C { ++bCalled; return C() }
67+
func a(_: A) -> B { aCalled += 1; return B() }
68+
func b(_: B) -> C { bCalled += 1; return C() }
6969

7070
ExperimentalTestSuite.test("ComposeOperator/CountCalls/Workaround") {
7171
var result = b a

test/1_stdlib/Float.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func checkNormal(normal: TestFloat) {
3737
}
3838

3939
func testNormal() {
40-
var positiveNormal: TestFloat = 42.0
40+
let positiveNormal: TestFloat = 42.0
4141
checkNormal(positiveNormal)
4242
_precondition(!positiveNormal.isSignMinus)
4343
_precondition(positiveNormal.floatingPointClass == .PositiveNormal)
4444

45-
var negativeNormal: TestFloat = -42.0
45+
let negativeNormal: TestFloat = -42.0
4646
checkNormal(negativeNormal)
4747
_precondition(negativeNormal.isSignMinus)
4848
_precondition(negativeNormal.floatingPointClass == .NegativeNormal)
@@ -74,12 +74,12 @@ func checkZero(zero: TestFloat) {
7474
}
7575

7676
func testZero() {
77-
var plusZero = noinlinePlusZero()
77+
let plusZero = noinlinePlusZero()
7878
checkZero(plusZero)
7979
_precondition(!plusZero.isSignMinus)
8080
_precondition(plusZero.floatingPointClass == .PositiveZero)
8181

82-
var minusZero = noinlineMinusZero()
82+
let minusZero = noinlineMinusZero()
8383
checkZero(minusZero)
8484
_precondition(minusZero.isSignMinus)
8585
_precondition(minusZero.floatingPointClass == .NegativeZero)
@@ -129,7 +129,7 @@ func testSubnormal() {
129129
_preconditionFailure("unhandled float kind")
130130
}
131131
var positiveSubnormal: TestFloat = 1.0
132-
for var i = 0; i < iterations; i++ {
132+
for var i = 0; i < iterations; i += 1 {
133133
positiveSubnormal /= 2.0 as TestFloat
134134
}
135135
checkSubnormal(positiveSubnormal)
@@ -138,7 +138,7 @@ func testSubnormal() {
138138
_precondition(positiveSubnormal != 0.0)
139139

140140
var negativeSubnormal: TestFloat = -1.0
141-
for var i = 0; i < iterations; i++ {
141+
for var i = 0; i < iterations; i += 1{
142142
negativeSubnormal /= 2.0 as TestFloat
143143
}
144144
checkSubnormal(negativeSubnormal)

test/1_stdlib/Generator.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,26 @@ tests.test("GeneratorSequence") {
3535
var x = MinimalGenerator(Array(r))
3636
for a in GeneratorSequence(x) {
3737
expectEqual(r.startIndex, a)
38-
++r.startIndex
38+
r.startIndex = r.startIndex.successor()
3939
}
4040
expectEqual(r.startIndex, r.endIndex)
4141
}
4242

4343
struct G : GeneratorType {
4444
var i = 0
4545
mutating func next() -> Int? {
46-
return i < 10 ? i++ : nil
46+
if i >= 10 { return nil }
47+
i += 1
48+
return i-1
4749
}
4850
}
4951

5052
extension G : SequenceType {}
5153
tests.test("GeneratorsModelSequenceTypeByDeclaration") {
5254
var n = 0
5355
for i in G() {
54-
expectEqual(n++, i)
56+
expectEqual(n, i)
57+
n += 1
5558
}
5659
}
5760

test/1_stdlib/Lazy.swift.gyb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ struct SequenceWithCustomUnderestimateCount : SequenceType {
209209
}
210210

211211
func underestimateCount() -> Int {
212-
++SequenceWithCustomUnderestimateCount.timesUnderestimateCountWasCalled
212+
SequenceWithCustomUnderestimateCount.timesUnderestimateCountWasCalled += 1
213213
return _data.underestimateCount()
214214
}
215215

@@ -487,7 +487,7 @@ tests.test("LazyMapSequence") {
487487
var calls = 0
488488
var mapped = base.map {
489489
(x: OpaqueValue<Int>)->OpaqueValue<Double> in
490-
++calls
490+
calls += 1
491491
return OpaqueValue(Double(x.value) / 2.0)
492492
}
493493

@@ -529,7 +529,7 @@ tests.test("LazyMapCollection/${traversal}") {
529529
var calls = 0
530530
var mapped = base.map {
531531
(x: OpaqueValue<Int>)->OpaqueValue<Double> in
532-
++calls
532+
calls += 1
533533
return OpaqueValue(Double(x.value) / 2.0)
534534
}
535535
expectEqual(0, calls)
@@ -595,7 +595,7 @@ tests.test("ReverseCollection") {
595595
// Check that the reverse collection is still eager
596596
do {
597597
var calls = 0
598-
_ = r.reverse().map { _ in ++calls }
598+
_ = r.reverse().map { _ in calls += 1 }
599599
expectEqual(r.count, calls)
600600
}
601601

@@ -606,7 +606,7 @@ tests.test("ReverseCollection") {
606606
// Check that the reverse collection is still eager
607607
do {
608608
var calls = 0
609-
_ = "foobar".characters.reverse().map { _ in ++calls }
609+
_ = "foobar".characters.reverse().map { _ in calls += 1 }
610610
expectEqual("foobar".characters.count, calls)
611611
}
612612
}
@@ -635,7 +635,7 @@ tests.test("ReverseCollection/Lazy") {
635635
ExpectType<LazyReversedBase>.test(reversed)
636636

637637
var calls = 0
638-
let reversedAndMapped = reversed.map { (x)->Int in ++calls; return x }
638+
let reversedAndMapped = reversed.map { (x)->Int in calls += 1; return x }
639639
expectEqual(0, calls)
640640
checkRandomAccessCollection(0...11, reversedAndMapped)
641641
expectNotEqual(0, calls)
@@ -657,7 +657,7 @@ tests.test("ReverseCollection/Lazy") {
657657
ExpectType<LazyReversedBase>.test(reversed)
658658

659659
var calls = 0
660-
let reversedAndMapped = reversed.map { (x)->Character in ++calls; return x }
660+
let reversedAndMapped = reversed.map { (x)->Character in calls += 1; return x }
661661
expectEqual(0, calls)
662662
checkBidirectionalCollection("raboof".characters, reversedAndMapped)
663663
expectNotEqual(0, calls)
@@ -695,7 +695,7 @@ tests.test("LazyFilterSequence") {
695695

696696
var calls = 0
697697
var filtered = MinimalSequence(elements: base).lazy.filter {
698-
x in ++calls;
698+
x in calls += 1;
699699
return x.value % 2 == 0
700700
}
701701
expectEqual(calls, 0, "filtering was eager!")
@@ -721,7 +721,7 @@ tests.test("LazyFilterSequence") {
721721
// Try again using explicit construction
722722
filtered = LazyFilterSequence(
723723
MinimalSequence(elements: base),
724-
whereElementsSatisfy: { x in ++calls; return x.value % 2 == 0})
724+
whereElementsSatisfy: { x in calls += 1; return x.value % 2 == 0})
725725

726726
expectEqual(100, calls)
727727

@@ -759,7 +759,7 @@ tests.test("LazyFilterCollection") {
759759

760760
var calls = 0
761761
let filtered = base.lazy.filter {
762-
x in ++calls;
762+
x in calls += 1;
763763
return x.value % 2 == 0
764764
}
765765
expectEqual(calls, 0, "filtering was eager!")
@@ -821,7 +821,7 @@ do {
821821
elements: data.map { MinimalSequence(elements: $0) })
822822
let flattened = base.flatten()
823823
var calls = 0
824-
_ = flattened.map { _ in ++calls }
824+
_ = flattened.map { _ in calls += 1 }
825825
expectEqual(
826826
expected.count, calls,
827827
"unexpected laziness in \(flattened.dynamicType)")
@@ -835,7 +835,7 @@ do {
835835

836836
let flattened = base.flatten()
837837
var calls = 0
838-
_ = flattened.map { _ in ++calls }
838+
_ = flattened.map { _ in calls += 1 }
839839
expectEqual(0, calls, "unexpected eagerness in \(flattened.dynamicType)")
840840
}
841841

@@ -850,7 +850,7 @@ do {
850850

851851
// Checking that flatten doesn't introduce laziness
852852
var calls = 0
853-
_ = flattened.map { _ in ++calls }
853+
_ = flattened.map { _ in calls += 1 }
854854
expectLE(
855855
expected.count, calls,
856856
"unexpected laziness in \(flattened.dynamicType)")
@@ -865,7 +865,7 @@ do {
865865
let flattened = base.flatten()
866866

867867
var calls = 0
868-
_ = flattened.map { _ in ++calls }
868+
_ = flattened.map { _ in calls += 1 }
869869
expectEqual(0, calls, "unexpected eagerness in \(flattened.dynamicType)")
870870
}
871871
% end

0 commit comments

Comments
 (0)