Skip to content

Commit

Permalink
improving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed May 27, 2020
1 parent cbad7e0 commit bb61c07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ function minify(sql, options) {
continue;
}

if (s === '\'') {
if (s === `'`) {
closeIdx = idx;
do {
closeIdx = sql.indexOf('\'', closeIdx + 1);
closeIdx = sql.indexOf(`'`, closeIdx + 1);
if (closeIdx > 0) {
let i = closeIdx;
while (sql[--i] === '\\') ;
if ((closeIdx - i) % 2) {
let step = closeIdx;
while (++step < len && sql[step] === '\'') ;
while (++step < len && sql[step] === `'`) ;
if ((step - closeIdx) % 2) {
closeIdx = step - 1;
break;
Expand Down
10 changes: 8 additions & 2 deletions test/mainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const minify = require('../lib');
const {parsingErrorCode} = require('../lib/error');
const PEC = parsingErrorCode;


describe('Minify/Positive', () => {

describe('end-of-line detection', () => {
Expand Down Expand Up @@ -279,7 +278,14 @@ describe('Minify/Negative', () => {
err = e.toString();
}
it('must contain error', () => {
expect(err).toBe(`SQLParsingError {${EOL}${gap}code: parsingErrorCode.unclosedText${EOL}${gap}error: "Unclosed text block."${EOL}${gap}position: {line: 1, col: 1}${EOL}}`);
const txt = [
`SQLParsingError {`,
`${gap}code: parsingErrorCode.unclosedText`,
`${gap}error: "Unclosed text block."`,
`${gap}position: {line: 1, col: 1}`,
`}`
];
expect(err).toBe(txt.join(EOL));
});
});

Expand Down

0 comments on commit bb61c07

Please sign in to comment.