mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Use string description in test sequence comparison
Using ObjectIdentifiers on the 32-bit simulator isn't a reliable comparison method. For the purposes of these tests, it's better to do a string comparison of the description instead. rdar://problem/19013004 Swift SVN r23415
This commit is contained in:
@@ -1396,23 +1396,22 @@ public func expectEqualSequence<
|
||||
public func expectEqualsUnordered<
|
||||
Expected : SequenceType,
|
||||
Actual : SequenceType
|
||||
where Expected.Generator.Element == Actual.Generator.Element,
|
||||
Expected.Generator.Element == AnyObject
|
||||
where Expected.Generator.Element == Actual.Generator.Element
|
||||
>(
|
||||
expected: Expected, actual: Actual,
|
||||
sameValue: (Expected.Generator.Element, Expected.Generator.Element)->Bool,
|
||||
compare: (Expected.Generator.Element, Expected.Generator.Element)
|
||||
-> ExpectedComparisonResult,
|
||||
stackTrace: SourceLocStack? = nil,
|
||||
collectMoreInfo: (()->String)? = nil,
|
||||
file: String = __FILE__, line: UWord = __LINE__
|
||||
) {
|
||||
let f = { (x, y) -> Bool in
|
||||
ObjectIdentifier(x) < ObjectIdentifier(y)
|
||||
}
|
||||
let x: [Expected.Generator.Element] = sorted(Array(expected), f)
|
||||
let y: [Actual.Generator.Element] = sorted(Array(actual), f)
|
||||
let x: [Expected.Generator.Element] = sorted(
|
||||
Array(expected), compose(compare, { $0.isLT() }))
|
||||
let y: [Actual.Generator.Element] = sorted(
|
||||
Array(actual), compose(compare, { $0.isLT() }))
|
||||
expectEqualSequence(
|
||||
x, y, sameValue, stackTrace: stackTrace, collectMoreInfo: collectMoreInfo,
|
||||
file: file, line: line)
|
||||
x, y, compose(compare, { $0.isEQ() }), stackTrace: stackTrace,
|
||||
collectMoreInfo: collectMoreInfo, file: file, line: line)
|
||||
}
|
||||
|
||||
public func expectEqualUnicodeScalars(
|
||||
@@ -1476,6 +1475,12 @@ public func expectDebugPrinted<T>(
|
||||
expectDebugPrinted(expectedOneOf: [expected], object, file: file, line: line)
|
||||
}
|
||||
|
||||
func compose<A, B, C>(f: A -> B, g: B -> C) -> A -> C {
|
||||
return { a in
|
||||
return g(f(a))
|
||||
}
|
||||
}
|
||||
|
||||
// ${'Local Variables'}:
|
||||
// eval: (read-only-mode 1)
|
||||
// End:
|
||||
|
||||
@@ -12,8 +12,13 @@ NSSetAPI.test("SequenceType") {
|
||||
|
||||
NSSetAPI.test("initWithObjects") {
|
||||
let result = NSSet(objects: 1, "two")
|
||||
// using the descriptions of 1 and "two" are fine for this test.
|
||||
expectEqualsUnordered([1, "two"], result) {
|
||||
($0 as NSObject) == ($1 as NSObject)
|
||||
switch ($0.description < $1.description, $0.description == $1.description) {
|
||||
case (true, _): return .LT
|
||||
case (_, true): return .EQ
|
||||
case _: return .GT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user