123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- var Tokenizer = require('../../../index').query.tokenizer;
- var assert = require('assert');
- describe('Tokenizer ::', function() {
- describe('WHERE IN statements', function() {
- it('should generate a valid token array', function() {
- var result = Tokenizer({
- select: ['name'],
- from: 'users',
- where: {
- and: [
- {
- id: {
- in: [1, 2, 3]
- }
- }
- ]
- }
- });
- assert.deepEqual(result, [
- { type: 'IDENTIFIER', value: 'SELECT' },
- { type: 'VALUE', value: 'name' },
- { type: 'ENDIDENTIFIER', value: 'SELECT' },
- { type: 'IDENTIFIER', value: 'FROM' },
- { type: 'VALUE', value: 'users' },
- { type: 'ENDIDENTIFIER', value: 'FROM' },
- { type: 'IDENTIFIER', value: 'WHERE' },
- { type: 'CONDITION', value: 'AND' },
- { type: 'GROUP', value: 0 },
- { type: 'KEY', value: 'id' },
- { type: 'CONDITION', value: 'IN' },
- { type: 'VALUE', value: [1, 2, 3] },
- { type: 'ENDCONDITION', value: 'IN' },
- { type: 'ENDGROUP', value: 0 },
- { type: 'ENDCONDITION', value: 'AND' },
- { type: 'ENDIDENTIFIER', value: 'WHERE' }
- ]);
- });
- it('should generate a valid token array when in an OR statement', function() {
- var result = Tokenizer({
- select: ['name'],
- from: 'users',
- where: {
- or: [
- {
- id: {
- in: [1, 2, 3]
- }
- },
- {
- id: {
- in: [4, 5, 6]
- }
- }
- ]
- }
- });
- assert.deepEqual(result, [
- { type: 'IDENTIFIER', value: 'SELECT' },
- { type: 'VALUE', value: 'name' },
- { type: 'ENDIDENTIFIER', value: 'SELECT' },
- { type: 'IDENTIFIER', value: 'FROM' },
- { type: 'VALUE', value: 'users' },
- { type: 'ENDIDENTIFIER', value: 'FROM' },
- { type: 'IDENTIFIER', value: 'WHERE' },
- { type: 'CONDITION', value: 'OR' },
- { type: 'GROUP', value: 0 },
- { type: 'KEY', value: 'id' },
- { type: 'CONDITION', value: 'IN' },
- { type: 'VALUE', value: [1, 2, 3] },
- { type: 'ENDCONDITION', value: 'IN' },
- { type: 'ENDGROUP', value: 0 },
- { type: 'GROUP', value: 1 },
- { type: 'KEY', value: 'id' },
- { type: 'CONDITION', value: 'IN' },
- { type: 'VALUE', value: [4, 5, 6] },
- { type: 'ENDCONDITION', value: 'IN' },
- { type: 'ENDGROUP', value: 1 },
- { type: 'ENDCONDITION', value: 'OR' },
- { type: 'ENDIDENTIFIER', value: 'WHERE' }
- ]);
- });
- });
- });
|