showdown.js 2.8 KB

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