summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2015-09-14 11:41:01 +0200
committerSamy Pesse <samypesse@gmail.com>2015-09-14 11:41:01 +0200
commit2c08ccad870efbf1a964b08c30da5de0c025a0ad (patch)
tree453765f2230508957e38eadbe0d330bef4d818d6 /test
parentfa4e234bab15db4b0a8a0a13f041ef5869a2458b (diff)
downloadgitbook-2c08ccad870efbf1a964b08c30da5de0c025a0ad.zip
gitbook-2c08ccad870efbf1a964b08c30da5de0c025a0ad.tar.gz
gitbook-2c08ccad870efbf1a964b08c30da5de0c025a0ad.tar.bz2
Pass language as kwargs to code block
Improve tests for extending code highlighting
Diffstat (limited to 'test')
-rw-r--r--test/assertions.js13
-rw-r--r--test/books/highlight/README.md12
-rw-r--r--test/codehighlighting.js44
-rw-r--r--test/plugins/highlight/index.js4
4 files changed, 60 insertions, 13 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
index 73d74c0..417fabc 100644
--- a/test/books/highlight/README.md
+++ b/test/books/highlight/README.md
@@ -1,7 +1,15 @@
# Readme
-Default description for the book.
+Block without language
```
-test
+test 1
```
+
+Block with a language
+
+```lang
+test 2
+```
+
+Inline code: `test 3` \ No newline at end of file
diff --git a/test/codehighlighting.js b/test/codehighlighting.js
index a64bf4b..b0c4110 100644
--- a/test/codehighlighting.js
+++ b/test/codehighlighting.js
@@ -7,27 +7,51 @@ var Plugin = require('../lib/plugin');
var PLUGINS_ROOT = path.resolve(__dirname, 'plugins');
describe('Code Highlighting', function () {
- it('should correctly replace highlighting', function() {
+ var book, PAGE;
+
+ before(function() {
return books.generate('highlight', 'website', {
- prepare: function(book) {
+ prepare: function(_book) {
+ book = _book;
+
var plugin = new Plugin(book, "highlight");
plugin.load("./highlight", PLUGINS_ROOT);
book.plugins.load(plugin);
}
})
- .then(function(book) {
- var PAGE = fs.readFileSync(
+ .then(function() {
+ PAGE = fs.readFileSync(
path.join(book.options.output, "index.html"),
{ encoding: "utf-8" }
);
+ });
+ });
- PAGE.should.be.html({
- "code": {
- count: 1,
- text: 'code_test\n_code'
- }
- });
+ 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/plugins/highlight/index.js b/test/plugins/highlight/index.js
index 01202f2..25f9642 100644
--- a/test/plugins/highlight/index.js
+++ b/test/plugins/highlight/index.js
@@ -2,7 +2,9 @@ module.exports = {
blocks: {
"code": {
process: function(blk) {
- return "code_"+blk.body+"_code";
+ var lang = blk.kwargs.language || 'code';
+
+ return lang+"_"+blk.body+"_"+lang;
}
}
}