analyzer.select.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var Analyzer = require('../../../index').query.analyzer;
  2. var tokenize = require('../../support/tokenize');
  3. var assert = require('assert');
  4. describe('Analyzer ::', function() {
  5. describe('SELECT statements', function() {
  6. it('should generate a valid group for select "*"', function() {
  7. var tokens = tokenize({
  8. select: ['*'],
  9. from: 'books'
  10. });
  11. var result = Analyzer(tokens);
  12. assert.deepEqual(result, [
  13. [
  14. { type: 'IDENTIFIER', value: 'SELECT' },
  15. { type: 'VALUE', value: '*' }
  16. ],
  17. [
  18. { type: 'IDENTIFIER', value: 'FROM' },
  19. { type: 'VALUE', value: 'books' }
  20. ]
  21. ]);
  22. });
  23. it('should generate a valid group for select when defined columns are used', function() {
  24. var tokens = tokenize({
  25. select: ['title', 'author', 'year'],
  26. from: 'books'
  27. });
  28. var result = Analyzer(tokens);
  29. assert.deepEqual(result, [
  30. [
  31. { type: 'IDENTIFIER', value: 'SELECT' },
  32. { type: 'VALUE', value: 'title' }
  33. ],
  34. [
  35. { type: 'IDENTIFIER', value: 'SELECT' },
  36. { type: 'VALUE', value: 'author' }
  37. ],
  38. [
  39. { type: 'IDENTIFIER', value: 'SELECT' },
  40. { type: 'VALUE', value: 'year' }
  41. ],
  42. [
  43. { type: 'IDENTIFIER', value: 'FROM' },
  44. { type: 'VALUE', value: 'books' }
  45. ]
  46. ]);
  47. });
  48. });
  49. });