2015-06-01 03:56:28 +08:00
|
|
|
require('source-map-support').install();
|
|
|
|
require('chai').should();
|
|
|
|
var expect = require('chai').expect,
|
|
|
|
showdown = require('../../dist/showdown.js');
|
|
|
|
|
|
|
|
describe('showdown.options', function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
describe('setOption() and getOption()', function () {
|
|
|
|
it('should set option foo=bar', function () {
|
|
|
|
showdown.setOption('foo', 'bar');
|
|
|
|
showdown.getOption('foo').should.equal('bar');
|
|
|
|
showdown.resetOptions();
|
|
|
|
expect(showdown.getOption('foo')).to.be.undefined();
|
|
|
|
});
|
|
|
|
});
|
2015-06-15 21:56:30 +08:00
|
|
|
|
|
|
|
describe('getDefaultOptions()', function () {
|
|
|
|
it('should get default options', function () {
|
|
|
|
var opts = {
|
|
|
|
omitExtraWLInCodeBlocks: false,
|
|
|
|
prefixHeaderId: false,
|
2015-06-17 08:22:05 +08:00
|
|
|
noHeaderId: false,
|
2015-06-17 09:19:44 +08:00
|
|
|
headerLevelStart: 1,
|
2015-06-17 08:22:05 +08:00
|
|
|
parseImgDimensions: false
|
2015-06-15 21:56:30 +08:00
|
|
|
};
|
|
|
|
expect(showdown.getDefaultOptions()).to.be.eql(opts);
|
|
|
|
});
|
|
|
|
});
|
2015-06-01 03:56:28 +08:00
|
|
|
});
|
|
|
|
|
2015-06-08 02:02:45 +08:00
|
|
|
describe('showdown.extension()', function () {
|
2015-06-01 03:56:28 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var extObjMock = {
|
|
|
|
type: 'lang',
|
|
|
|
filter: function () {}
|
|
|
|
},
|
|
|
|
extObjFunc = function () {
|
|
|
|
return extObjMock;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('should register', function () {
|
2015-06-08 02:02:45 +08:00
|
|
|
it('an extension object', function () {
|
2015-06-01 03:56:28 +08:00
|
|
|
showdown.extension('foo', extObjMock);
|
2015-06-08 02:02:45 +08:00
|
|
|
showdown.extension('foo').should.eql([extObjMock]);
|
2015-06-01 03:56:28 +08:00
|
|
|
showdown.resetExtensions();
|
|
|
|
});
|
|
|
|
|
2015-06-08 02:02:45 +08:00
|
|
|
it('an extension function', function () {
|
2015-06-01 03:56:28 +08:00
|
|
|
showdown.extension('foo', extObjFunc);
|
2015-06-08 02:02:45 +08:00
|
|
|
showdown.extension('foo').should.eql([extObjMock]);
|
2015-06-01 03:56:28 +08:00
|
|
|
showdown.resetExtensions();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('should refuse to register', function () {
|
|
|
|
it('a generic object', function () {
|
|
|
|
var fn = function () {
|
|
|
|
showdown.extension('foo', {});
|
|
|
|
};
|
|
|
|
expect(fn).to.throw();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('an extension with invalid type', function () {
|
|
|
|
var fn = function () {
|
|
|
|
showdown.extension('foo', {
|
|
|
|
type: 'foo'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
expect(fn).to.throw(/type .+? is not recognized\. Valid values: "lang" or "output"/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('an extension without regex or filter', function () {
|
|
|
|
var fn = function () {
|
|
|
|
showdown.extension('foo', {
|
|
|
|
type: 'lang'
|
|
|
|
});
|
|
|
|
};
|
|
|
|
expect(fn).to.throw(/extensions must define either a "regex" property or a "filter" method/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showdown.getAllExtensions()', function () {
|
|
|
|
'use strict';
|
|
|
|
var extObjMock = {
|
|
|
|
type: 'lang',
|
|
|
|
filter: function () {}
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should return all extensions', function () {
|
|
|
|
showdown.extension('bar', extObjMock);
|
2015-06-08 02:02:45 +08:00
|
|
|
showdown.getAllExtensions().should.eql({bar: [extObjMock]});
|
2015-06-01 03:56:28 +08:00
|
|
|
});
|
|
|
|
});
|