showdown.js 2.9 KB

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