diff options
Diffstat (limited to 'lib/output/modifiers/__tests__/highlightCode.js')
-rw-r--r-- | lib/output/modifiers/__tests__/highlightCode.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/output/modifiers/__tests__/highlightCode.js b/lib/output/modifiers/__tests__/highlightCode.js new file mode 100644 index 0000000..bd7d422 --- /dev/null +++ b/lib/output/modifiers/__tests__/highlightCode.js @@ -0,0 +1,63 @@ +jest.autoMockOff(); + +var cheerio = require('cheerio'); +var Promise = require('../../../utils/promise'); + +describe('highlightCode', function() { + var highlightCode = require('../highlightCode'); + + function doHighlight(lang, code) { + return { + text: '' + (lang || '') + '$' + code + }; + } + + function doHighlightAsync(lang, code) { + return Promise() + .then(function() { + return doHighlight(lang, code); + }); + } + + pit('should call it for normal code element', function() { + var $ = cheerio.load('<p>This is a <code>test</code></p>'); + + return highlightCode(doHighlight, $) + .then(function() { + var $code = $('code'); + expect($code.text()).toBe('$test'); + }); + }); + + pit('should call it for markdown code block', function() { + var $ = cheerio.load('<pre><code class="lang-js">test</code></pre>'); + + return highlightCode(doHighlight, $) + .then(function() { + var $code = $('code'); + expect($code.text()).toBe('js$test'); + }); + }); + + pit('should call it for asciidoc code block', function() { + var $ = cheerio.load('<pre><code class="language-python">test</code></pre>'); + + return highlightCode(doHighlight, $) + .then(function() { + var $code = $('code'); + expect($code.text()).toBe('python$test'); + }); + }); + + pit('should accept async highlighter', function() { + var $ = cheerio.load('<pre><code class="language-python">test</code></pre>'); + + return highlightCode(doHighlightAsync, $) + .then(function() { + var $code = $('code'); + expect($code.text()).toBe('python$test'); + }); + }); +}); + + |