Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/core/src/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ class Integer {
}
}

/**
* Converts the Integer to it primitive value.
*
* @since 5.4.0
* @returns {bigint}
*
* @see {@link Integer#toBigInt}
* @see {@link Integer#toInt}
* @see {@link Integer#toNumber}
* @see {@link Integer#toString}
*/
valueOf (): bigint {
return this.toBigInt()
}

/**
* Gets the high 32 bits as a signed integer.
* @returns {number} Signed high bits
Expand Down
28 changes: 28 additions & 0 deletions packages/core/test/integer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,34 @@ describe('Integer', () => {
fc.assert(fc.property(fc.integer(), i => i.toString() === int(i).toString()))
})

test('Integer.valueOf should be equivalent to the Integer.toBigInt', () => {
fc.assert(
fc.property(
fc.bigInt({ max: Integer.MAX_SAFE_VALUE.toBigInt(), min: Integer.MIN_SAFE_VALUE.toBigInt() }),
num => int(num).toBigInt() === int(num).valueOf()
)
)
})

test('Integer should concatenate with a string', () => {
fc.assert(
fc.property(
fc.bigInt({ max: Integer.MAX_SAFE_VALUE.toBigInt(), min: Integer.MIN_SAFE_VALUE.toBigInt() }),
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
num => 'string' + int(num) + 'str' === 'string' + int(num).toString() + 'str'
)
)
})

test('Integer should be able to used in the string interpolation', () => {
fc.assert(
fc.property(
fc.bigInt({ max: Integer.MAX_SAFE_VALUE.toBigInt(), min: Integer.MIN_SAFE_VALUE.toBigInt() }),
num => `string${int(num)}str` === 'string' + int(num).toString() + 'str'
)
)
})

test('int(string) should match int(Integer)', () => {
fc.assert(fc.property(fc.integer(), i => int(i).equals(int(i.toString()))))
})
Expand Down
15 changes: 15 additions & 0 deletions packages/neo4j-driver-deno/lib/core/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ class Integer {
}
}

/**
* Converts the Integer to it primitive value.
*
* @since 5.4.0
* @returns {bigint}
*
* @see {@link Integer#toBigInt}
* @see {@link Integer#toInt}
* @see {@link Integer#toNumber}
* @see {@link Integer#toString}
*/
valueOf (): bigint {
return this.toBigInt()
}

/**
* Gets the high 32 bits as a signed integer.
* @returns {number} Signed high bits
Expand Down
2 changes: 1 addition & 1 deletion packages/neo4j-driver/test/internal/routing-table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('#unit RoutingTable', () => {
}))

it('should return Integer.MAX_VALUE as expirationTime when ttl overflowed', async () => {
const ttl = int(Integer.MAX_VALUE - 2)
const ttl = int(Integer.MAX_VALUE - 2n)
const routers = ['router:7699']
const readers = ['reader1:7699', 'reader2:7699']
const writers = ['writer1:7693', 'writer2:7692', 'writer3:7629']
Expand Down