showdown.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. require('source-map-support').install();
  2. require('chai').should();
  3. var expect = require('chai').expect,
  4. showdown = require('../../dist/showdown.js');
  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 = {
  18. omitExtraWLInCodeBlocks: false,
  19. prefixHeaderId: false,
  20. noHeaderId: false,
  21. headerLevelStart: 1,
  22. parseImgDimensions: false,
  23. simplifiedAutoLink: false,
  24. literalMidWordUnderscores: false,
  25. strikethrough: false
  26. };
  27. expect(showdown.getDefaultOptions()).to.be.eql(opts);
  28. });
  29. });
  30. });
  31. describe('showdown.extension()', function () {
  32. 'use strict';
  33. var extObjMock = {
  34. type: 'lang',
  35. filter: function () {}
  36. },
  37. extObjFunc = function () {
  38. return extObjMock;
  39. };
  40. describe('should register', function () {
  41. it('an extension object', function () {
  42. showdown.extension('foo', extObjMock);
  43. showdown.extension('foo').should.eql([extObjMock]);
  44. showdown.resetExtensions();
  45. });
  46. it('an extension function', function () {
  47. showdown.extension('foo', extObjFunc);
  48. showdown.extension('foo').should.eql([extObjMock]);
  49. showdown.resetExtensions();
  50. });
  51. });
  52. describe('should refuse to register', function () {
  53. it('a generic object', function () {
  54. var fn = function () {
  55. showdown.extension('foo', {});
  56. };
  57. expect(fn).to.throw();
  58. });
  59. it('an extension with invalid type', function () {
  60. var fn = function () {
  61. showdown.extension('foo', {
  62. type: 'foo'
  63. });
  64. };
  65. expect(fn).to.throw(/type .+? is not recognized\. Valid values: "lang" or "output"/);
  66. });
  67. it('an extension without regex or filter', function () {
  68. var fn = function () {
  69. showdown.extension('foo', {
  70. type: 'lang'
  71. });
  72. };
  73. expect(fn).to.throw(/extensions must define either a "regex" property or a "filter" method/);
  74. });
  75. });
  76. });
  77. describe('showdown.getAllExtensions()', function () {
  78. 'use strict';
  79. var extObjMock = {
  80. type: 'lang',
  81. filter: function () {}
  82. };
  83. it('should return all extensions', function () {
  84. showdown.extension('bar', extObjMock);
  85. showdown.getAllExtensions().should.eql({bar: [extObjMock]});
  86. });
  87. });