|
| 1 | +import XCTest |
| 2 | +import JavaScriptBigIntSupport |
| 3 | +import JavaScriptKit |
| 4 | + |
| 5 | +class JavaScriptBigIntSupportTests: XCTestCase { |
| 6 | + func testBigIntSupport() { |
| 7 | + // Test signed values |
| 8 | + func testSignedValue(_ value: Int64, file: StaticString = #filePath, line: UInt = #line) { |
| 9 | + let bigInt = JSBigInt(value) |
| 10 | + XCTAssertEqual(bigInt.description, value.description, file: file, line: line) |
| 11 | + let bigInt2 = JSBigInt(_slowBridge: value) |
| 12 | + XCTAssertEqual(bigInt2.description, value.description, file: file, line: line) |
| 13 | + } |
| 14 | + |
| 15 | + // Test unsigned values |
| 16 | + func testUnsignedValue(_ value: UInt64, file: StaticString = #filePath, line: UInt = #line) { |
| 17 | + let bigInt = JSBigInt(unsigned: value) |
| 18 | + XCTAssertEqual(bigInt.description, value.description, file: file, line: line) |
| 19 | + let bigInt2 = JSBigInt(_slowBridge: value) |
| 20 | + XCTAssertEqual(bigInt2.description, value.description, file: file, line: line) |
| 21 | + } |
| 22 | + |
| 23 | + // Test specific signed values |
| 24 | + testSignedValue(0) |
| 25 | + testSignedValue(1 << 62) |
| 26 | + testSignedValue(-2305) |
| 27 | + |
| 28 | + // Test random signed values |
| 29 | + for _ in 0..<100 { |
| 30 | + testSignedValue(.random(in: .min ... .max)) |
| 31 | + } |
| 32 | + |
| 33 | + // Test edge signed values |
| 34 | + testSignedValue(.min) |
| 35 | + testSignedValue(.max) |
| 36 | + |
| 37 | + // Test specific unsigned values |
| 38 | + testUnsignedValue(0) |
| 39 | + testUnsignedValue(1 << 62) |
| 40 | + testUnsignedValue(1 << 63) |
| 41 | + testUnsignedValue(.min) |
| 42 | + testUnsignedValue(.max) |
| 43 | + testUnsignedValue(~0) |
| 44 | + |
| 45 | + // Test random unsigned values |
| 46 | + for _ in 0..<100 { |
| 47 | + testUnsignedValue(.random(in: .min ... .max)) |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments