Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed May 9, 2020
1 parent 1f6807d commit da12e2c
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 49 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
],
"quotes": [
"error",
"single"
"single",{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"semi": [
"error",
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js
matrix:
include:
- node_js: "7"
script: "npm test"
- node_js: "10"
- node_js: "8"
script: "npm test"
- node_js: "12"
script: "npm run travis"
- node_js: "14"
script: "npm test"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ $ npm run coverage

## License

Copyright © 2019 [Vitaly Tomilov](https://github.com/vitaly-t);
Copyright © 2020 [Vitaly Tomilov](https://github.com/vitaly-t);
Released under the MIT license.

[SQLParsingError]:https://github.com/vitaly-t/pg-minify/blob/master/lib/error.js#L22
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-minify",
"version": "1.5.3",
"version": "1.6.0",
"description": "Minifies PostgreSQL scripts.",
"main": "lib/index.js",
"typings": "typescript/pg-minify.d.ts",
Expand Down Expand Up @@ -39,7 +39,7 @@
},
"license": "MIT",
"engines": {
"node": ">=7.6"
"node": ">=8.0"
},
"devDependencies": {
"coveralls": "3.1.0",
Expand Down
8 changes: 4 additions & 4 deletions test/compressSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Compress', () => {

describe('with a text block', () => {
it('must remove all gaps', () => {
expect(minify('some \'text\' here')).toBe('some\'text\'here');
expect(minify(`some 'text' here`)).toBe(`some'text'here`);
});
});

Expand All @@ -48,15 +48,15 @@ describe('Compress', () => {

describe('for multi-line text', () => {
it('must preserve the prefix space', () => {
expect(minify('select \'\nvalue\'', {compress: true})).toBe('select E\'\\nvalue\'');
expect(minify(`select '\nvalue'`, {compress: true})).toBe(`select E'\\nvalue'`);
});
it('must not add a space to an empty string', () => {
expect(minify('\'\nvalue\'', {compress: true})).toBe('E\'\\nvalue\'');
expect(minify(`'\nvalue'`, {compress: true})).toBe(`E'\\nvalue'`);
});
it('must not add a space after special symbols', () => {
for (let i = 0; i < compressors.length; i++) {
const c = compressors[i];
expect(minify(c + '\'\nvalue\'', {compress: true})).toBe(c + 'E\'\\nvalue\'');
expect(minify(c + `'\nvalue'`, {compress: true})).toBe(c + `E'\\nvalue'`);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/identSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Quoted Identifier / Positive', () => {
});

it('must allow single-quotes inside', () => {
expect(minify('"\'some\'text\'"')).toBe('"\'some\'text\'"');
expect(minify(`"'some'text'"`)).toBe(`"'some'text'"`);
});
});

Expand Down
70 changes: 35 additions & 35 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ describe('Minify/Positive', () => {

describe('comments in strings', () => {
it('must be skipped', () => {
expect(minify('\'--comment\'')).toBe('\'--comment\'');
expect(minify('\'--comment' + LB + 'text\'')).toBe('E\'--comment\\ntext\'');
expect(minify('\'/*comment*/\'')).toBe('\'/*comment*/\'');
expect(minify(`'--comment'`)).toBe(`'--comment'`);
expect(minify(`'--comment` + LB + `text'`)).toBe(`E'--comment\\ntext'`);
expect(minify(`'/*comment*/'`)).toBe(`'/*comment*/'`);
});
});

Expand All @@ -55,31 +55,31 @@ describe('Minify/Positive', () => {
describe('empty text', () => {
it('must be returned empty', () => {
expect(minify('')).toBe('');
expect(minify('\'\'')).toBe('\'\'');
expect(minify(`''`)).toBe(`''`);
});
});

describe('multi-line text', () => {
it('must be returned with E', () => {
expect(minify('\'' + LB + '\'')).toBe('E\'\\n\'');
expect(minify('\'' + LB + LB + '\'')).toBe('E\'\\n\\n\'');
expect(minify('text \'' + LB + '\'')).toBe('text E\'\\n\'');
expect(minify('text e\'' + LB + '\'')).toBe('text e\'\\n\'');
expect(minify('e\'' + LB + '\'')).toBe('e\'\\n\'');
expect(minify('E\'' + LB + '\'')).toBe('E\'\\n\'');
expect(minify(`'` + LB + `'`)).toBe(`E'\\n'`);
expect(minify(`'` + LB + LB + `'`)).toBe(`E'\\n\\n'`);
expect(minify(`text '` + LB + `'`)).toBe(`text E'\\n'`);
expect(minify(`text e'` + LB + `'`)).toBe(`text e'\\n'`);
expect(minify(`e'` + LB + `'`)).toBe(`e'\\n'`);
expect(minify(`E'` + LB + `'`)).toBe(`E'\\n'`);
});

it('must truncate text correctly', () => {
expect(minify('\' first ' + LB + ' last \'')).toBe('E\' first\\nlast \'');
expect(minify('\' first ' + LB + ' second ' + LB + ' third \'')).toBe('E\' first\\nsecond\\nthird \'');
expect(minify(`' first ` + LB + ` last '`)).toBe(`E' first\\nlast '`);
expect(minify(`' first ` + LB + ` second ` + LB + ` third '`)).toBe(`E' first\\nsecond\\nthird '`);
});

it('must add a space where necessary', () => {
expect(minify('select\'\nvalue\'')).toBe('select E\'\\nvalue\'');
expect(minify(`select'\nvalue'`)).toBe(`select E'\\nvalue'`);
});

it('must not add a space to an empty string', () => {
expect(minify('\'\nvalue\'')).toBe('E\'\\nvalue\'');
expect(minify(`'\nvalue'`)).toBe(`E'\\nvalue'`);
});

});
Expand Down Expand Up @@ -120,20 +120,20 @@ describe('Minify/Positive', () => {
describe('tabs in text', () => {
it('must be replaced', () => {
expect(minify('\t')).toBe('');
expect(minify('\'\t\'')).toBe('E\'\\t\'');
expect(minify('\'\\t\'')).toBe('\'\\t\'');
expect(minify('e\' \t \'')).toBe('e\' \\t \'');
expect(minify('\'\t first ' + LB + '\t second \t' + LB + '\t third \t\'')).toBe('E\'\\t first\\nsecond\\nthird \\t\'');
expect(minify(`'\t'`)).toBe(`E'\\t'`);
expect(minify(`'\\t'`)).toBe(`'\\t'`);
expect(minify(`e' \t '`)).toBe(`e' \\t '`);
expect(minify(`'\t first ` + LB + `\t second \t` + LB + `\t third \t'`)).toBe(`E'\\t first\\nsecond\\nthird \\t'`);
});
});

describe('quotes in strings', () => {
it('must be ignored', () => {
expect(minify('\'\'')).toBe('\'\'');
expect(minify('text \'\'')).toBe('text \'\'');
expect(minify('\'text\\\\\'')).toBe('\'text\\\\\'');
expect(minify('\'\'')).toBe('\'\'');
expect(minify('\'\'\'\'\'\'')).toBe('\'\'\'\'\'\'');
expect(minify(`''`)).toBe(`''`);
expect(minify(`text ''`)).toBe(`text ''`);
expect(minify(`'text\\\\'`)).toBe(`'text\\\\'`);
expect(minify(`''`)).toBe(`''`);
expect(minify(`''''''`)).toBe(`''''''`);
});
});

Expand Down Expand Up @@ -216,24 +216,24 @@ describe('Minify/Negative', () => {
expect(getErrorPos('hello/*world!/**/').column).toBe(14);
});
it('must ignore closures in text', () => {
expect(errorCode('/*\'*/\'*/')).toBe(PEC.unclosedText);
expect(errorCode(`/*'*/'*/`)).toBe(PEC.unclosedText);
});
});

describe('quotes in strings', () => {

it('must report an error', () => {
expect(errorCode('\'')).toBe(PEC.unclosedText);
expect(errorCode('\'\'\'')).toBe(PEC.unclosedText);
expect(errorCode('\'\'\' ')).toBe(PEC.unclosedText);
expect(errorCode('\'\\\'')).toBe(PEC.unclosedText);
expect(errorCode(`'`)).toBe(PEC.unclosedText);
expect(errorCode(`'''`)).toBe(PEC.unclosedText);
expect(errorCode(`''' `)).toBe(PEC.unclosedText);
expect(errorCode(`'\\'`)).toBe(PEC.unclosedText);
});

it('must report positions correctly', () => {
expect(getErrorPos('\'').column).toBe(1);
expect(getErrorPos(' \'').column).toBe(2);
expect(getErrorPos('s\'').column).toBe(2);
expect(getErrorPos('s \'').column).toBe(3);
expect(getErrorPos(`'`).column).toBe(1);
expect(getErrorPos(` '`).column).toBe(2);
expect(getErrorPos(`s'`).column).toBe(2);
expect(getErrorPos(`s '`).column).toBe(3);
});

});
Expand All @@ -252,15 +252,15 @@ describe('Minify/Negative', () => {
// are present, they are expected to affect the comment block.
it('must throw on extra openers', () => {
expect(() => {
minify('1/*0\'/*\'*//2');
minify(`1/*0'/*'*//2`);
}).toThrow('Error parsing SQL at {line:1,col:6}: Unclosed multi-line comment.');
expect(() => {
minify('3/*0"/*"*//4');
}).toThrow('Error parsing SQL at {line:1,col:6}: Unclosed multi-line comment.');
});
it('must throw on extra closures', () => {
expect(() => {
minify('1/*0\'*/\'*//2');
minify(`1/*0'*/'*//2`);
}).toThrow('Error parsing SQL at {line:1,col:8}: Unclosed text block.');
expect(() => {
minify('3/*0"*/"*//4');
Expand All @@ -272,7 +272,7 @@ describe('Minify/Negative', () => {
it('must produce the same output', () => {
let error;
try {
minify('\'test');
minify(`'test`);
} catch (e) {
error = e;
}
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {SQLParsingError} from '../../typescript/pg-minify';
import minify from '../../typescript/pg-minify';

try {
minify('select \'* from table; --comment');
minify(`select '* from table; --comment`);
} catch (error) {
const a = <minify.SQLParsingError>error;
console.log(a.position.line);
Expand Down
2 changes: 1 addition & 1 deletion typescript/pg-minify.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////////////////////////////////////////
// For pg-minify v1.5.0 or later.
// For pg-minify v1.6.0 or later.
////////////////////////////////////////

declare namespace pgMinify {
Expand Down

0 comments on commit da12e2c

Please sign in to comment.