|
@@ -23,6 +23,9 @@
|
|
|
s += first ? '{\n' : ', {\n';
|
|
s += first ? '{\n' : ', {\n';
|
|
|
s += ' statement: \'' + entry.statement.replace(/\n/g, '\\n') + '\',\n';
|
|
s += ' statement: \'' + entry.statement.replace(/\n/g, '\\n') + '\',\n';
|
|
|
s += ' location: { first_line: ' + entry.location.first_line + ', first_column: ' + entry.location.first_column + ', last_line: ' + entry.location.last_line + ', last_column: ' + entry.location.last_column + ' }'
|
|
s += ' location: { first_line: ' + entry.location.first_line + ', first_column: ' + entry.location.first_column + ', last_line: ' + entry.location.last_line + ', last_column: ' + entry.location.last_column + ' }'
|
|
|
|
|
+ if (entry.firstToken) {
|
|
|
|
|
+ s+= ',\n firstToken: \'' + entry.firstToken + '\''
|
|
|
|
|
+ }
|
|
|
s += '\n}';
|
|
s += '\n}';
|
|
|
first = false;
|
|
first = false;
|
|
|
});
|
|
});
|
|
@@ -73,7 +76,8 @@
|
|
|
it('should split "select * from bla" correctly', function () {
|
|
it('should split "select * from bla" correctly', function () {
|
|
|
testParser('select * from bla', [{
|
|
testParser('select * from bla', [{
|
|
|
statement: 'select * from bla',
|
|
statement: 'select * from bla',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 17 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 17 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -86,157 +90,194 @@
|
|
|
location: { first_line: 1, first_column: 1, last_line: 1, last_column: 2 }
|
|
location: { first_line: 1, first_column: 1, last_line: 1, last_column: 2 }
|
|
|
}, {
|
|
}, {
|
|
|
statement: 'select * from bla',
|
|
statement: 'select * from bla',
|
|
|
- location: { first_line: 1, first_column: 2, last_line: 1, last_column: 19 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 2, last_line: 1, last_column: 19 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla;" correctly', function () {
|
|
it('should split "select * from bla;" correctly', function () {
|
|
|
testParser('select * from bla;', [{
|
|
testParser('select * from bla;', [{
|
|
|
statement: 'select * from bla;',
|
|
statement: 'select * from bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla;select * from ble" correctly', function () {
|
|
it('should split "select * from bla;select * from ble" correctly', function () {
|
|
|
testParser('select * from bla;select * from ble', [{
|
|
testParser('select * from bla;select * from ble', [{
|
|
|
statement: 'select * from bla;',
|
|
statement: 'select * from bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}, {
|
|
}, {
|
|
|
statement: 'select * from ble',
|
|
statement: 'select * from ble',
|
|
|
- location: { first_line: 1, first_column: 18, last_line: 1, last_column: 35 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 18, last_line: 1, last_column: 35 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla;;select * from ble" correctly', function () {
|
|
it('should split "select * from bla;;select * from ble" correctly', function () {
|
|
|
testParser('select * from bla;;select * from ble', [{
|
|
testParser('select * from bla;;select * from ble', [{
|
|
|
statement: 'select * from bla;',
|
|
statement: 'select * from bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}, {
|
|
}, {
|
|
|
statement: ';',
|
|
statement: ';',
|
|
|
location: { first_line: 1, first_column: 18, last_line: 1, last_column: 19 }
|
|
location: { first_line: 1, first_column: 18, last_line: 1, last_column: 19 }
|
|
|
},{
|
|
},{
|
|
|
statement: 'select * from ble',
|
|
statement: 'select * from ble',
|
|
|
- location: { first_line: 1, first_column: 19, last_line: 1, last_column: 36 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 19, last_line: 1, last_column: 36 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla;\\n;select * from ble" correctly', function () {
|
|
it('should split "select * from bla;\\n;select * from ble" correctly', function () {
|
|
|
testParser('select * from bla;\n;select * from ble', [{
|
|
testParser('select * from bla;\n;select * from ble', [{
|
|
|
statement: 'select * from bla;',
|
|
statement: 'select * from bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 18 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}, {
|
|
}, {
|
|
|
statement: '\n;',
|
|
statement: '\n;',
|
|
|
location: { first_line: 1, first_column: 18, last_line: 2, last_column: 1 }
|
|
location: { first_line: 1, first_column: 18, last_line: 2, last_column: 1 }
|
|
|
},{
|
|
},{
|
|
|
statement: 'select * from ble',
|
|
statement: 'select * from ble',
|
|
|
- location: { first_line: 2, first_column: 1, last_line: 2, last_column: 18 }
|
|
|
|
|
|
|
+ location: { first_line: 2, first_column: 1, last_line: 2, last_column: 18 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * \\nfrom bla;\\r\\nselect * from ble;\\n" correctly', function () {
|
|
it('should split "select * \\nfrom bla;\\r\\nselect * from ble;\\n" correctly', function () {
|
|
|
testParser('select * \nfrom bla;\r\nselect * from ble;\n', [{
|
|
testParser('select * \nfrom bla;\r\nselect * from ble;\n', [{
|
|
|
statement: 'select * \nfrom bla;',
|
|
statement: 'select * \nfrom bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 2, last_column: 9 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 2, last_column: 9 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}, {
|
|
}, {
|
|
|
statement: '\r\nselect * from ble;',
|
|
statement: '\r\nselect * from ble;',
|
|
|
- location: { first_line: 2, first_column: 9, last_line: 3, last_column: 18 }
|
|
|
|
|
|
|
+ location: { first_line: 2, first_column: 9, last_line: 3, last_column: 18 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla where x = ";";" correctly', function () {
|
|
it('should split "select * from bla where x = ";";" correctly', function () {
|
|
|
testParser('select * from bla where x = ";";', [{
|
|
testParser('select * from bla where x = ";";', [{
|
|
|
statement: 'select * from bla where x = ";";',
|
|
statement: 'select * from bla where x = ";";',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 32 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 32 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla where x = \';\';\\n\\nSELECT bla FROM foo WHERE y = `;` AND true = false;" correctly', function () {
|
|
it('should split "select * from bla where x = \';\';\\n\\nSELECT bla FROM foo WHERE y = `;` AND true = false;" correctly', function () {
|
|
|
testParser('select * from bla where x = \';\';\n\nSELECT bla FROM foo WHERE y = `;` AND true = false;', [{
|
|
testParser('select * from bla where x = \';\';\n\nSELECT bla FROM foo WHERE y = `;` AND true = false;', [{
|
|
|
statement: 'select * from bla where x = \';\';',
|
|
statement: 'select * from bla where x = \';\';',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 32 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 32 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}, {
|
|
}, {
|
|
|
statement: '\n\nSELECT bla FROM foo WHERE y = `;` AND true = false;',
|
|
statement: '\n\nSELECT bla FROM foo WHERE y = `;` AND true = false;',
|
|
|
- location: { first_line: 1, first_column: 32, last_line: 3, last_column: 51 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 32, last_line: 3, last_column: 51 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select * from bla where x = "; AND boo = 1;\\n\\nUSE db" correctly', function () {
|
|
it('should split "select * from bla where x = "; AND boo = 1;\\n\\nUSE db" correctly', function () {
|
|
|
testParser('select * from bla where x = "; AND boo = 1;\n\nUSE db', [{
|
|
testParser('select * from bla where x = "; AND boo = 1;\n\nUSE db', [{
|
|
|
statement: 'select * from bla where x = "; AND boo = 1;\n\nUSE db',
|
|
statement: 'select * from bla where x = "; AND boo = 1;\n\nUSE db',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 3, last_column: 6 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 3, last_column: 6 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "--- Some comment with ; ; \\nselect * from bla where x = ";";" correctly', function () {
|
|
it('should split "--- Some comment with ; ; \\nselect * from bla where x = ";";" correctly', function () {
|
|
|
testParser('--- Some comment with ; ; \nselect * from bla where x = ";";', [{
|
|
testParser('--- Some comment with ; ; \nselect * from bla where x = ";";', [{
|
|
|
statement: '--- Some comment with ; ; \nselect * from bla where x = ";";',
|
|
statement: '--- Some comment with ; ; \nselect * from bla where x = ";";',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 2, last_column: 32 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 2, last_column: 32 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select *\n-- bla\n from bla;" correctly', function () {
|
|
it('should split "select *\n-- bla\n from bla;" correctly', function () {
|
|
|
testParser('select *\n-- bla\n from bla;', [{
|
|
testParser('select *\n-- bla\n from bla;', [{
|
|
|
statement: 'select *\n-- bla\n from bla;',
|
|
statement: 'select *\n-- bla\n from bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 3, last_column: 10 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 3, last_column: 10 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "select *\\n/* bla \\n\\n*/\\n from bla;" correctly', function () {
|
|
it('should split "select *\\n/* bla \\n\\n*/\\n from bla;" correctly', function () {
|
|
|
testParser('select *\n/* bla \n\n*/\n from bla;', [{
|
|
testParser('select *\n/* bla \n\n*/\n from bla;', [{
|
|
|
statement: 'select *\n/* bla \n\n*/\n from bla;',
|
|
statement: 'select *\n/* bla \n\n*/\n from bla;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 5, last_column: 10 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 5, last_column: 10 },
|
|
|
|
|
+ firstToken: 'select'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT\\n id -- some ID\\n FROM customers;" correctly', function () {
|
|
it('should split "SELECT\\n id -- some ID\\n FROM customers;" correctly', function () {
|
|
|
testParser('SELECT\n id -- some ID\n FROM customers;', [{
|
|
testParser('SELECT\n id -- some ID\n FROM customers;', [{
|
|
|
statement: 'SELECT\n id -- some ID\n FROM customers;',
|
|
statement: 'SELECT\n id -- some ID\n FROM customers;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 3, last_column: 16 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 3, last_column: 16 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT\n id -- some ID;\n FROM customers;" correctly', function () {
|
|
it('should split "SELECT\n id -- some ID;\n FROM customers;" correctly', function () {
|
|
|
testParser('SELECT\n id -- some ID;\n FROM customers;', [{
|
|
testParser('SELECT\n id -- some ID;\n FROM customers;', [{
|
|
|
statement: 'SELECT\n id -- some ID;\n FROM customers;',
|
|
statement: 'SELECT\n id -- some ID;\n FROM customers;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 3, last_column: 16 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 3, last_column: 16 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT id\\n\\n /* from customers; */ FROM other;" correctly', function () {
|
|
it('should split "SELECT id\\n\\n /* from customers; */ FROM other;" correctly', function () {
|
|
|
testParser('SELECT id\n\n /* from customers; */ FROM other;', [{
|
|
testParser('SELECT id\n\n /* from customers; */ FROM other;', [{
|
|
|
statement: 'SELECT id\n\n /* from customers; */ FROM other;',
|
|
statement: 'SELECT id\n\n /* from customers; */ FROM other;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 3, last_column: 34 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 3, last_column: 34 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT ` " correctly', function () {
|
|
it('should split "SELECT ` " correctly', function () {
|
|
|
testParser('SELECT ` ', [{
|
|
testParser('SELECT ` ', [{
|
|
|
statement: 'SELECT ` ',
|
|
statement: 'SELECT ` ',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 11 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 11 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT " " correctly', function () {
|
|
it('should split "SELECT " " correctly', function () {
|
|
|
testParser('SELECT " ', [{
|
|
testParser('SELECT " ', [{
|
|
|
statement: 'SELECT " ',
|
|
statement: 'SELECT " ',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 11 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 11 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT \' " correctly', function () {
|
|
it('should split "SELECT \' " correctly', function () {
|
|
|
testParser('SELECT \' ', [{
|
|
testParser('SELECT \' ', [{
|
|
|
statement: 'SELECT \' ',
|
|
statement: 'SELECT \' ',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 11 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 11 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
|
|
+ }]);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should split "-- Some comment\\n\\n CREATE TABLE bla (id int); /* some \\nother comment*/ ALTER TABLE boo" correctly', function () {
|
|
|
|
|
+ testParser('-- Some comment\n\n CREATE TABLE bla (id int); /* some \nother comment*/ ALTER TABLE boo', [{
|
|
|
|
|
+ statement: '-- Some comment\n\n CREATE TABLE bla (id int);',
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 3, last_column: 30 },
|
|
|
|
|
+ firstToken: 'CREATE'
|
|
|
|
|
+ }, {
|
|
|
|
|
+ statement: ' /* some \nother comment*/ ALTER TABLE boo',
|
|
|
|
|
+ location: { first_line: 3, first_column: 30, last_line: 4, last_column: 31 },
|
|
|
|
|
+ firstToken: 'ALTER'
|
|
|
}]);
|
|
}]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should split "SELECT " \\" ;; ", \'"\', \' ;\' from bla; /* \\n\\n"" ; \\n; */ FROM other;" correctly', function () {
|
|
it('should split "SELECT " \\" ;; ", \'"\', \' ;\' from bla; /* \\n\\n"" ; \\n; */ FROM other;" correctly', function () {
|
|
|
testParser('USE `db;`;\r\nSELECT " \\" ;; ", \'"\', \' ;\' from bla; /* \n\n"" ; \n; FROM other;*/', [{
|
|
testParser('USE `db;`;\r\nSELECT " \\" ;; ", \'"\', \' ;\' from bla; /* \n\n"" ; \n; FROM other;*/', [{
|
|
|
statement: 'USE `db;`;',
|
|
statement: 'USE `db;`;',
|
|
|
- location: { first_line: 1, first_column: 0, last_line: 1, last_column: 10 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 0, last_line: 1, last_column: 10 },
|
|
|
|
|
+ firstToken: 'USE'
|
|
|
}, {
|
|
}, {
|
|
|
statement: '\r\nSELECT " \\" ;; ", \'"\', \' ;\' from bla;',
|
|
statement: '\r\nSELECT " \\" ;; ", \'"\', \' ;\' from bla;',
|
|
|
- location: { first_line: 1, first_column: 10, last_line: 2, last_column: 37 }
|
|
|
|
|
|
|
+ location: { first_line: 1, first_column: 10, last_line: 2, last_column: 37 },
|
|
|
|
|
+ firstToken: 'SELECT'
|
|
|
}, {
|
|
}, {
|
|
|
statement: ' /* \n\n"" ; \n; FROM other;*/',
|
|
statement: ' /* \n\n"" ; \n; FROM other;*/',
|
|
|
location: { first_line: 2, first_column: 37, last_line: 5, last_column: 16 }
|
|
location: { first_line: 2, first_column: 37, last_line: 5, last_column: 16 }
|