Skip to content

Commit

Permalink
Update various tests to stop using ++/--
Browse files Browse the repository at this point in the history
  • Loading branch information
lattner committed Dec 22, 2015
1 parent 66f7ef1 commit 82e5c0c
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 79 deletions.
15 changes: 8 additions & 7 deletions test/1_stdlib/ArrayBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ class Tracked : NSObject, Fooable {
func foo() { }

required init(_ value: Int) {
++trackedCount
serialNumber = ++nextTrackedSerialNumber
trackedCount += 1
nextTrackedSerialNumber += 1
serialNumber = nextTrackedSerialNumber
self.value = value
}

deinit {
assert(serialNumber > 0, "double destruction!")
--trackedCount
trackedCount -= 1
serialNumber = -serialNumber
}

Expand Down Expand Up @@ -102,7 +103,7 @@ struct BridgedSwift : CustomStringConvertible, _ObjectiveCBridgeable {
}

func _bridgeToObjectiveC() -> BridgedObjC {
++bridgeToOperationCount
bridgeToOperationCount += 1
return BridgedObjC(trak.value)
}

Expand All @@ -115,7 +116,7 @@ struct BridgedSwift : CustomStringConvertible, _ObjectiveCBridgeable {
inout result: BridgedSwift?
) {
assert(x.value >= 0, "not bridged")
++bridgeFromOperationCount
bridgeFromOperationCount += 1
result = BridgedSwift(x.value)
}

Expand Down Expand Up @@ -527,7 +528,7 @@ func testRoundTrip() {
}
}

var test = Test()
let test = Test()

