parser_spec.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. const chai = require('chai');
  3. const sinon = require('sinon');
  4. const sinonChai = require('sinon-chai');
  5. const expect = chai.expect;
  6. chai.use(sinonChai);
  7. describe('Testing parser', function () {
  8. var Parser = require('../src/parser');
  9. it('Availability of the class', function () {
  10. expect(Parser).not.to.be.undefined;
  11. expect(Parser).not.to.be.null;
  12. });
  13. it('Instantiate with default params', function () {
  14. var instance = new Parser();
  15. expect(instance).not.to.be.null;
  16. });
  17. describe('getKeyValue', function () {
  18. var instance = new Parser({ keep_quotes: true });
  19. it('Returning key value not matching', function () {
  20. var wrapper = function () {
  21. instance.getKeyValue('key');
  22. };
  23. expect(wrapper).to.throw;
  24. });
  25. });
  26. describe('getMultiKeyValue', function () {
  27. var instance = new Parser({ keep_quotes: true });
  28. it('Returning key value not matching', function () {
  29. var wrapper = function () {
  30. instance.getMultiKeyValue('');
  31. };
  32. expect(wrapper).to.throw;
  33. });
  34. });
  35. describe('getMultiLineEndValue', function () {
  36. var instance = new Parser({ keep_quotes: true });
  37. it('Returning key value not matching', function () {
  38. var wrapper = function () {
  39. instance.getMultiLineEndValue('');
  40. };
  41. expect(wrapper).to.throw;
  42. });
  43. });
  44. describe('handleSection', function () {
  45. var instance = new Parser({ keep_quotes: true });
  46. it('Same section appears twice', function () {
  47. var ctx = { ini: {} };
  48. instance.handleSection(ctx, '[multi]');
  49. instance.handleSection(ctx, '[another]');
  50. instance.handleSection(ctx, '[multi]');
  51. expect(ctx.ini.multi).to.be.defined;
  52. expect(ctx.ini.another).to.be.defined;
  53. expect(ctx.current).to.equal(ctx.ini.multi);
  54. });
  55. it('Section inherits from other section', function () {
  56. var ctx = { ini: {} };
  57. instance.handleSection(ctx, '[parent]');
  58. instance.handleSection(ctx, '[child:parent]');
  59. expect(ctx.ini.parent).to.be.defined;
  60. expect(ctx.ini.child).to.be.defined;
  61. });
  62. });
  63. });