Skip to content

Commit d64860e

Browse files
committed
move tests to deserialize
1 parent cdaec88 commit d64860e

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

test/node/bigint.test.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ describe('BSON BigInt support', function () {
1010
}
1111
});
1212

13-
describe('BSON roundtripping', function () {
14-
const numbers = [-(2n ** 63n), -1n, 0n, 1n, 2n ** 63n - 1n];
15-
16-
for (const number of numbers) {
17-
it(`correctly roundtrips ${number}`, function () {
18-
const inputDoc = { number };
19-
const serializedDoc = BSON.serialize(inputDoc);
20-
const outputDoc = BSON.deserialize(serializedDoc, { useBigInt64: true });
21-
22-
expect(outputDoc).to.deep.equal(inputDoc);
23-
});
24-
}
25-
});
26-
2713
describe('BSON.deserialize()', function () {
2814
type DeserialzationOptions = {
2915
useBigInt64: boolean | undefined;
@@ -119,6 +105,39 @@ describe('BSON BigInt support', function () {
119105

120106
it(description, test);
121107
}
108+
109+
describe('edge case tests', function () {
110+
const tests = [
111+
{
112+
expectedResult: { a: -(2n ** 63n) },
113+
input: Buffer.from('10000000126100000000000000008000', 'hex')
114+
},
115+
{
116+
expectedResult: { a: -1n },
117+
input: Buffer.from('10000000126100FFFFFFFFFFFFFFFF00', 'hex')
118+
},
119+
{
120+
expectedResult: { a: 0n },
121+
input: Buffer.from('10000000126100000000000000000000', 'hex')
122+
},
123+
{
124+
expectedResult: { a: 1n },
125+
input: Buffer.from('10000000126100010000000000000000', 'hex')
126+
},
127+
{
128+
expectedResult: { a: 2n ** 63n - 1n },
129+
input: Buffer.from('10000000126100FFFFFFFFFFFFFF7F00', 'hex')
130+
}
131+
];
132+
133+
for (const test of tests) {
134+
it(`correctly deserializes the bson document encoded in ${test.input.toString('hex')}`, function () {
135+
expect(BSON.deserialize(test.input, { useBigInt64: true })).to.deep.equal(
136+
test.expectedResult
137+
);
138+
});
139+
}
140+
});
122141
});
123142

124143
describe('BSON.serialize()', function () {

0 commit comments

Comments
 (0)