tokenizer.whereexempt.test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var Tokenizer = require('../../../index').query.tokenizer;
  2. var assert = require('assert');
  3. describe('Tokenizer ::', function() {
  4. describe('WHERE statements', function() {
  5. it('should generate a valid token array when exempt identifiers are used as keys', function() {
  6. var result = Tokenizer({
  7. select: ['from', 'count', 'insert'],
  8. from: 'user',
  9. where: {
  10. and: [{
  11. from: 'catland'
  12. }, {
  13. insert: false
  14. }, {
  15. count: {
  16. '>': 4
  17. }
  18. }]
  19. }
  20. });
  21. assert.deepEqual(result, [
  22. { type: 'IDENTIFIER', value: 'SELECT' },
  23. { type: 'VALUE', value: 'from' },
  24. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  25. { type: 'IDENTIFIER', value: 'SELECT' },
  26. { type: 'VALUE', value: 'count' },
  27. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  28. { type: 'IDENTIFIER', value: 'SELECT' },
  29. { type: 'VALUE', value: 'insert' },
  30. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  31. { type: 'IDENTIFIER', value: 'FROM' },
  32. { type: 'VALUE', value: 'user' },
  33. { type: 'ENDIDENTIFIER', value: 'FROM' },
  34. { type: 'IDENTIFIER', value: 'WHERE' },
  35. { type: 'CONDITION', value: 'AND' },
  36. { type: 'GROUP', value: 0 },
  37. { type: 'KEY', value: 'from' },
  38. { type: 'VALUE', value: 'catland' },
  39. { type: 'ENDGROUP', value: 0 },
  40. { type: 'GROUP', value: 1 },
  41. { type: 'KEY', value: 'insert' },
  42. { type: 'VALUE', value: false },
  43. { type: 'ENDGROUP', value: 1 },
  44. { type: 'GROUP', value: 2 },
  45. { type: 'KEY', value: 'count' },
  46. { type: 'OPERATOR', value: '>' },
  47. { type: 'VALUE', value: 4 },
  48. { type: 'ENDOPERATOR', value: '>' },
  49. { type: 'ENDGROUP', value: 2 },
  50. { type: 'ENDCONDITION', value: 'AND' },
  51. { type: 'ENDIDENTIFIER', value: 'WHERE' }
  52. ]);
  53. });
  54. });
  55. });