From 383d632bb0aae1021960c99909c5b6d51c7ccc4d Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 10 Feb 2016 13:09:06 -0500 Subject: [PATCH] Fix mysql insert batch tests --- gulpfile.js | 2 +- lib/QueryParser.js | 31 ++++++++++++++++--------------- test/adapters/mysql-base.js | 22 ---------------------- test/adapters/mysql2_test.js | 23 +++++++++++++++++++++++ test/adapters/mysql_test.js | 23 +++++++++++++++++++++++ test/mocha.opts | 2 +- 6 files changed, 64 insertions(+), 39 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index cace1f5..09c7ae1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -89,7 +89,7 @@ gulp.task('sloc', () => gulp.src(SRC_FILES).pipe(sloc())); gulp.task('test-sloc', () => gulp.src(TEST_FILES).pipe(sloc())); gulp.task('docs', () => { - gulp.src(['lib/**/*.js']) + gulp.src(['lib/*.js']) .pipe(documentation({format: 'html'})) .pipe(gulp.dest('docs')); gulp.src(['lib/*.js']) diff --git a/lib/QueryParser.js b/lib/QueryParser.js index 461a531..02a3cd3 100644 --- a/lib/QueryParser.js +++ b/lib/QueryParser.js @@ -1,6 +1,7 @@ 'use strict'; -let helpers = require('./helpers'); +const XRegExp = require('xregexp'); +const helpers = require('./helpers'); // -------------------------------------------------------------------------- @@ -20,7 +21,7 @@ class QueryParser { constructor(driver) { this.driver = driver; - let matchPatterns = { + const matchPatterns = { function: /([a-z0-9_]+\((.*)\))/i, operator: /\!=?|\=|\+|&&?|~|\|\|?|\^|\/|<>|>=?|<=?|\-|%|OR|AND|NOT|XOR/ig, literal: /([0-9]+)|'(.*?)'|true|false/ig, @@ -28,21 +29,21 @@ class QueryParser { // Full pattern for identifiers // Making sure that literals and functions aren't matched - matchPatterns.identifier = new RegExp( - '(' - + '(?!' - + matchPatterns['function'].source + '|' - + matchPatterns.literal.source - + ')' - + '([a-z_\-]+[0-9]*\\.?)' - + ')+', 'ig'); + matchPatterns.identifier = XRegExp( + `( + (?! + ${matchPatterns['function'].source}| + ${matchPatterns.literal.source} + ) + ([a-z_\-]+[0-9]*\\.?) + )+`, 'igx'); // Full pattern for determining ordering of the pieces - matchPatterns.joinCombined = new RegExp( - matchPatterns['function'].source + '+|' - + matchPatterns.literal.source + '+|' - + matchPatterns.identifier.source - + '|(' + matchPatterns.operator.source + ')+', 'ig'); + matchPatterns.joinCombined = XRegExp( + `${matchPatterns['function'].source}+| # functions + ${matchPatterns.literal.source}+| # literal values + ${matchPatterns.identifier.source} # identifiers + |(${matchPatterns.operator.source})+`, 'igx'); this.matchPatterns = matchPatterns; this.identifierBlacklist = ['true', 'false', 'null']; diff --git a/test/adapters/mysql-base.js b/test/adapters/mysql-base.js index 3f9bd06..504ecd7 100644 --- a/test/adapters/mysql-base.js +++ b/test/adapters/mysql-base.js @@ -22,28 +22,6 @@ module.exports = function mysqlBase(qb, nodeQuery, expect, testRunner, promiseTe return done(); }); }); - test('Test Insert Batch', done => { - let data = [ - { - id: 544, - key: 3, - val: new Buffer('7'), - }, { - id: 89, - key: 34, - val: new Buffer('10 o\'clock'), - }, { - id: 48, - key: 403, - val: new Buffer('97'), - }, - ]; - - qb.insertBatch('create_test', data, (err, rows) => { - expect(err).is.not.ok; - return done(); - }); - }); /*--------------------------------------------------------------------------- Promise Tests diff --git a/test/adapters/mysql2_test.js b/test/adapters/mysql2_test.js index 8314700..cc72f01 100644 --- a/test/adapters/mysql2_test.js +++ b/test/adapters/mysql2_test.js @@ -26,4 +26,27 @@ let qb = nodeQuery.init('mysql', connection, adapterName); suite('Mysql2 adapter tests -', () => { require('./mysql-base')(qb, nodeQuery, expect, testRunner, promiseTestRunner); + + test('Test Insert Batch', done => { + let data = [ + { + id: 5441, + key: 3, + val: new Buffer('7'), + }, { + id: 891, + key: 34, + val: new Buffer('10 o\'clock'), + }, { + id: 481, + key: 403, + val: new Buffer('97'), + }, + ]; + + qb.insertBatch('create_test', data, (err, rows) => { + expect(err).is.not.ok; + return done(); + }); + }); }); \ No newline at end of file diff --git a/test/adapters/mysql_test.js b/test/adapters/mysql_test.js index 05d047c..2abe314 100644 --- a/test/adapters/mysql_test.js +++ b/test/adapters/mysql_test.js @@ -26,4 +26,27 @@ let qb = nodeQuery.init('mysql', connection); suite('Mysql adapter tests -', () => { require('./mysql-base')(qb, nodeQuery, expect, testRunner, promiseTestRunner); + + test('Test Insert Batch', done => { + let data = [ + { + id: 544, + key: 3, + val: new Buffer('7'), + }, { + id: 89, + key: 34, + val: new Buffer('10 o\'clock'), + }, { + id: 48, + key: 403, + val: new Buffer('97'), + }, + ]; + + qb.insertBatch('create_test', data, (err, rows) => { + expect(err).is.not.ok; + return done(); + }); + }); }); \ No newline at end of file diff --git a/test/mocha.opts b/test/mocha.opts index 31bf1aa..8c8ffe8 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,7 +1,7 @@ --ui tdd --bail --recursive ---reporter list +--reporter nyan --slow 200 --timeout 10000 --check-leaks