showdown.js 2.8 KB

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