Skip to content

Commit 69b7304

Browse files
committed
move tests out of loop
1 parent d64860e commit 69b7304

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

test/node/bigint.test.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -106,37 +106,44 @@ describe('BSON BigInt support', function () {
106106
it(description, test);
107107
}
108108

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-
];
109+
it('correctly deserializes min 64 bit int (-2n**63n)', function () {
110+
expect(
111+
BSON.deserialize(Buffer.from('10000000126100000000000000008000', 'hex'), {
112+
useBigInt64: true
113+
})
114+
).to.deep.equal({ a: -(2n ** 63n) });
115+
});
132116

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-
}
117+
it('correctly deserializes -1n', function () {
118+
expect(
119+
BSON.deserialize(Buffer.from('10000000126100FFFFFFFFFFFFFFFF00', 'hex'), {
120+
useBigInt64: true
121+
})
122+
).to.deep.equal({ a: -1n });
123+
});
124+
125+
it('correctly deserializes 0n', function () {
126+
expect(
127+
BSON.deserialize(Buffer.from('10000000126100000000000000000000', 'hex'), {
128+
useBigInt64: true
129+
})
130+
).to.deep.equal({ a: 0n });
131+
});
132+
133+
it('correctly deserializes 1n', function () {
134+
expect(
135+
BSON.deserialize(Buffer.from('10000000126100010000000000000000', 'hex'), {
136+
useBigInt64: true
137+
})
138+
).to.deep.equal({ a: 1n });
139+
});
140+
141+
it('correctly deserializes max 64 bit int (2n**63n -1n)', function () {
142+
expect(
143+
BSON.deserialize(Buffer.from('10000000126100FFFFFFFFFFFFFF7F00', 'hex'), {
144+
useBigInt64: true
145+
})
146+
).to.deep.equal({ a: 2n ** 63n - 1n });
140147
});
141148
});
142149

0 commit comments

Comments
 (0)