Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expect(pgp.as.format('$1^', 'one')).toBe('one');
expect(pgp.as.format('$1:raw', 'one')).toBe('one');
expect(pgp.as.format('$1', ['one'])).toBe('\'one\'');
expect(pgp.as.format('$1^', ['one'])).toBe('one');
expect(pgp.as.format('$1:raw', ['one'])).toBe('one');
expect(pgp.as.format('$1, $1', 'one')).toBe('\'one\', \'one\'');
expect(pgp.as.format('$1$1', 'one')).toBe('\'one\'\'one\'');
expect(pgp.as.format('$1^$1^', 'one')).toBe('oneone');
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 $1, $2 $2, $1', [1, 'two'])).toBe('1 1, \'two\' \'two\', 1'); // test for repeated variables;
expect(pgp.as.format('Test: $1', ['don\'t break quotes!'])).toBe('Test: \'don\'\'t break quotes!\'');
// testing with lots of variables;
let source = '', dest = '';
const params = [];
for (let i = 1; i <= 1000; i++) {
source += '$' + i;
dest += i;
params.push(i);
}
expect(pgp.as.format(source, params)).toBe(dest);
// testing various cases with many variables:
it('must correctly inject raw-text variables', () => {
expect(pgp.as.format('${name},${name^},${name},${name^}', {
name: 'me'
})).toBe('\'me\',me,\'me\',me');
expect(pgp.as.format('$1,$1^,$1,$1^', 'hello')).toBe('\'hello\',hello,\'hello\',hello');
expect(pgp.as.format('$1,$2,$1^,$2^', ['one', 'two']))
.toBe('\'one\',\'two\',one,two');
expect(pgp.as.format('$1^ $2^ $1', ['Don\'t break', 'this']))
.toBe('Don\'t break this \'Don\'\'t break\'');
expect(pgp.as.format('$1^,$1', dateSample))
.toBe($pgUtils.prepareValue(dateSample) + ',\'' + $pgUtils.prepareValue(dateSample) + '\'');
});
it('must correctly convert any date', () => {
expect(pgp.as.date()).toBe('null');
expect(pgp.as.date(null)).toBe('null');
expect(pgp.as.date(dateSample)).toBe('\'' + $pgUtils.prepareValue(dateSample) + '\'');
expect(pgp.as.date(dateSample, true)).toBe($pgUtils.prepareValue(dateSample));
});