/** * Tests the footnotes extension for showdown * */ /*globals describe, it */ /*jshint expr:true*/ var should = require('should'), // Stuff we are testing ghostfootnotes = require('../../shared/lib/showdown/extensions/ghostfootnotes'); // To stop jshint complaining should.equal(true, true); function _ExecuteExtension(ext, text) { if (ext.regex) { var re = new RegExp(ext.regex, 'g'); return text.replace(re, ext.replace); } else if (ext.filter) { return ext.filter(text); } } function _ConvertPhrase(testPhrase) { return ghostfootnotes().reduce(function (text, ext) { return _ExecuteExtension(ext, text); }, testPhrase); } describe('Ghost footnotes showdown extension', function () { /*jslint regexp: true */ it('should export an array of methods for processing', function () { ghostfootnotes.should.be.a.function; ghostfootnotes().should.be.an.Array; ghostfootnotes().forEach(function (processor) { processor.should.be.an.Object; processor.should.have.property('type'); processor.type.should.be.a.String; }); }); it('should replace inline footnotes with the right html', function () { var testPhrase = { input: 'foo_bar[^1]', output: /1<\/a><\/sup>/ }, processedMarkup = _ConvertPhrase(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); it('should replace end footnotes with the right html', function () { var testPhrase = { input: '[^1]: foo bar', output: /
  1. foo bar ↩<\/a><\/p><\/li><\/ol><\/div>/ }, processedMarkup = _ConvertPhrase(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); it('should number multiple footnotes correctly', function () { var testPhrase = { input: 'foo[^1] bar[^n] etc[^2]', output: /foo1<\/a><\/sup> bar2<\/a><\/sup> etc2<\/a><\/sup>/ }, processedMarkup = _ConvertPhrase(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); it('should put everything together', function () { // Tests for some interaction bugs between components e.g. // confusing the end form and the inline form var testPhrase = { input: 'foo bar[^1] is a very[^n] foo bar[^1]\n' + '[^n]: a metasyntactic variable\n' + '[^n]: this is hard to measure', output: 'foo bar1 is a very2 foo bar1\n' + '

    1. a metasyntactic variable

    2. \n' + '
    3. this is hard to measure

    ' }, processedMarkup = _ConvertPhrase(testPhrase.input); processedMarkup.should.match(testPhrase.output); }); });