tokenizer.insert.test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var Tokenizer = require('../../../index').query.tokenizer;
  2. var assert = require('assert');
  3. describe('Tokenizer ::', function() {
  4. describe('INSERT statements', function() {
  5. it('should generate a valid token array for an INSERT is used', function() {
  6. var result = Tokenizer({
  7. insert: {
  8. title: 'Slaughterhouse Five'
  9. },
  10. into: 'books'
  11. });
  12. assert.deepEqual(result, [
  13. { type: 'IDENTIFIER', value: 'INSERT' },
  14. { type: 'KEY', value: 'title' },
  15. { type: 'VALUE', value: 'Slaughterhouse Five' },
  16. { type: 'ENDIDENTIFIER', value: 'INSERT' },
  17. { type: 'IDENTIFIER', value: 'INTO' },
  18. { type: 'VALUE', value: 'books' },
  19. { type: 'ENDIDENTIFIER', value: 'INTO' }
  20. ]);
  21. });
  22. it('should generate a valid token array for an INSERT is used as an array', function() {
  23. var result = Tokenizer({
  24. insert: [
  25. {
  26. title: 'Slaughterhouse Five'
  27. },
  28. {
  29. title: 'The Great Gatsby'
  30. }
  31. ],
  32. into: 'books'
  33. });
  34. assert.deepEqual(result, [
  35. { type: 'IDENTIFIER', value: 'INSERT' },
  36. { type: 'GROUP', value: 0 },
  37. { type: 'KEY', value: 'title' },
  38. { type: 'VALUE', value: 'Slaughterhouse Five' },
  39. { type: 'ENDGROUP', value: 0 },
  40. { type: 'GROUP', value: 1 },
  41. { type: 'KEY', value: 'title' },
  42. { type: 'VALUE', value: 'The Great Gatsby' },
  43. { type: 'ENDGROUP', value: 1 },
  44. { type: 'ENDIDENTIFIER', value: 'INSERT' },
  45. { type: 'IDENTIFIER', value: 'INTO' },
  46. { type: 'VALUE', value: 'books' },
  47. { type: 'ENDIDENTIFIER', value: 'INTO' }
  48. ]);
  49. });
  50. });
  51. });