let array = [
BridgedSwift(10), BridgedSwift(20), BridgedSwift(30),
Expand Down Expand Up @@ -555,7 +556,7 @@ print(x.objectAtIndex(0) as Base)
*/

func testMutableArray() {
var m = NSMutableArray(array: ["fu", "bar", "buzz"])
let m = NSMutableArray(array: ["fu", "bar", "buzz"])
let a = m as NSArray as! [NSString]
print(a) // CHECK-NEXT: [fu, bar, buzz]
m.addObject("goop")
Expand Down
7 changes: 4 additions & 3 deletions test/1_stdlib/ArrayCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ var nextTrackedSerialNumber = 0

final class Tracked : ForwardIndexType, CustomStringConvertible {
required init(_ value: Int) {
++trackedCount
serialNumber = ++nextTrackedSerialNumber
trackedCount += 1
nextTrackedSerialNumber += 1
serialNumber = nextTrackedSerialNumber
self.value = value
}

deinit {
assert(serialNumber > 0, "double destruction!")
--trackedCount
trackedCount -= 1
serialNumber = -serialNumber
}

Expand Down
11 changes: 6 additions & 5 deletions test/1_stdlib/BridgeNonVerbatim.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ var nextTrackedSerialNumber = 0

final class Tracked : ForwardIndexType, CustomStringConvertible {
required init(_ value: Int) {
++trackedCount
serialNumber = ++nextTrackedSerialNumber
trackedCount += 1
nextTrackedSerialNumber += 1
serialNumber = nextTrackedSerialNumber
self.value = value
}

deinit {
assert(serialNumber > 0, "double destruction!")
--trackedCount
trackedCount -= 1
serialNumber = -serialNumber
}

Expand Down Expand Up @@ -111,12 +112,12 @@ func testScope() {

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

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

// Because the elements come back at +0, we really don't want to
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/Builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ var NoisyDeathCount = 0
protocol P {}

class Noisy : P {
init() { ++NoisyLifeCount }
deinit { ++NoisyDeathCount }
init() { NoisyLifeCount += 1 }
deinit { NoisyDeathCount += 1}
}

struct Large : P {
Expand Down
5 changes: 3 additions & 2 deletions test/1_stdlib/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func isPalindrome0<
>(seq: S) -> Bool {
typealias Index = S.Index

var a = seq.indices
let a = seq.indices
var i = seq.indices
var ir = i.lazy.reverse()
var b = ir.generate()
Expand Down Expand Up @@ -111,7 +111,8 @@ func isPalindrome2<
var b = seq.startIndex, e = seq.endIndex

while (b != e) {
if (b == --e) {
e = e.predecessor()
if (b == e) {
break
}
if seq[b++] != seq[e] {
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/ErrorHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import ObjectiveC
var NoisyCount = 0

class Noisy {
init() { NoisyCount++ }
deinit { NoisyCount-- }
init() { NoisyCount += 1 }
deinit { NoisyCount -= 1 }
}
enum SillyError: ErrorType { case JazzHands }

Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/ErrorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ protocol OtherClassProtocol : class {
}

class NoisyError : ErrorType, OtherProtocol, OtherClassProtocol {
init() { ++NoisyErrorLifeCount }
deinit { ++NoisyErrorDeathCount }
init() { NoisyErrorLifeCount += 1 }
deinit { NoisyErrorDeathCount += 1 }

let _domain = "NoisyError"
let _code = 123
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/ErrorTypeBridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ protocol OtherClassProtocol : class {
}

class NoisyError : ErrorType, OtherProtocol, OtherClassProtocol {
init() { ++NoisyErrorLifeCount }
deinit { ++NoisyErrorDeathCount }
init() { NoisyErrorLifeCount += 1 }
deinit { NoisyErrorDeathCount += 1 }

let _domain = "NoisyError"
let _code = 123
Expand Down
8 changes: 4 additions & 4 deletions test/1_stdlib/Experimental.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ ExperimentalTestSuite.test("ComposeOperator/CountCalls") {

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

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

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

ExperimentalTestSuite.test("ComposeOperator/CountCalls/Workaround") {
var result = b a
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/Float.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func checkNormal(normal: TestFloat) {
}

func testNormal() {
var positiveNormal: TestFloat = 42.0
let positiveNormal: TestFloat = 42.0
checkNormal(positiveNormal)
_precondition(!positiveNormal.isSignMinus)
_precondition(positiveNormal.floatingPointClass == .PositiveNormal)

var negativeNormal: TestFloat = -42.0
let negativeNormal: TestFloat = -42.0
checkNormal(negativeNormal)
_precondition(negativeNormal.isSignMinus)
_precondition(negativeNormal.floatingPointClass == .NegativeNormal)
Expand Down Expand Up @@ -74,12 +74,12 @@ func checkZero(zero: TestFloat) {
}

func testZero() {
var plusZero = noinlinePlusZero()
let plusZero = noinlinePlusZero()
checkZero(plusZero)
_precondition(!plusZero.isSignMinus)
_precondition(plusZero.floatingPointClass == .PositiveZero)

var minusZero = noinlineMinusZero()
let minusZero = noinlineMinusZero()
checkZero(minusZero)
_precondition(minusZero.isSignMinus)
_precondition(minusZero.floatingPointClass == .NegativeZero)
Expand Down Expand Up @@ -129,7 +129,7 @@ func testSubnormal() {
_preconditionFailure("unhandled float kind")
}
var positiveSubnormal: TestFloat = 1.0
for var i = 0; i < iterations; i++ {
for var i = 0; i < iterations; i += 1 {
positiveSubnormal /= 2.0 as TestFloat
}
checkSubnormal(positiveSubnormal)
Expand All @@ -138,7 +138,7 @@ func testSubnormal() {
_precondition(positiveSubnormal != 0.0)

var negativeSubnormal: TestFloat = -1.0
for var i = 0; i < iterations; i++ {
for var i = 0; i < iterations; i += 1{
negativeSubnormal /= 2.0 as TestFloat
}
checkSubnormal(negativeSubnormal)
Expand Down
9 changes: 6 additions & 3 deletions test/1_stdlib/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ tests.test("GeneratorSequence") {
var x = MinimalGenerator(Array(r))
for a in GeneratorSequence(x) {
expectEqual(r.startIndex, a)
++r.startIndex
r.startIndex = r.startIndex.successor()
}
expectEqual(r.startIndex, r.endIndex)
}

struct G : GeneratorType {
var i = 0
mutating func next() -> Int? {
return i < 10 ? i++ : nil
if i >= 10 { return nil }
i += 1
return i-1
}
}

extension G : SequenceType {}
tests.test("GeneratorsModelSequenceTypeByDeclaration") {
var n = 0
for i in G() {
expectEqual(n++, i)
expectEqual(n, i)
n += 1
}
}

Expand Down
28 changes: 14 additions & 14 deletions test/1_stdlib/Lazy.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct SequenceWithCustomUnderestimateCount : SequenceType {
}

func underestimateCount() -> Int {
++SequenceWithCustomUnderestimateCount.timesUnderestimateCountWasCalled
SequenceWithCustomUnderestimateCount.timesUnderestimateCountWasCalled += 1
return _data.underestimateCount()
}

Expand Down Expand Up @@ -487,7 +487,7 @@ tests.test("LazyMapSequence") {
var calls = 0
var mapped = base.map {
(x: OpaqueValue<Int>)->OpaqueValue<Double> in
++calls
calls += 1
return OpaqueValue(Double(x.value) / 2.0)
}

Expand Down Expand Up @@ -529,7 +529,7 @@ tests.test("LazyMapCollection/${traversal}") {
var calls = 0
var mapped = base.map {
(x: OpaqueValue<Int>)->OpaqueValue<Double> in
++calls
calls += 1
return OpaqueValue(Double(x.value) / 2.0)
}
expectEqual(0, calls)
Expand Down Expand Up @@ -595,7 +595,7 @@ tests.test("ReverseCollection") {
// Check that the reverse collection is still eager
do {
var calls = 0
_ = r.reverse().map { _ in ++calls }
_ = r.reverse().map { _ in calls += 1 }
expectEqual(r.count, calls)
}

Expand All @@ -606,7 +606,7 @@ tests.test("ReverseCollection") {
// Check that the reverse collection is still eager
do {
var calls = 0
_ = "foobar".characters.reverse().map { _ in ++calls }
_ = "foobar".characters.reverse().map { _ in calls += 1 }
expectEqual("foobar".characters.count, calls)
}
}
Expand Down Expand Up @@ -635,7 +635,7 @@ tests.test("ReverseCollection/Lazy") {
ExpectType<LazyReversedBase>.test(reversed)

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

var calls = 0
let reversedAndMapped = reversed.map { (x)->Character in ++calls; return x }
let reversedAndMapped = reversed.map { (x)->Character in calls += 1; return x }
expectEqual(0, calls)
checkBidirectionalCollection("raboof".characters, reversedAndMapped)
expectNotEqual(0, calls)
Expand Down Expand Up @@ -695,7 +695,7 @@ tests.test("LazyFilterSequence") {

var calls = 0
var filtered = MinimalSequence(elements: base).lazy.filter {
x in ++calls;
x in calls += 1;
return x.value % 2 == 0
}
expectEqual(calls, 0, "filtering was eager!")
Expand All @@ -721,7 +721,7 @@ tests.test("LazyFilterSequence") {
// Try again using explicit construction
filtered = LazyFilterSequence(
MinimalSequence(elements: base),
whereElementsSatisfy: { x in ++calls; return x.value % 2 == 0})
whereElementsSatisfy: { x in calls += 1; return x.value % 2 == 0})

expectEqual(100, calls)

Expand Down Expand Up @@ -759,7 +759,7 @@ tests.test("LazyFilterCollection") {

var calls = 0
let filtered = base.lazy.filter {
x in ++calls;
x in calls += 1;
return x.value % 2 == 0
}
expectEqual(calls, 0, "filtering was eager!")
Expand Down Expand Up @@ -821,7 +821,7 @@ do {
elements: data.map { MinimalSequence(elements: $0) })
let flattened = base.flatten()
var calls = 0
_ = flattened.map { _ in ++calls }
_ = flattened.map { _ in calls += 1 }
expectEqual(
expected.count, calls,
"unexpected laziness in \(flattened.dynamicType)")
Expand All @@ -835,7 +835,7 @@ do {

let flattened = base.flatten()
var calls = 0
_ = flattened.map { _ in ++calls }
_ = flattened.map { _ in calls += 1 }
expectEqual(0, calls, "unexpected eagerness in \(flattened.dynamicType)")
}

Expand All @@ -850,7 +850,7 @@ do {

// Checking that flatten doesn't introduce laziness
var calls = 0
_ = flattened.map { _ in ++calls }
_ = flattened.map { _ in calls += 1 }
expectLE(
expected.count, calls,
"unexpected laziness in \(flattened.dynamicType)")
Expand All @@ -865,7 +865,7 @@ do {
let flattened = base.flatten()

var calls = 0
_ = flattened.map { _ in ++calls }
_ = flattened.map { _ in calls += 1 }
expectEqual(0, calls, "unexpected eagerness in \(flattened.dynamicType)")
}
% end
Expand Down
Loading

0 comments on commit 82e5c0c

Please sign in to comment.