showdown.js 2.8 KB

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