Skip to content

Commit 4b06bb1

Browse files
committed
Merge pull request #2269 from JaviSoto/SR-1238-UnsafePointer-Comparable-tests
[test] SR-1238: Add test for UnsafePointer and UnsafeMutablePointer conformance to Comparable
2 parents 014bfa1 + c27f3d8 commit 4b06bb1

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

test/1_stdlib/UnsafePointer.swift.gyb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,35 @@ UnsafeMutablePointerTestSuite.test("customPlaygroundQuickLook") {
387387
}
388388
}
389389

390-
runAllTests()
390+
% for (SelfName, SelfType) in [
391+
% ('UnsafePointer', 'UnsafePointer<Int>'),
392+
% ('UnsafeMutablePointer', 'UnsafeMutablePointer<Int>')]:
393+
394+
${SelfName}TestSuite.test("Comparable") {
395+
var addresses: [UInt] = [
396+
0x00000001,
397+
0xFF00FF00,
398+
0x00001111,
399+
0x00000002,
400+
0xFFFFFFFF,
401+
0x00001111
402+
]
403+
404+
#if arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le)
405+
addresses += [
406+
0xFFFFFFFF80000000,
407+
0x8000000000000000
408+
]
409+
#endif
410+
411+
let instances = addresses.map { ($0, ${SelfType}(bitPattern: $0)!) }
391412

413+
func comparisonOracle(i: Int, j: Int) -> ExpectedComparisonResult {
414+
return instances[i].0 <=> instances[j].0
415+
}
416+
checkComparable(instances.map { $0.1 }, oracle: comparisonOracle)
417+
}
418+
419+
% end
420+
421+
runAllTests()

0 commit comments

Comments
 (0)