showdown.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. require('source-map-support').install();
  2. require('chai').should();
  3. var expect = require('chai').expect,
  4. showdown = require('../bootstrap').showdown;
  5. describe('showdown.options', function () {
  6. 'use strict';
  7. describe('setOption() and getOption()', function () {
  8. it('should set option foo=bar', function () {
  9. showdown.setOption('foo', 'bar');
  10. showdown.getOption('foo').should.equal('bar');
  11. showdown.resetOptions();
  12. expect(showdown.getOption('foo')).to.be.undefined();
  13. });
  14. });
  15. describe('getDefaultOptions()', function () {
  16. it('should get default options', function () {
  17. var opts = require('../optionswp').getDefaultOpts(true);
  18. /*
  19. var opts = {
  20. omitExtraWLInCodeBlocks: false,
  21. prefixHeaderId: false,
  22. noHeaderId: false,
  23. headerLevelStart: 1,
  24. parseImgDimensions: false,
  25. simplifiedAutoLink: false,
  26. literalMidWordUnderscores: false,
  27. strikethrough: false,
  28. tables: false,
  29. tablesHeaderId: false,
  30. ghCodeBlocks: true,
  31. tasklists: false
  32. };
  33. */
  34. expect(showdown.getDefaultOptions()).to.be.eql(opts);
  35. });
  36. });
  37. });
  38. describe('showdown.extension()', function () {
  39. 'use strict';
  40. var extObjMock = {
  41. type: 'lang',
  42. filter: function () {}
  43. },
  44. extObjFunc = function () {
  45. return extObjMock;
  46. };
  47. describe('should register', function () {
  48. it('an extension object', function () {
  49. showdown.extension('foo', extObjMock);
  50. showdown.extension('foo').should.eql([extObjMock]);
  51. showdown.resetExtensions();
  52. });
  53. it('an extension function', function () {
  54. showdown.extension('foo', extObjFunc);
  55. showdown.extension('foo').should.eql([extObjMock]);
  56. showdown.resetExtensions();
  57. });
  58. });
  59. describe('should refuse to register', function () {
  60. it('a generic object', function () {
  61. var fn = function () {
  62. showdown.extension('foo', {});
  63. };
  64. expect(fn).to.throw();
  65. });
  66. it('an extension with invalid type', function () {
  67. var fn = function () {
  68. showdown.extension('foo', {
  69. type: 'foo'
  70. });
  71. };
  72. expect(fn).to.throw(/type .+? is not recognized\. Valid values: "lang" or "output"/);
  73. });
  74. it('an extension without regex or filter', function () {
  75. var fn = function () {
  76. showdown.extension('foo', {
  77. type: 'lang'
  78. });
  79. };
  80. expect(fn).to.throw(/extensions must define either a "regex" property or a "filter" method/);
  81. });
  82. });
  83. });
  84. describe('showdown.getAllExtensions()', function () {
  85. 'use strict';
  86. var extObjMock = {
  87. type: 'lang',
  88. filter: function () {}
  89. };
  90. it('should return all extensions', function () {
  91. showdown.extension('bar', extObjMock);
  92. showdown.getAllExtensions().should.eql({bar: [extObjMock]});
  93. });
  94. });