showdown.js 2.7 KB

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