diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/assertions.js | 13 | ||||
-rw-r--r-- | test/books/highlight/README.md | 15 | ||||
-rw-r--r-- | test/books/highlight/SUMMARY.md | 1 | ||||
-rw-r--r-- | test/books/init/SUMMARY.md | 3 | ||||
-rw-r--r-- | test/codehighlighting.js | 58 | ||||
-rw-r--r-- | test/helper.js | 12 | ||||
-rw-r--r-- | test/init.js | 1 | ||||
-rw-r--r-- | test/plugins.js | 35 | ||||
-rw-r--r-- | test/plugins/replace_highlight/index.js | 11 | ||||
-rw-r--r-- | test/plugins/replace_highlight/package.json | 9 |
10 files changed, 156 insertions, 2 deletions
diff --git a/test/assertions.js b/test/assertions.js index 7a34380..f81645b 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -26,14 +26,27 @@ should.Assertion.add('html', function(rules, description) { _.each(rules, function(validations, query) { validations = _.defaults(validations || {}, { + // Select a specific element in the list of matched elements + index: null, + + // Check that there is the correct count of elements count: 1, + + // Check attribute values attributes: {}, + + // Trim inner text trim: false, + + // Check inner text text: undefined }); var $el = $(query); + // Select correct element + if (_.isNumber(validations.index)) $el = $($el.get(validations.index)); + // Test number of elements $el.length.should.be.equal(validations.count); diff --git a/test/books/highlight/README.md b/test/books/highlight/README.md new file mode 100644 index 0000000..417fabc --- /dev/null +++ b/test/books/highlight/README.md @@ -0,0 +1,15 @@ +# Readme + +Block without language + +``` +test 1 +``` + +Block with a language + +```lang +test 2 +``` + +Inline code: `test 3`
\ No newline at end of file diff --git a/test/books/highlight/SUMMARY.md b/test/books/highlight/SUMMARY.md new file mode 100644 index 0000000..ac9323c --- /dev/null +++ b/test/books/highlight/SUMMARY.md @@ -0,0 +1 @@ +# Summary diff --git a/test/books/init/SUMMARY.md b/test/books/init/SUMMARY.md index 1e63aed..31c1561 100644 --- a/test/books/init/SUMMARY.md +++ b/test/books/init/SUMMARY.md @@ -4,3 +4,6 @@ * [Hello 2](hello2.md) * Hello 3 * [Hello 4](hello3/hello4.md) + * Hello 5 + * [Hello 6](hello3/hello5/hello6.md) + diff --git a/test/codehighlighting.js b/test/codehighlighting.js new file mode 100644 index 0000000..e35f37e --- /dev/null +++ b/test/codehighlighting.js @@ -0,0 +1,58 @@ +var _ = require('lodash'); +var should = require('should'); +var path = require('path'); +var fs = require('fs'); + +var Plugin = require('../lib/plugin'); +var PLUGINS_ROOT = path.resolve(__dirname, 'plugins'); + +describe('Code Highlighting', function () { + var book, PAGE; + + before(function() { + return books.generate('highlight', 'website', { + prepare: function(_book) { + book = _book; + + var plugin = new Plugin(book, "replace_highlight"); + plugin.load("./replace_highlight", PLUGINS_ROOT); + + book.plugins.load(plugin); + } + }) + .then(function() { + PAGE = fs.readFileSync( + path.join(book.options.output, "index.html"), + { encoding: "utf-8" } + ); + }); + }); + + it('should correctly replace highlighting', function() { + PAGE.should.be.html({ + "code": { + index: 0, + text: 'code_test 1\n_code' + } + }); + }); + + it('should correctly replace highlighting with language', function() { + PAGE.should.be.html({ + "code": { + index: 1, + text: 'lang_test 2\n_lang' + } + }); + }); + + it('should correctly replace highlighting for inline code', function() { + PAGE.should.be.html({ + "code": { + index: 2, + text: 'code_test 3_code' + } + }); + }); +}); + diff --git a/test/helper.js b/test/helper.js index f6b671b..f4432a9 100644 --- a/test/helper.js +++ b/test/helper.js @@ -17,10 +17,18 @@ var TMPDIR = os.tmpdir(); // Generate and return a book -function generateBook(bookId, test) { +function generateBook(bookId, test, opts) { + opts = _.defaults(opts || {}, { + prepare: function() {} + }); + return parseBook(bookId, test) .then(function(book) { - return book.generate(test) + + return Q(opts.prepare(book)) + .then(function() { + return book.generate(test); + }) .thenResolve(book); }); } diff --git a/test/init.js b/test/init.js index 3ba701f..8415b20 100644 --- a/test/init.js +++ b/test/init.js @@ -19,5 +19,6 @@ describe('Init Books', function () { should(fs.existsSync(path.resolve(initRoot, "hello.md"))).be.ok; should(fs.existsSync(path.resolve(initRoot, "hello2.md"))).be.ok; should(fs.existsSync(path.resolve(initRoot, "hello3/hello4.md"))).be.ok; + should(fs.existsSync(path.resolve(initRoot, "hello3/hello5/hello6.md"))).be.ok; }); }); diff --git a/test/plugins.js b/test/plugins.js index e3d0c49..cc9c8e6 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -1,8 +1,10 @@ var _ = require('lodash'); var should = require('should'); var path = require('path'); +var fs = require('fs'); var Plugin = require('../lib/plugin'); +var parsers = require("gitbook-parsers"); var PLUGINS_ROOT = path.resolve(__dirname, 'plugins'); describe('Plugins', function () { @@ -200,5 +202,38 @@ describe('Plugins', function () { }); }); }); + + describe('Blocks without parsing', function() { + var plugin; + + before(function() { + plugin = new Plugin(book, "blocks"); + plugin.load("./blocks", PLUGINS_ROOT); + + return book.plugins.load(plugin); + }); + + var testTpl = function(markup, str, args, options) { + var filetype = parsers.get(markup); + + return book.template.renderString(str, args, options) + .then(filetype.page).get('sections').get(0).get('content') + .then(book.template.postProcess) + }; + + it('should correctly process unparsable for markdown', function() { + return testTpl('.md', '{% test %}**hello**{% endtest %}') + .then(function(content) { + content.should.equal("<p>test**hello**test</p>\n"); + }); + }); + + it('should correctly process unparsable for asciidoc', function() { + return testTpl('.adoc', '{% test %}**hello**{% endtest %}') + .then(function(content) { + content.should.equal('<div class="paragraph">\n<p>test**hello**test</p>\n</div>'); + }); + }); + }); }); diff --git a/test/plugins/replace_highlight/index.js b/test/plugins/replace_highlight/index.js new file mode 100644 index 0000000..25f9642 --- /dev/null +++ b/test/plugins/replace_highlight/index.js @@ -0,0 +1,11 @@ +module.exports = { + blocks: { + "code": { + process: function(blk) { + var lang = blk.kwargs.language || 'code'; + + return lang+"_"+blk.body+"_"+lang; + } + } + } +};
\ No newline at end of file diff --git a/test/plugins/replace_highlight/package.json b/test/plugins/replace_highlight/package.json new file mode 100644 index 0000000..72d1033 --- /dev/null +++ b/test/plugins/replace_highlight/package.json @@ -0,0 +1,9 @@ +{ + "name": "gitbook-plugin-replace_highlight", + "description": "Test replacing default code highlighter", + "main": "index.js", + "version": "0.0.1", + "engines": { + "gitbook": "*" + } +}
\ No newline at end of file |