Skip to content

Commit

Permalink
fix: make Long inspect result evaluable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
addaleax authored and durran committed May 10, 2021
1 parent 2aba3c0 commit 3a2eff1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/long.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ export class Long {
}

inspect(): string {
return `new Long("${this.toString()}")`;
return `Long.fromString("${this.toString()}"${this.unsigned ? ', true' : ''})`;
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/node/bson_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,10 @@ describe('BSON', function () {
*/
it('Long', function () {
const long = Long.fromString('42');
expect(inspect(long)).to.equal('new Long("42")');
expect(inspect(long)).to.equal('Long.fromString("42")');

const unsignedLong = Long.fromString('42', true);
expect(inspect(unsignedLong)).to.equal('Long.fromString("42", true)');
});

/**
Expand Down

0 comments on commit 3a2eff1

Please sign in to comment.