Skip to content

Commit bf8133b

Browse files
committed
Fix NSNumber bridging test for large integers
1 parent 316f120 commit bf8133b

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

TestFoundation/TestNSNumberBridging.swift

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,16 @@ class TestNSNumberBridging : XCTestCase {
242242
XCTAssertEqual(Int(exactly: interestingValue), int)
243243
let uint = UInt(exactly: number!)
244244
XCTAssertEqual(UInt(exactly: interestingValue), uint)
245+
245246
let float = Float(exactly: number!)
246247
let expectedFloat = Float(exactly: int32!)
247-
// these are disabled because of https://bugs.swift.org/browse/SR-4634
248-
if (int32! != Int32.min && int32! != Int32.max &&
249-
int32! != Int32.min + 1 && int32! != Int32.max - 1) {
248+
if int32! > Int32.min + 1 && int32! < Int32.max - 1 {
250249
testFloat(expectedFloat, float)
250+
} else {
251+
XCTAssertNil(float)
252+
XCTAssertNil(expectedFloat)
251253
}
254+
252255
let double = Double(exactly: number!)
253256
let expectedDouble = Double(exactly: int32!)
254257
testDouble(expectedDouble, double)
@@ -284,12 +287,16 @@ class TestNSNumberBridging : XCTestCase {
284287
XCTAssertEqual(Int(exactly: interestingValue), int)
285288
let uint = UInt(exactly: number!)
286289
XCTAssertEqual(UInt(exactly: interestingValue), uint)
290+
287291
let float = Float(exactly: number!)
288292
let expectedFloat = Float(exactly: uint32!)
289-
// these are disabled because of https://bugs.swift.org/browse/SR-4634
290-
if (uint32! != UInt32.max && uint32! != UInt32.max - 1) {
293+
if uint32! < UInt32.max - 1 {
291294
testFloat(expectedFloat, float)
295+
} else {
296+
XCTAssertNil(float)
297+
XCTAssertNil(expectedFloat)
292298
}
299+
293300
let double = Double(exactly: number!)
294301
let expectedDouble = Double(exactly: uint32!)
295302
testDouble(expectedDouble, double)
@@ -325,10 +332,16 @@ class TestNSNumberBridging : XCTestCase {
325332
XCTAssertEqual(Int(exactly: interestingValue), int)
326333
let uint = UInt(exactly: number!)
327334
XCTAssertEqual(UInt(exactly: interestingValue), uint)
335+
328336
let float = Float(exactly: number!)
329-
XCTAssertEqual(Float(interestingValue), float)
330337
let double = Double(exactly: number!)
331-
XCTAssertEqual(Double(interestingValue), double)
338+
if int64! > Int64.min + 1 && int64! < Int64.max - 1 {
339+
XCTAssertEqual(Float(interestingValue), float)
340+
XCTAssertEqual(Double(interestingValue), double)
341+
} else {
342+
XCTAssertNil(float)
343+
XCTAssertNil(double)
344+
}
332345
}
333346
let bridged = interestingValue._bridgeToObjectiveC()
334347
testNumber(bridged)
@@ -361,10 +374,16 @@ class TestNSNumberBridging : XCTestCase {
361374
XCTAssertEqual(Int(exactly: interestingValue), int)
362375
let uint = UInt(exactly: number!)
363376
XCTAssertEqual(UInt(exactly: interestingValue), uint)
377+
364378
let float = Float(exactly: number!)
365-
XCTAssertEqual(Float(interestingValue), float)
366379
let double = Double(exactly: number!)
367-
XCTAssertEqual(Double(interestingValue), double)
380+
if uint64! < UInt64.max - 1 {
381+
XCTAssertEqual(Float(interestingValue), float)
382+
XCTAssertEqual(Double(interestingValue), double)
383+
} else {
384+
XCTAssertNil(float)
385+
XCTAssertNil(double)
386+
}
368387
}
369388
let bridged = interestingValue._bridgeToObjectiveC()
370389
testNumber(bridged)
@@ -397,10 +416,16 @@ class TestNSNumberBridging : XCTestCase {
397416
XCTAssertEqual(Int(exactly: interestingValue), int)
398417
let uint = UInt(exactly: number!)
399418
XCTAssertEqual(UInt(exactly: interestingValue), uint)
419+
400420
let float = Float(exactly: number!)
401-
XCTAssertEqual(Float(interestingValue), float)
402421
let double = Double(exactly: number!)
403-
XCTAssertEqual(Double(interestingValue), double)
422+
if int! > Int.min + 1 && int! < Int.max - 1 {
423+
XCTAssertEqual(Float(interestingValue), float)
424+
XCTAssertEqual(Double(interestingValue), double)
425+
} else {
426+
XCTAssertNil(float)
427+
XCTAssertNil(double)
428+
}
404429
}
405430
let bridged = interestingValue._bridgeToObjectiveC()
406431
testNumber(bridged)
@@ -433,10 +458,16 @@ class TestNSNumberBridging : XCTestCase {
433458
XCTAssertEqual(Int(exactly: interestingValue), int)
434459
let uint = UInt(exactly: number!)
435460
XCTAssertEqual(UInt(exactly: interestingValue), uint)
461+
436462
let float = Float(exactly: number!)
437-
XCTAssertEqual(Float(interestingValue), float)
438463
let double = Double(exactly: number!)
439-
XCTAssertEqual(Double(interestingValue), double)
464+
if uint! < UInt.max - 1 {
465+
XCTAssertEqual(Float(interestingValue), float)
466+
XCTAssertEqual(Double(interestingValue), double)
467+
} else {
468+
XCTAssertNil(float)
469+
XCTAssertNil(double)
470+
}
440471
}
441472
let bridged = interestingValue._bridgeToObjectiveC()
442473
testNumber(bridged)

0 commit comments

Comments
 (0)