analyzer.insert.test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var Analyzer = require('../../../index').query.analyzer;
  2. var tokenize = require('../../support/tokenize');
  3. var assert = require('assert');
  4. describe('Analyzer ::', function() {
  5. describe('INSERT statements', function() {
  6. it('should generate a valid group for INSERT statements', function() {
  7. var tokens = tokenize({
  8. insert: {
  9. title: 'Slaughterhouse Five'
  10. },
  11. into: 'books'
  12. });
  13. var result = Analyzer(tokens);
  14. assert.deepEqual(result, [
  15. [
  16. { type: 'IDENTIFIER', value: 'INSERT' },
  17. { type: 'KEY', value: 'title' },
  18. { type: 'VALUE', value: 'Slaughterhouse Five' }
  19. ],
  20. [
  21. { type: 'IDENTIFIER', value: 'INTO' },
  22. { type: 'VALUE', value: 'books' }
  23. ]
  24. ]);
  25. });
  26. it('should generate a valid group for INSERT statements when an array is used', function() {
  27. var tokens = tokenize({
  28. insert: [
  29. {
  30. title: 'Slaughterhouse Five',
  31. author: 'Kurt Vonnegut'
  32. },
  33. {
  34. title: 'The Great Gatsby',
  35. author: 'F. Scott Fitzgerald'
  36. }
  37. ],
  38. into: 'books'
  39. });
  40. var result = Analyzer(tokens);
  41. assert.deepEqual(result, [
  42. [
  43. { type: 'IDENTIFIER', value: 'INSERT' },
  44. [
  45. { type: 'KEY', value: 'title' },
  46. { type: 'VALUE', value: 'Slaughterhouse Five' },
  47. { type: 'KEY', value: 'author' },
  48. { type: 'VALUE', value: 'Kurt Vonnegut' }
  49. ],
  50. [
  51. { type: 'KEY', value: 'title' },
  52. { type: 'VALUE', value: 'The Great Gatsby' },
  53. { type: 'KEY', value: 'author' },
  54. { type: 'VALUE', value: 'F. Scott Fitzgerald' }
  55. ]
  56. ],
  57. [
  58. { type: 'IDENTIFIER', value: 'INTO' },
  59. { type: 'VALUE', value: 'books' }
  60. ]
  61. ]);
  62. });
  63. });
  64. });