diff --git a/lib/formatting.js b/lib/formatting.js index de7e637b..9bd96112 100644 --- a/lib/formatting.js +++ b/lib/formatting.js @@ -839,7 +839,7 @@ const $as = { * - `obj` - the formatting object, and is the same as `this` context * * - For $[Index Variables] formatting: - * - `index` - element's index (starts with 1) that's outside of the input array + * - `index` - element's index (starts with 1) that's outside the input array * - `arr` - the formatting/input array, and is the same as `this` context * * You can tell which type of call it is by checking the type of the first parameter. @@ -884,7 +884,8 @@ const $to = { }, number(num) { if (typeof num === 'bigint' || Number.isFinite(num)) { - return num.toString(); + const s = num.toString(); + return num < 0 ? `(${s})` : s; } // Converting NaN/+Infinity/-Infinity according to Postgres documentation: // http://www.postgresql.org/docs/9.6/static/datatype-numeric.html#DATATYPE-FLOAT diff --git a/test/db.spec.js b/test/db.spec.js index 918933b5..369758ca 100644 --- a/test/db.spec.js +++ b/test/db.spec.js @@ -239,9 +239,6 @@ describe('Connection', () => { }); if (!isWindows) { - /* - Disabled this test on 14/11/2020, since it started showing crypto-related issues on Windows; - */ describe('for invalid connection', () => { const dbErr = pgp('bla-bla'); let error; @@ -268,9 +265,6 @@ describe('Connection', () => { } if (!isWindows) { - /* - Disabled this test on 14/11/2020, since it started showing crypto-related issues on Windows; - */ describe('for invalid user name', () => { const errCN = JSON.parse(JSON.stringify(dbHeader.cn)); // dumb connection cloning; errCN.user = 'somebody'; @@ -354,10 +348,6 @@ describe('Connection', () => { }); if (!isWindows) { - /* - This test has been known to be very flaky, especially on Windows, and keeps - getting in the way of testing the framework locally. - */ describe('db side closing of the connection pool', () => { const singleCN = JSON.parse(JSON.stringify(dbHeader.cn)); // dumb connection cloning; singleCN.max = 1; diff --git a/test/format.spec.js b/test/format.spec.js index f7f5e66f..3b3290aa 100644 --- a/test/format.spec.js +++ b/test/format.spec.js @@ -122,7 +122,7 @@ describe('Method as.number', () => { expect(pgp.as.number(0)).toBe('0'); expect(pgp.as.number(1)).toBe('1'); expect(pgp.as.number(1234567890)).toBe('1234567890'); - expect(pgp.as.number(-123.456)).toBe('-123.456'); + expect(pgp.as.number(-123.456)).toBe('(-123.456)'); expect(pgp.as.number(NaN)).toBe('\'NaN\''); expect(pgp.as.number(Number.NaN)).toBe('\'NaN\''); expect(pgp.as.number(1 / 0)).toBe('\'+Infinity\''); @@ -326,8 +326,8 @@ describe('Method as.csv', () => { expect(pgp.as.csv(0)).toBe('0'); // test zero; expect(pgp.as.csv([0])).toBe('0'); // test zero in array; - expect(pgp.as.csv(-123.456)).toBe('-123.456'); // test a float; - expect(pgp.as.csv([-123.456])).toBe('-123.456'); // test a float in array; + expect(pgp.as.csv(-123.456)).toBe('(-123.456)'); // test a float; + expect(pgp.as.csv([-123.456])).toBe('(-123.456)'); // test a float in array; expect(pgp.as.csv(true)).toBe('true'); // test boolean True; expect(pgp.as.csv([true])).toBe('true'); // test boolean True in array; @@ -678,7 +678,7 @@ describe('Method as.format', () => { expect(pgp.as.format('$1', [userObj])).toBe(pgp.as.text(JSON.stringify(userObj))); expect(pgp.as.format('$1^', [userObj])).toBe(JSON.stringify(userObj)); - expect(pgp.as.format('$1, $2, $3, $4', [true, -12.34, 'text', dateSample])).toBe(`true, -12.34, 'text', '${$pgUtils.prepareValue(dateSample)}'`); + expect(pgp.as.format('$1, $2, $3, $4', [true, -12.34, 'text', dateSample])).toBe(`true, (-12.34), 'text', '${$pgUtils.prepareValue(dateSample)}'`); expect(pgp.as.format('$1 $1, $2 $2, $1', [1, 'two'])).toBe('1 1, \'two\' \'two\', 1'); // test for repeated variables; @@ -970,7 +970,7 @@ describe('Named Parameters', () => { three: -123.45, four: dateSample, five: () => 'text' - })).toBe('null,true,-123.45,\'' + $pgUtils.prepareValue(dateSample) + '\',\'text\''); + })).toBe('null,true,(-123.45),\'' + $pgUtils.prepareValue(dateSample) + '\',\'text\''); }); it('must treat null and undefined values equally', () => {