tokenizer.select.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var Tokenizer = require('../../../index').query.tokenizer;
  2. var assert = require('assert');
  3. describe('Tokenizer ::', function() {
  4. describe('SELECT statements', function() {
  5. it('should generate a valid token array when "*" is used', function() {
  6. var result = Tokenizer({
  7. select: ['*'],
  8. from: 'books'
  9. });
  10. assert.deepEqual(result, [
  11. { type: 'IDENTIFIER', value: 'SELECT' },
  12. { type: 'VALUE', value: '*' },
  13. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  14. { type: 'IDENTIFIER', value: 'FROM' },
  15. { type: 'VALUE', value: 'books' },
  16. { type: 'ENDIDENTIFIER', value: 'FROM' }
  17. ]);
  18. });
  19. it('should generate a valid token array when defined columns are used', function() {
  20. var result = Tokenizer({
  21. select: ['title', 'author', 'year'],
  22. from: 'books'
  23. });
  24. assert.deepEqual(result, [
  25. { type: 'IDENTIFIER', value: 'SELECT' },
  26. { type: 'VALUE', value: 'title' },
  27. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  28. { type: 'IDENTIFIER', value: 'SELECT' },
  29. { type: 'VALUE', value: 'author' },
  30. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  31. { type: 'IDENTIFIER', value: 'SELECT' },
  32. { type: 'VALUE', value: 'year' },
  33. { type: 'ENDIDENTIFIER', value: 'SELECT' },
  34. { type: 'IDENTIFIER', value: 'FROM' },
  35. { type: 'VALUE', value: 'books' },
  36. { type: 'ENDIDENTIFIER', value: 'FROM' }
  37. ]);
  38. });
  39. });
  40. });