From 2cdb217c89c20ca8b5aedf00aa15bd2c3dee9afe Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 4 May 2021 18:48:54 +0200 Subject: [PATCH] fix(service-provider-core): make Long print evaluable MONGOSH-750 --- packages/cli-repl/test/e2e-bson.spec.ts | 6 +++--- packages/service-provider-core/src/printable-bson.spec.ts | 6 +++++- packages/service-provider-core/src/printable-bson.ts | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/cli-repl/test/e2e-bson.spec.ts b/packages/cli-repl/test/e2e-bson.spec.ts index ea3c255922..e496cf32a7 100644 --- a/packages/cli-repl/test/e2e-bson.spec.ts +++ b/packages/cli-repl/test/e2e-bson.spec.ts @@ -42,7 +42,7 @@ describe('BSON e2e', function() { MinKey: 'MinKey()', MaxKey: 'MaxKey()', NumberInt: 'Int32(32)', - NumberLong: 'Long("64")', + NumberLong: 'Long.fromString("64")', Timestamp: 'Timestamp(1, 100)', Symbol: 'abc', Code: 'Code("abc")', @@ -231,7 +231,7 @@ describe('BSON e2e', function() { const value = 'NumberLong("64")'; await shell.writeInputLine(value); await eventually(() => { - shell.assertContainsOutput('Long("64")'); + shell.assertContainsOutput('Long.fromString("64")'); }); shell.assertNoErrors(); }); @@ -239,7 +239,7 @@ describe('BSON e2e', function() { const value = 'NumberLong("345678654321234561")'; await shell.writeInputLine(value); await eventually(() => { - shell.assertContainsOutput('Long("345678654321234561")'); + shell.assertContainsOutput('Long.fromString("345678654321234561")'); }); shell.assertNoErrors(); }); diff --git a/packages/service-provider-core/src/printable-bson.spec.ts b/packages/service-provider-core/src/printable-bson.spec.ts index da959df1c6..27f56b45a5 100644 --- a/packages/service-provider-core/src/printable-bson.spec.ts +++ b/packages/service-provider-core/src/printable-bson.spec.ts @@ -28,7 +28,11 @@ describe('BSON printers', function() { }); it('formats NumberLong correctly', function() { - expect(inspect(bson.Long.fromString('64'))).to.equal('Long("64")'); + expect(inspect(bson.Long.fromString('64'))).to.equal('Long.fromString("64")'); + }); + + it('formats unsigned NumberLong correctly', function() { + expect(inspect(bson.Long.fromString('64', true))).to.equal('Long.fromString("64", true)'); }); it('formats NumberDecimal correctly', function() { diff --git a/packages/service-provider-core/src/printable-bson.ts b/packages/service-provider-core/src/printable-bson.ts index cb5ae9a059..d32278d8d9 100644 --- a/packages/service-provider-core/src/printable-bson.ts +++ b/packages/service-provider-core/src/printable-bson.ts @@ -45,7 +45,7 @@ export const bsonStringifiers: Record string> = { }, Long: function(): string { - return `Long("${this.toString()}")`; + return `Long.fromString("${this.toString()}"${this.unsigned ? ', true' : ''})`; }, Binary: function(): string {