Skip to content

Commit 3a2eff1

Browse files
addaleaxdurran
authored andcommitted
fix: make Long inspect result evaluable
Do basically the same thing we’re already doing for `Decimal128` to ensure that the inspect result accurately represents the contents in a way that can be used to evaluate it again. NODE-3256
1 parent 2aba3c0 commit 3a2eff1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/long.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ export class Long {
994994
}
995995

996996
inspect(): string {
997-
return `new Long("${this.toString()}")`;
997+
return `Long.fromString("${this.toString()}"${this.unsigned ? ', true' : ''})`;
998998
}
999999
}
10001000

test/node/bson_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,10 @@ describe('BSON', function () {
23562356
*/
23572357
it('Long', function () {
23582358
const long = Long.fromString('42');
2359-
expect(inspect(long)).to.equal('new Long("42")');
2359+
expect(inspect(long)).to.equal('Long.fromString("42")');
2360+
2361+
const unsignedLong = Long.fromString('42', true);
2362+
expect(inspect(unsignedLong)).to.equal('Long.fromString("42", true)');
23602363
});
23612364

23622365
/**

0 commit comments

Comments
 (0)